1818
1919import static com .google .common .base .Preconditions .checkState ;
2020
21+ import com .google .auth .oauth2 .GoogleCredentials ;
2122import com .google .cloud .spanner .spi .v1 .SpannerInterceptorProvider ;
2223import io .grpc .CallOptions ;
2324import io .grpc .Channel ;
2829import io .grpc .Metadata ;
2930import io .grpc .MethodDescriptor ;
3031import io .grpc .Status ;
32+ import java .io .FileInputStream ;
33+ import java .io .IOException ;
3134import java .util .Random ;
3235import java .util .concurrent .atomic .AtomicBoolean ;
3336
3437/** Configure TestEnv based on configuration provided. */
3538public class GceTestEnvConfig implements TestEnvConfig {
3639 public static final String GCE_PROJECT_ID = "spanner.gce.config.project_id" ;
3740 public static final String GCE_SERVER_URL = "spanner.gce.config.server_url" ;
41+ public static final String GCE_CREDENTIALS_FILE = "spanner.gce.config.credentials_file" ;
3842 public static final String GCE_STREAM_BROKEN_PROBABILITY =
3943 "spanner.gce.config.stream_broken_probability" ;
4044
@@ -43,6 +47,7 @@ public class GceTestEnvConfig implements TestEnvConfig {
4347 public GceTestEnvConfig () {
4448 String projectId = System .getProperty (GCE_PROJECT_ID , "" );
4549 String serverUrl = System .getProperty (GCE_SERVER_URL , "" );
50+ String credentialsFile = System .getProperty (GCE_CREDENTIALS_FILE , "" );
4651 double errorProbability =
4752 Double .parseDouble (System .getProperty (GCE_STREAM_BROKEN_PROBABILITY , "0.0" ));
4853 checkState (errorProbability <= 1.0 );
@@ -53,6 +58,13 @@ public GceTestEnvConfig() {
5358 if (!serverUrl .isEmpty ()) {
5459 builder .setHost (serverUrl );
5560 }
61+ if (!credentialsFile .isEmpty ()) {
62+ try {
63+ builder .setCredentials (GoogleCredentials .fromStream (new FileInputStream (credentialsFile )));
64+ } catch (IOException e ) {
65+ throw new RuntimeException (e );
66+ }
67+ }
5668 options =
5769 builder
5870 .setInterceptorProvider (
0 commit comments