Search in sources :

Example 1 with Builder

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();
}
Also used : InstanceConfig(com.google.cloud.spanner.InstanceConfig) InstanceAdminClient(com.google.cloud.spanner.InstanceAdminClient) Builder(com.google.cloud.spanner.SpannerOptions.Builder) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) IOException(java.io.IOException) SpannerOptions(com.google.cloud.spanner.SpannerOptions) Spanner(com.google.cloud.spanner.Spanner) IntegrationTest(nl.topicus.jdbc.test.category.IntegrationTest) Test(org.junit.Test)

Example 2 with Builder

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();
}
Also used : Random(java.util.Random) Builder(com.google.cloud.spanner.SpannerOptions.Builder) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) SpannerOptions(com.google.cloud.spanner.SpannerOptions)

Example 3 with Builder

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();
}
Also used : Builder(com.google.cloud.spanner.SpannerOptions.Builder) SpannerOptions(com.google.cloud.spanner.SpannerOptions)

Aggregations

SpannerOptions (com.google.cloud.spanner.SpannerOptions)3 Builder (com.google.cloud.spanner.SpannerOptions.Builder)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 InstanceAdminClient (com.google.cloud.spanner.InstanceAdminClient)1 InstanceConfig (com.google.cloud.spanner.InstanceConfig)1 Spanner (com.google.cloud.spanner.Spanner)1 IOException (java.io.IOException)1 Random (java.util.Random)1 IntegrationTest (nl.topicus.jdbc.test.category.IntegrationTest)1 Test (org.junit.Test)1