use of com.google.cloud.spanner.SpannerOptions.Builder 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.Builder 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.Builder in project spanner-jdbc by olavloite.
the class CloudSpannerDriver method createSpanner.
private Spanner createSpanner(SpannerKey key) {
Builder builder = SpannerOptions.newBuilder();
if (key.projectId != null)
builder.setProjectId(key.projectId);
if (key.credentials != null)
builder.setCredentials(key.credentials);
else if (!hasDefaultCredentials())
builder.setCredentials(NoCredentials.getInstance());
if (key.host != null)
builder.setHost(key.host);
SpannerOptions options = builder.build();
return options.getService();
}
Aggregations