This repository was archived by the owner on Apr 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
fix: enables emulator tests #380
Merged
thiagotnunes
merged 4 commits into
googleapis:master
from
thiagotnunes:fix-enables-emulator-tests
Aug 13, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...e-cloud-spanner/src/main/java/com/google/cloud/spanner/testing/EmulatorSpannerHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright 2020 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.spanner.testing; | ||
|
|
||
| import com.google.common.base.Strings; | ||
|
|
||
| /** Utility class for checking emulator state for tests */ | ||
| public class EmulatorSpannerHelper { | ||
|
|
||
| public static final String SPANNER_EMULATOR_HOST = "SPANNER_EMULATOR_HOST"; | ||
|
|
||
| /** | ||
| * Checks whether the emulator is being used. This is done by checking if the | ||
| * SPANNER_EMULATOR_HOST environment variable is set. | ||
| * | ||
| * @return true if the emulator is being used. Returns false otherwise. | ||
| */ | ||
| public static boolean isUsingEmulator() { | ||
| return !Strings.isNullOrEmpty(System.getenv(SPANNER_EMULATOR_HOST)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| 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; | ||
|
|
@@ -79,7 +80,7 @@ protected void before() throws Throwable { | |
| SpannerOptions options = config.spannerOptions(); | ||
| String instanceProperty = System.getProperty(TEST_INSTANCE_PROPERTY, ""); | ||
| InstanceId instanceId; | ||
| if (!instanceProperty.isEmpty()) { | ||
| if (!instanceProperty.isEmpty() && !isUsingEmulator()) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needed to be updated so that the tests run properly with the emulator. This enables a new spanner instance to be created when running with the emulator. |
||
| instanceId = InstanceId.of(instanceProperty); | ||
| isOwnedInstance = false; | ||
| logger.log(Level.INFO, "Using existing test instance: {0}", instanceId); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.Assert.fail; | ||
| import static org.junit.Assume.assumeFalse; | ||
|
|
||
| import com.google.api.core.ApiFuture; | ||
| import com.google.cloud.spanner.AsyncResultSet; | ||
|
|
@@ -279,9 +278,6 @@ public void columnNotFound() throws Exception { | |
|
|
||
| @Test | ||
| public void asyncRunnerFireAndForgetInvalidUpdate() throws Exception { | ||
| assumeFalse( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enables this test to use the emulator. |
||
| "errors in read/write transactions on emulator are sticky", | ||
| env.getTestHelper().isEmulator()); | ||
| try { | ||
| assertThat(client.singleUse().readRow("TestTable", Key.of("k999"), ALL_COLUMNS)).isNull(); | ||
| AsyncRunner runner = client.runAsync(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ | |
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.fail; | ||
| import static org.junit.Assume.assumeFalse; | ||
|
|
||
| import com.google.cloud.spanner.AbortedException; | ||
| import com.google.cloud.spanner.Database; | ||
|
|
@@ -61,10 +60,6 @@ public class ITClosedSessionTest { | |
|
|
||
| @BeforeClass | ||
| public static void setUpDatabase() { | ||
| // TODO: Enable when the emulator returns ResourceInfo for Session not found errors. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enables this test to use the emulator. |
||
| assumeFalse( | ||
| "Emulator does not return ResourceInfo for Session not found errors", | ||
| env.getTestHelper().isEmulator()); | ||
| // Empty database. | ||
| db = env.getTestHelper().createTestDatabase(); | ||
| client = (DatabaseClientWithClosedSessionImpl) env.getTestHelper().getDatabaseClient(db); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactors: deprecate this method and use the newly created method.