use of com.google.cloud.spanner.SpannerOptions in project spanner-jdbc by olavloite.
the class InstanceConfigIT method testEuropeWestSingleNodeConfig.
@Test
public void testEuropeWestSingleNodeConfig() {
String credentialsPath = "cloudspanner-emulator-key.json";
String projectId = "test-project";
GoogleCredentials credentials = null;
try {
credentials = CloudSpannerConnection.getCredentialsFromFile(credentialsPath);
} catch (IOException e) {
throw new RuntimeException("Could not read key file " + credentialsPath, e);
}
Builder builder = SpannerOptions.newBuilder();
builder.setProjectId(projectId);
builder.setCredentials(credentials);
builder.setHost(CloudSpannerIT.getHost());
SpannerOptions options = builder.build();
Spanner spanner = options.getService();
InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
InstanceConfig config = instanceAdminClient.getInstanceConfig("regional-europe-west1");
assertEquals("regional-europe-west1", config.getId().getInstanceConfig());
spanner.close();
}
use of com.google.cloud.spanner.SpannerOptions in project spanner-jdbc by olavloite.
the class AbstractSpecificIntegrationTest method createSpanner.
private static void createSpanner() throws IOException {
// generate a unique instance id for this test run
Random rnd = new Random();
instanceId = "test-instance-" + rnd.nextInt(1000000);
credentialsPath = getKeyFile();
projectId = getProject();
GoogleCredentials credentials = CloudSpannerConnection.getCredentialsFromFile(credentialsPath);
Builder builder = SpannerOptions.newBuilder();
builder.setProjectId(projectId);
builder.setCredentials(credentials);
builder.setHost(getHost());
SpannerOptions options = builder.build();
spanner = options.getService();
}
use of com.google.cloud.spanner.SpannerOptions in project spring-cloud-gcp by spring-cloud.
the class GcpSpannerEmulatorAutoConfigurationTests method testEmulatorAutoConfigurationDisabled.
@Test
public void testEmulatorAutoConfigurationDisabled() {
this.contextRunner.run(context -> {
SpannerOptions spannerOptions = context.getBean(SpannerOptions.class);
assertThat(spannerOptions.getEndpoint()).isEqualTo("spanner.googleapis.com:443");
});
}
use of com.google.cloud.spanner.SpannerOptions in project spring-cloud-gcp by spring-cloud.
the class GcpSpannerEmulatorAutoConfigurationTests method testEmulatorAutoConfigurationEnabledCustomHostPort.
@Test
public void testEmulatorAutoConfigurationEnabledCustomHostPort() {
this.contextRunner.withPropertyValues("spring.cloud.gcp.spanner.emulator.enabled=true", "spring.cloud.gcp.spanner.emulator-host=localhost:9090").run(context -> {
SpannerOptions spannerOptions = context.getBean(SpannerOptions.class);
assertThat(spannerOptions.getEndpoint()).isEqualTo("localhost:9090");
});
}
Aggregations