Skip to content

Commit

Permalink
test: enable more tests on the Emulator (#3535)
Browse files Browse the repository at this point in the history
Multiple tests were skipped on the Emulator, because the features that
are covered by these tests were originally not supported on the
Emulator. These features are now available on the Emulator, and the
tests can be enabled.
  • Loading branch information
olavloite authored Dec 9, 2024
1 parent 4501a3e commit 10912a6
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package com.google.cloud.spanner.connection.it;

import static com.google.cloud.spanner.SpannerApiFutures.get;
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
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.api.core.SettableApiFuture;
Expand Down Expand Up @@ -580,7 +578,6 @@ public void testAbortWithResultSetFullyConsumed() {

@Test
public void testAbortWithConcurrentInsert() {
assumeFalse("concurrent transactions are not supported on the emulator", isUsingEmulator());
AbortInterceptor interceptor = new AbortInterceptor(0);
try (ITConnection connection =
createConnection(interceptor, new CountTransactionRetryListener())) {
Expand Down Expand Up @@ -632,7 +629,6 @@ public void testAbortWithConcurrentInsert() {

@Test
public void testAbortWithConcurrentDelete() {
assumeFalse("concurrent transactions are not supported on the emulator", isUsingEmulator());
AbortInterceptor interceptor = new AbortInterceptor(0);
// first insert two test records
try (ITConnection connection = createConnection()) {
Expand Down Expand Up @@ -686,7 +682,6 @@ public void testAbortWithConcurrentDelete() {

@Test
public void testAbortWithConcurrentUpdate() {
assumeFalse("concurrent transactions are not supported on the emulator", isUsingEmulator());
AbortInterceptor interceptor = new AbortInterceptor(0);
// first insert two test records
try (ITConnection connection = createConnection()) {
Expand Down Expand Up @@ -746,7 +741,6 @@ public void testAbortWithConcurrentUpdate() {
*/
@Test
public void testAbortWithUnseenConcurrentInsert() throws InterruptedException {
assumeFalse("concurrent transactions are not supported on the emulator", isUsingEmulator());
AbortInterceptor interceptor = new AbortInterceptor(0);
try (ITConnection connection =
createConnection(interceptor, new CountTransactionRetryListener())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
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.EmulatorSpannerHelper.isUsingEmulator;
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 @@ -96,10 +94,7 @@ public class ITBatchReadTest {
public static List<DialectTestParameter> data() {
List<DialectTestParameter> params = new ArrayList<>();
params.add(new DialectTestParameter(Dialect.GOOGLE_STANDARD_SQL));
// PG dialect tests are not supported by the emulator
if (!isUsingEmulator()) {
params.add(new DialectTestParameter(Dialect.POSTGRESQL));
}
params.add(new DialectTestParameter(Dialect.POSTGRESQL));
return params;
}

Expand Down Expand Up @@ -135,30 +130,28 @@ public static void setUpDatabase() throws Exception {
List<DatabaseClient> databaseClients = new ArrayList<>();
databaseClients.add(env.getTestHelper().getDatabaseClient(googleStandardDatabase));

if (!isUsingEmulator()) {
postgreSQLDatabase =
env.getTestHelper().createTestDatabase(Dialect.POSTGRESQL, Collections.emptyList());
env.getTestHelper()
.getClient()
.getDatabaseAdminClient()
.updateDatabaseDdl(
env.getTestHelper().getInstanceId().getInstance(),
postgreSQLDatabase.getId().getDatabase(),
ImmutableList.of(
"CREATE TABLE "
+ TABLE_NAME
+ " ("
+ " Key bigint not null primary key,"
+ " Data bytea,"
+ " Fingerprint bigint,"
+ " Size bigint"
+ ")",
"CREATE INDEX " + INDEX_NAME + " ON " + TABLE_NAME + "(Fingerprint)"),
null)
.get();
postgreSQLBatchClient = env.getTestHelper().getBatchClient(postgreSQLDatabase);
databaseClients.add(env.getTestHelper().getDatabaseClient(postgreSQLDatabase));
}
postgreSQLDatabase =
env.getTestHelper().createTestDatabase(Dialect.POSTGRESQL, Collections.emptyList());
env.getTestHelper()
.getClient()
.getDatabaseAdminClient()
.updateDatabaseDdl(
env.getTestHelper().getInstanceId().getInstance(),
postgreSQLDatabase.getId().getDatabase(),
ImmutableList.of(
"CREATE TABLE "
+ TABLE_NAME
+ " ("
+ " Key bigint not null primary key,"
+ " Data bytea,"
+ " Fingerprint bigint,"
+ " Size bigint"
+ ")",
"CREATE INDEX " + INDEX_NAME + " ON " + TABLE_NAME + "(Fingerprint)"),
null)
.get();
postgreSQLBatchClient = env.getTestHelper().getBatchClient(postgreSQLDatabase);
databaseClients.add(env.getTestHelper().getDatabaseClient(postgreSQLDatabase));

List<Integer> rows = manyRows();
numRows = rows.size();
Expand Down Expand Up @@ -210,9 +203,6 @@ private Database getDatabase() {

@Test
public void read() {
assumeFalse(
"PostgreSQL does not support the PartitionRead RPC", dialect.dialect == Dialect.POSTGRESQL);

BitSet seenRows = new BitSet(numRows);
TimestampBound bound = getRandomBound();
PartitionOptions partitionParams = getRandomPartitionOptions();
Expand All @@ -229,9 +219,6 @@ public void read() {

@Test
public void readUsingIndex() {
assumeFalse(
"PostgreSQL does not support the PartitionRead RPC", dialect.dialect == Dialect.POSTGRESQL);

TimestampBound bound = getRandomBound();
PartitionOptions partitionParams = getRandomPartitionOptions();
batchTxn = getBatchClient().batchReadOnlyTransaction(bound);
Expand All @@ -258,8 +245,6 @@ public void readUsingIndex() {

@Test
public void dataBoostRead() {
assumeFalse("Emulator does not support data boost read", isUsingEmulator());

BitSet seenRows = new BitSet(numRows);
TimestampBound bound = getRandomBound();
PartitionOptions partitionParams = getRandomPartitionOptions();
Expand Down Expand Up @@ -312,7 +297,6 @@ private PartitionOptions getRandomPartitionOptions() {

@Test
public void dataBoostQuery() {
assumeFalse("Emulator does not support data boost query", isUsingEmulator());
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,14 +16,12 @@

package com.google.cloud.spanner.it;

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

import com.google.cloud.spanner.AbortedException;
import com.google.cloud.spanner.Database;
Expand Down Expand Up @@ -90,15 +88,13 @@ public static void setUpDatabase() {
+ " V INT64,"
+ ") PRIMARY KEY (K)");
googleStandardSQLClient = env.getTestHelper().getDatabaseClient(googleStandardSQLDatabase);
if (!isUsingEmulator()) {
Database postgreSQLDatabase =
env.getTestHelper()
.createTestDatabase(
Dialect.POSTGRESQL,
Arrays.asList(
"CREATE TABLE T (" + " K VARCHAR PRIMARY KEY," + " V BIGINT" + ")"));
postgreSQLClient = env.getTestHelper().getDatabaseClient(postgreSQLDatabase);
}
Database postgreSQLDatabase =
env.getTestHelper()
.createTestDatabase(
Dialect.POSTGRESQL,
Arrays.asList(
"CREATE TABLE T (" + " K VARCHAR PRIMARY KEY," + " V BIGINT" + ")"));
postgreSQLClient = env.getTestHelper().getDatabaseClient(postgreSQLDatabase);
}

@AfterClass
Expand All @@ -122,10 +118,7 @@ public void increaseTestIdAndDeleteTestData() {
public static List<DialectTestParameter> data() {
List<DialectTestParameter> params = new ArrayList<>();
params.add(new DialectTestParameter(Dialect.GOOGLE_STANDARD_SQL));
// "PG dialect tests are not supported by the emulator"
if (!isUsingEmulator()) {
params.add(new DialectTestParameter(Dialect.POSTGRESQL));
}
params.add(new DialectTestParameter(Dialect.POSTGRESQL));
return params;
}

Expand Down Expand Up @@ -389,10 +382,6 @@ public void standardDMLWithExecuteSQL() {

@Test
public void testUntypedNullValues() {
assumeFalse(
"Spanner PostgreSQL does not yet support untyped null values",
dialect.dialect == Dialect.POSTGRESQL);

DatabaseClient client = getClient(dialect.dialect);
String sql;
if (dialect.dialect == Dialect.POSTGRESQL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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 @@ -182,8 +181,6 @@ public void instanceNotFound() {

@Test
public void testNumericPrimaryKey() {
assumeFalse("Emulator does not support numeric primary keys", isUsingEmulator());

final String table = "NumericTable";

// Creates table with numeric primary key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.google.cloud.spanner.TransactionRunner;
import com.google.cloud.spanner.TransactionRunner.TransactionCallable;
import com.google.cloud.spanner.connection.ConnectionOptions;
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -75,8 +74,6 @@ public final class ITDmlReturningTest {

@BeforeClass
public static void setUpDatabase() {
assumeFalse(
"DML Returning is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
Database googleStandardSQLDatabase =
env.getTestHelper()
.createTestDatabase(
Expand All @@ -85,18 +82,16 @@ public static void setUpDatabase() {
+ " V INT64,"
+ ") PRIMARY KEY (K)");
googleStandardSQLClient = env.getTestHelper().getDatabaseClient(googleStandardSQLDatabase);
if (!isUsingEmulator()) {
Database postgreSQLDatabase =
env.getTestHelper()
.createTestDatabase(
Dialect.POSTGRESQL,
Collections.singletonList(
"CREATE TABLE T ("
+ " \"K\" VARCHAR PRIMARY KEY,"
+ " \"V\" BIGINT"
+ ")"));
postgreSQLClient = env.getTestHelper().getDatabaseClient(postgreSQLDatabase);
}
Database postgreSQLDatabase =
env.getTestHelper()
.createTestDatabase(
Dialect.POSTGRESQL,
Collections.singletonList(
"CREATE TABLE T ("
+ " \"K\" VARCHAR PRIMARY KEY,"
+ " \"V\" BIGINT"
+ ")"));
postgreSQLClient = env.getTestHelper().getDatabaseClient(postgreSQLDatabase);
}

@AfterClass
Expand Down Expand Up @@ -222,6 +217,9 @@ private void executeUpdateAsync(long expectedCount, final String... stmts) {

@Test
public void dmlReturningWithExecutePartitionedUpdate() {
assumeFalse(
"The emulator does not dis-allow THEN RETURN statements for PDML", isUsingEmulator());

SpannerException e =
assertThrows(
SpannerException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

package com.google.cloud.spanner.it;

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Database;
Expand Down Expand Up @@ -93,8 +91,6 @@ public static List<DialectTestParameter> data() {
@BeforeClass
public static void setUpDatabase()
throws ExecutionException, InterruptedException, TimeoutException {
assumeFalse("Emulator does not support FLOAT32 yet", isUsingEmulator());

Database googleStandardSQLDatabase =
env.getTestHelper().createTestDatabase(GOOGLE_STANDARD_SQL_SCHEMA);

Expand Down
Loading

0 comments on commit 10912a6

Please sign in to comment.