diff --git a/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java b/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java index b49fb1ef5d70..eaea833491b9 100644 --- a/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java +++ b/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkState; +import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spanner.spi.v1.SpannerInterceptorProvider; import io.grpc.CallOptions; import io.grpc.Channel; @@ -28,6 +29,8 @@ import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; +import java.io.FileInputStream; +import java.io.IOException; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; @@ -35,6 +38,7 @@ public class GceTestEnvConfig implements TestEnvConfig { public static final String GCE_PROJECT_ID = "spanner.gce.config.project_id"; public static final String GCE_SERVER_URL = "spanner.gce.config.server_url"; + public static final String GCE_CREDENTIALS_FILE = "spanner.gce.config.credentials_file"; public static final String GCE_STREAM_BROKEN_PROBABILITY = "spanner.gce.config.stream_broken_probability"; @@ -43,6 +47,7 @@ public class GceTestEnvConfig implements TestEnvConfig { public GceTestEnvConfig() { String projectId = System.getProperty(GCE_PROJECT_ID, ""); String serverUrl = System.getProperty(GCE_SERVER_URL, ""); + String credentialsFile = System.getProperty(GCE_CREDENTIALS_FILE, ""); double errorProbability = Double.parseDouble(System.getProperty(GCE_STREAM_BROKEN_PROBABILITY, "0.0")); checkState(errorProbability <= 1.0); @@ -53,6 +58,13 @@ public GceTestEnvConfig() { if (!serverUrl.isEmpty()) { builder.setHost(serverUrl); } + if (!credentialsFile.isEmpty()) { + try { + builder.setCredentials(GoogleCredentials.fromStream(new FileInputStream(credentialsFile))); + } catch (IOException e) { + throw new RuntimeException(e); + } + } options = builder .setInterceptorProvider(