Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,11 @@ protected SpannerOptions(Builder builder) {
openTelemetry = builder.openTelemetry;
enableApiTracing = builder.enableApiTracing;
enableExtendedTracing = builder.enableExtendedTracing;
enableBuiltInMetrics = builder.enableBuiltInMetrics;
if (builder.isExperimentalHost) {
enableBuiltInMetrics = false;
} else {
enableBuiltInMetrics = builder.enableBuiltInMetrics;
}
enableEndToEndTracing = builder.enableEndToEndTracing;
monitoringHost = builder.monitoringHost;
defaultTransactionOptions = builder.defaultTransactionOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.cloud.NoCredentials;
import com.google.cloud.spanner.SpannerOptions;
import com.google.common.base.Strings;
import io.grpc.ManagedChannelBuilder;

public class ExperimentalHostHelper {
private static final String EXPERIMENTAL_HOST = "spanner.experimental_host";
private static final String USE_PLAIN_TEXT = "spanner.use_plain_text";
private static final String USE_MTLS = "spanner.mtls";
private static final String CLIENT_CERT_PATH = "spanner.client_cert_path";
private static final String CLIENT_CERT_KEY_PATH = "spanner.client_cert_key_path";

/**
* 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 isExperimentalHost() {
return !Strings.isNullOrEmpty(System.getProperty(EXPERIMENTAL_HOST));
}

public static void appendExperimentalHost(StringBuilder uri) {
uri.append(";isExperimentalHost=true");
if (isMtlsSetup()) {
String clientCertificate = System.getProperty(CLIENT_CERT_PATH, "");
String clientKey = System.getProperty(CLIENT_CERT_KEY_PATH, "");
uri.append(";clientCertificate=").append(clientCertificate);
uri.append(";clientKey=").append(clientKey);
}
}

public static boolean isMtlsSetup() {
return Boolean.getBoolean(USE_MTLS);
}

public static void setExperimentalHostSpannerOptions(SpannerOptions.Builder builder) {
String experimentalHost = System.getProperty(EXPERIMENTAL_HOST, "");
boolean usePlainText = Boolean.getBoolean(USE_PLAIN_TEXT);
builder.setExperimentalHost(experimentalHost);
builder.setBuiltInMetricsEnabled(false);
if (usePlainText) {
builder
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.setCredentials(NoCredentials.getInstance());
}
if (isMtlsSetup()) {
String clientCertificate = System.getProperty(CLIENT_CERT_PATH, "");
String clientKey = System.getProperty(CLIENT_CERT_KEY_PATH, "");
builder.useClientCert(clientCertificate, clientKey);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.cloud.spanner;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.setExperimentalHostSpannerOptions;
import static com.google.common.base.Preconditions.checkState;

import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
Expand Down Expand Up @@ -101,6 +103,10 @@ public GceTestEnvConfig() {
.setInterceptorProvider(interceptorProvider);
builder.setChannelProvider(customChannelProviderBuilder.build());
}

if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
options = builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.google.cloud.spanner;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assume.assumeFalse;

import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory;
import com.google.cloud.spanner.SessionPool.PooledSessionFuture;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class ITSessionPoolIntegrationTest {

@BeforeClass
public static void setUpDatabase() {
assumeFalse("Only Multiplexed Sessions are supported on this host", isExperimentalHost());
db =
env.getTestHelper()
.createTestDatabase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -42,6 +43,7 @@ public void TestRetryInfo() {
assumeFalse(
"Skipping the test due to a known bug b/422916293",
env.getTestHelper().getOptions().isEnableDirectAccess());
assumeFalse("Skipping the test due to a known bug b/422916293", isExperimentalHost());

// Creating a database with the table which contains INT64 columns
Database db =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.base.Preconditions.checkState;
import static org.junit.Assume.assumeFalse;

Expand Down Expand Up @@ -130,6 +131,9 @@ boolean isCloudDevel() {
protected void before() throws Throwable {
this.initializeConfig();
assumeFalse(alwaysCreateNewInstance && isCloudDevel());
assumeFalse(
"Creating instances is not supported in experimental host",
alwaysCreateNewInstance && isExperimentalHost());

this.config.setUp();
SpannerOptions options = config.spannerOptions();
Expand Down Expand Up @@ -324,7 +328,7 @@ private void cleanUpInstance() {
if (isOwnedInstance) {
// Delete the instance, which implicitly drops all databases in it.
try {
if (!EmulatorSpannerHelper.isUsingEmulator()) {
if (!EmulatorSpannerHelper.isUsingEmulator() && !isExperimentalHost()) {
// Backups must be explicitly deleted before the instance may be deleted.
logger.log(
Level.FINE, "Deleting backups on test instance {0}", testHelper.getInstanceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.google.cloud.spanner.connection;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.appendExperimentalHost;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;

import com.google.cloud.NoCredentials;
import com.google.cloud.spanner.Database;
import com.google.cloud.spanner.ErrorCode;
Expand Down Expand Up @@ -236,6 +239,9 @@ public static StringBuilder extractConnectionUrl(SpannerOptions options, Databas
if (options.getCredentials() == NoCredentials.getInstance()) {
url.append(";usePlainText=true");
}
if (isExperimentalHost()) {
appendExperimentalHost(url);
}
return url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner.connection.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class ITRetryDmlAsPartitionedDmlTest extends ITAbstractSpannerTest {
public static void setup() {
// This shadows the setup() method in the super class and prevents it from being executed.
// That allows us to have a custom setup method in this class.
assumeFalse("Skipping the test due to a known bug b/422916293", isExperimentalHost());
}

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeFalse;
Expand Down Expand Up @@ -84,6 +85,7 @@ public static List<DatabaseDialect> data() {

@BeforeClass
public static void setUp() {
assumeFalse("Experimental Host does not support database roles", isExperimentalHost());
assumeFalse("Emulator does not support database roles", isUsingEmulator());
testHelper = env.getTestHelper();
dbAdminClient = testHelper.getClient().createDatabaseAdminClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import static com.google.cloud.spanner.connection.ITAbstractSpannerTest.extractConnectionUrl;
import static com.google.cloud.spanner.connection.ITAbstractSpannerTest.getKeyFile;
import static com.google.cloud.spanner.connection.ITAbstractSpannerTest.hasValidKeyFile;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import com.google.cloud.ByteArray;
import com.google.cloud.Timestamp;
Expand Down Expand Up @@ -247,6 +249,7 @@ public void readUsingIndex() {

@Test
public void dataBoostRead() {
assumeFalse("data boost is not supported on experimental host yet", isExperimentalHost());
BitSet seenRows = new BitSet(numRows);
TimestampBound bound = getRandomBound();
PartitionOptions partitionParams = getRandomPartitionOptions();
Expand Down Expand Up @@ -299,6 +302,7 @@ private PartitionOptions getRandomPartitionOptions() {

@Test
public void dataBoostQuery() {
assumeFalse("data boost is not supported on experimental host yet", isExperimentalHost());
BitSet seenRows = new BitSet(numRows);
TimestampBound bound = getRandomBound();
PartitionOptions partitionParams = getRandomPartitionOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assume.assumeFalse;

Expand Down Expand Up @@ -64,6 +65,7 @@ public class ITBuiltInMetricsTest {

@BeforeClass
public static void setUp() throws IOException {
assumeFalse("not applicable for experimental host", isExperimentalHost());
assumeFalse("This test requires credentials", EmulatorSpannerHelper.isUsingEmulator());
metricClient = MetricServiceClient.create();
// Enable BuiltinMetrics when the metrics are GA'ed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Database;
Expand Down Expand Up @@ -227,6 +229,9 @@ public void invalidColumnOptionValue() throws Exception {

@Test
public void invalidColumnType() throws Exception {
assumeFalse(
"Validation currently not available in experimental host mode - tracked via b/442339325",
isExperimentalHost());
// error_catalog error OptionErrorList
String statement = "ALTER TABLE T ADD COLUMN T4 INT64 OPTIONS (allow_commit_timestamp=true)";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -194,6 +195,7 @@ public void listPagination() {

@Test
public void createAndListDatabaseRoles() throws Exception {
assumeFalse("Experimental Host does not support database roles", isExperimentalHost());
assumeFalse("Emulator does not support create & list database roles", isUsingEmulator());
List<String> dbRoles =
ImmutableList.of(
Expand Down Expand Up @@ -274,6 +276,7 @@ public void updateDatabaseInvalidFieldsToUpdate() {

@Test
public void dropDatabaseWithProtectionEnabled() throws Exception {
assumeFalse("Tracking the failure via b/441255724", isExperimentalHost());
assumeFalse("Emulator does not drop database protection", isUsingEmulator());
String instanceId = testHelper.getInstanceId().getInstance();
Database database = testHelper.createTestDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeFalse;
Expand Down Expand Up @@ -73,6 +74,7 @@ public static List<DialectTestParameter> data() {

@BeforeClass
public static void setUp() {
assumeFalse("Experimental Host does not support database roles", isExperimentalHost());
assumeFalse("Emulator does not support database roles", isUsingEmulator());
testHelper = env.getTestHelper();
dbAdminClient = testHelper.getClient().getDatabaseAdminClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import com.google.api.client.util.ExponentialBackOff;
import com.google.api.gax.longrunning.OperationFuture;
Expand Down Expand Up @@ -166,6 +168,8 @@ public void databaseDeletedTest() throws Exception {

@Test
public void instanceNotFound() {
assumeFalse(
"experimental hosts only support pre-created default instance", isExperimentalHost());
InstanceId testId = env.getTestHelper().getInstanceId();
InstanceId nonExistingInstanceId =
InstanceId.of(testId.getProject(), testId.getInstance() + "-na");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assume.assumeFalse;

Expand Down Expand Up @@ -52,6 +53,9 @@ public class ITInstanceAdminTest {

@BeforeClass
public static void setUp() {
assumeFalse(
"instance / instanceConfig operations are not supported on experimental host",
isExperimentalHost());
instanceClient = env.getTestHelper().getClient().getInstanceAdminClient();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assume.assumeFalse;

import com.google.cloud.spanner.Database;
import com.google.cloud.spanner.DatabaseClient;
Expand Down Expand Up @@ -110,6 +112,7 @@ public void testWriteValidJsonValues() throws IOException {

@Test
public void testWriteAndReadInvalidJsonValues() throws IOException {
assumeFalse("Tracking the failure via b/441255097 for experimental host", isExperimentalHost());
List<String> resources = getJsonFilePaths(RESOURCES_DIR + File.separator + INVALID_JSON_DIR);

AtomicLong id = new AtomicLong(100);
Expand Down
Loading