-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: enables emulator tests #380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)); | ||
} | ||
} |
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()) { | ||
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); | ||
|
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( | ||
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(); | ||
|
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. | ||
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); | ||
|
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.