Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Rename property to host-port and add assert
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed May 7, 2020
1 parent f1f8394 commit 6c5c52a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

/**
* Provides auto-configuration to use the Spanner emulator if enabled.
Expand All @@ -46,12 +47,10 @@ public GcpSpannerEmulatorAutoConfiguration(GcpSpannerProperties properties) {
@Bean
@ConditionalOnMissingBean
public SpannerOptions spannerOptions() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
Assert.notNull(this.properties.getHostPort(), "`spring.cloud.gcp.spanner.host-port` must be set.");
return SpannerOptions.newBuilder()
.setProjectId(this.properties.getProjectId())
.setCredentials(NoCredentials.getInstance());
if (this.properties.getEmulatorHost() != null) {
builder.setEmulatorHost(this.properties.getEmulatorHost());
}
return builder.build();
.setCredentials(NoCredentials.getInstance())
.setEmulatorHost(this.properties.getHostPort()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class GcpSpannerProperties implements CredentialsSupplier {
// Otherwise, by default, block until a session becomes available.
private boolean failIfPoolExhausted = false;

private String emulatorHost;
private String hostPort;

public Credentials getCredentials() {
return this.credentials;
Expand Down Expand Up @@ -175,11 +175,11 @@ public void setFailIfPoolExhausted(boolean failIfPoolExhausted) {
this.failIfPoolExhausted = failIfPoolExhausted;
}

public String getEmulatorHost() {
return this.emulatorHost;
public String getHostPort() {
return this.hostPort;
}

public void setEmulatorHost(String emulatorHost) {
this.emulatorHost = emulatorHost;
public void setHostPort(String hostPort) {
this.hostPort = hostPort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class GcpSpannerEmulatorAutoConfigurationTests {
@Test
public void testEmulatorAutoConfigurationEnabled() {
this.contextRunner.withPropertyValues("spring.cloud.gcp.spanner.emulator.enabled=true",
"spring.cloud.gcp.spanner.emulator-host=localhost:9010")
"spring.cloud.gcp.spanner.host-port=localhost:9010")
.run(context -> {
SpannerOptions spannerOptions = context.getBean(SpannerOptions.class);
assertThat(spannerOptions.getEndpoint()).isEqualTo("localhost:9010");
Expand Down

0 comments on commit 6c5c52a

Please sign in to comment.