From c8fa458f5369a09c780ee38ecc09bd2562e8f987 Mon Sep 17 00:00:00 2001 From: Thiago Nunes Date: Tue, 18 Aug 2020 09:26:26 +1000 Subject: [PATCH] fix: sets the project for the integration tests (#386) The emulator uses the project set in order to list the instance configurations. If the none is set, it gets that information through the gcloud project set, which might mismatch the project being used to create the databases in the integration tests. This PR hardcodes the project so it matches the instance for the integration tests. Note it can still be overridden, instructions were added in the `CONTRIBUTING.md` file. --- CONTRIBUTING.md | 6 +++++- google-cloud-spanner/pom.xml | 3 ++- .../java/com/google/cloud/spanner/IntegrationTestEnv.java | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2dbdee06b..53d2460178 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,11 @@ integration tests. ```bash export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json -mvn -Penable-integration-tests clean verify +mvn \ + -Penable-integration-tests \ + -Dspanner.testenv.instance=projects//instances/ \ + -Dspanner.gce.config.project_id= \ + clean verify ``` ## Code Samples diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index f749be01b4..63db371d05 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -69,6 +69,7 @@ com.google.cloud.spanner.GceTestEnvConfig projects/gcloud-devel/instances/spanner-testing + gcloud-devel 3000 @@ -363,4 +364,4 @@ - \ No newline at end of file + diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java index 3d5263fb08..b67f970273 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java @@ -16,7 +16,6 @@ package com.google.cloud.spanner; -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; import static com.google.common.base.Preconditions.checkState; import com.google.api.gax.longrunning.OperationFuture; @@ -80,7 +79,7 @@ protected void before() throws Throwable { SpannerOptions options = config.spannerOptions(); String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, ""); InstanceId instanceId; - if (!instanceProperty.isEmpty() && !isUsingEmulator()) { + if (!instanceProperty.isEmpty()) { instanceId = InstanceId.of(instanceProperty); isOwnedInstance = false; logger.log(Level.INFO, "Using existing test instance: {0}", instanceId);