Skip to content

Commit 84045ef

Browse files
committed
chore(spanner): fix conection it tests
1 parent c9842c9 commit 84045ef

File tree

8 files changed

+74
-0
lines changed

8 files changed

+74
-0
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITAsyncTransactionRetryTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public boolean doCreateDefaultTestTable() {
9191
@Before
9292
public void clearTable() {
9393
try (ITConnection connection = createConnection()) {
94+
connection.execute(Statement.of("SELECT 1"));
95+
connection.commit();
9496
connection.bufferedWrite(Mutation.delete("TEST", KeySet.all()));
97+
//connection.executeUpdate(Statement.of("DELETE FROM TEST WHERE TRUE"));
9598
get(connection.commitAsync());
9699
}
97100
}
@@ -221,6 +224,7 @@ public void testCommitAborted() {
221224
AbortInterceptor interceptor = new AbortInterceptor(0);
222225
try (ITConnection connection =
223226
createConnection(interceptor, new CountTransactionRetryListener())) {
227+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
224228
ApiFuture<Long> count = getTestRecordCountAsync(connection);
225229
// do an insert
226230
ApiFuture<Long> updateCount =
@@ -253,6 +257,7 @@ public void testInsertAborted() {
253257
AbortInterceptor interceptor = new AbortInterceptor(0);
254258
try (ITConnection connection =
255259
createConnection(interceptor, new CountTransactionRetryListener())) {
260+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
256261
ApiFuture<Long> count = getTestRecordCountAsync(connection);
257262
// indicate that the next statement should abort
258263
interceptor.setProbability(1.0);
@@ -276,6 +281,7 @@ public void testUpdateAborted() {
276281
AbortInterceptor interceptor = new AbortInterceptor(0);
277282
try (ITConnection connection =
278283
createConnection(interceptor, new CountTransactionRetryListener())) {
284+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
279285
ApiFuture<Long> count = getTestRecordCountAsync(connection);
280286
// insert a test record
281287
connection.executeUpdateAsync(
@@ -309,6 +315,7 @@ public void testQueryAborted() {
309315
AbortInterceptor interceptor = new AbortInterceptor(0);
310316
try (ITConnection connection =
311317
createConnection(interceptor, new CountTransactionRetryListener())) {
318+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
312319
// insert a test record
313320
connection.executeUpdateAsync(
314321
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test aborted')"));
@@ -359,6 +366,7 @@ public void testNextCallAborted() {
359366
AbortInterceptor interceptor = new AbortInterceptor(0);
360367
try (ITConnection connection =
361368
createConnection(interceptor, new CountTransactionRetryListener())) {
369+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
362370
// insert two test records
363371
connection.executeUpdateAsync(
364372
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test 1')"));
@@ -392,6 +400,7 @@ public void testMultipleAborts() {
392400
AbortInterceptor interceptor = new AbortInterceptor(0);
393401
try (ITConnection connection =
394402
createConnection(interceptor, new CountTransactionRetryListener())) {
403+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
395404
ApiFuture<Long> count = getTestRecordCountAsync(connection);
396405
// do three inserts which all will abort and retry
397406
interceptor.setProbability(1.0);
@@ -428,6 +437,7 @@ public void testAbortAfterSelect() {
428437
AbortInterceptor interceptor = new AbortInterceptor(0);
429438
try (ITConnection connection =
430439
createConnection(interceptor, new CountTransactionRetryListener())) {
440+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
431441
ApiFuture<Long> count = getTestRecordCountAsync(connection);
432442
// insert a test record
433443
connection.executeUpdateAsync(
@@ -504,6 +514,7 @@ public void testAbortWithResultSetHalfway() {
504514
AbortInterceptor interceptor = new AbortInterceptor(0);
505515
try (ITConnection connection =
506516
createConnection(interceptor, new CountTransactionRetryListener())) {
517+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
507518
// insert two test records
508519
connection.executeUpdateAsync(
509520
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test 1')"));
@@ -539,6 +550,7 @@ public void testAbortWithResultSetFullyConsumed() {
539550
AbortInterceptor interceptor = new AbortInterceptor(0);
540551
try (ITConnection connection =
541552
createConnection(interceptor, new CountTransactionRetryListener())) {
553+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
542554
// insert two test records
543555
connection.executeUpdateAsync(
544556
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test 1')"));
@@ -581,6 +593,7 @@ public void testAbortWithConcurrentInsert() {
581593
AbortInterceptor interceptor = new AbortInterceptor(0);
582594
try (ITConnection connection =
583595
createConnection(interceptor, new CountTransactionRetryListener())) {
596+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
584597
// insert two test records
585598
connection.executeUpdateAsync(
586599
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test 1')"));
@@ -632,6 +645,7 @@ public void testAbortWithConcurrentDelete() {
632645
AbortInterceptor interceptor = new AbortInterceptor(0);
633646
// first insert two test records
634647
try (ITConnection connection = createConnection()) {
648+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
635649
connection.executeUpdateAsync(
636650
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test 1')"));
637651
connection.executeUpdateAsync(
@@ -641,6 +655,7 @@ public void testAbortWithConcurrentDelete() {
641655
// open a new connection and select the two test records
642656
try (ITConnection connection =
643657
createConnection(interceptor, new CountTransactionRetryListener())) {
658+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
644659
// select the test records and consume the entire result set
645660
try (AsyncResultSet rs =
646661
connection.executeQueryAsync(Statement.of("SELECT * FROM TEST ORDER BY ID"))) {
@@ -694,6 +709,7 @@ public void testAbortWithConcurrentUpdate() {
694709
// open a new connection and select the two test records
695710
try (ITConnection connection =
696711
createConnection(interceptor, new CountTransactionRetryListener())) {
712+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
697713
// select the test records and consume the entire result set
698714
try (AsyncResultSet rs =
699715
connection.executeQueryAsync(Statement.of("SELECT * FROM TEST ORDER BY ID"))) {
@@ -744,6 +760,7 @@ public void testAbortWithUnseenConcurrentInsert() throws InterruptedException {
744760
AbortInterceptor interceptor = new AbortInterceptor(0);
745761
try (ITConnection connection =
746762
createConnection(interceptor, new CountTransactionRetryListener())) {
763+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
747764
// insert three test records
748765
connection.executeUpdateAsync(
749766
Statement.of("INSERT INTO TEST (ID, NAME) VALUES (1, 'test 1')"));
@@ -833,6 +850,7 @@ public void testRetryLargeResultSet() {
833850
final long UPDATED_RECORDS = 1000L;
834851
AbortInterceptor interceptor = new AbortInterceptor(0);
835852
try (ITConnection connection = createConnection()) {
853+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
836854
// insert test records
837855
for (int i = 0; i < NUMBER_OF_TEST_RECORDS; i++) {
838856
connection.bufferedWrite(
@@ -845,6 +863,7 @@ public void testRetryLargeResultSet() {
845863
}
846864
try (ITConnection connection =
847865
createConnection(interceptor, new CountTransactionRetryListener())) {
866+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
848867
// select the test records and iterate over them
849868
try (AsyncResultSet rs =
850869
connection.executeQueryAsync(Statement.of("SELECT * FROM TEST ORDER BY ID"))) {
@@ -867,6 +886,7 @@ public void testRetryLargeResultSet() {
867886
// Wait until the entire result set has been consumed.
868887
get(finished);
869888
}
889+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
870890
// Do an update that will abort and retry.
871891
interceptor.setProbability(1.0);
872892
interceptor.setOnlyInjectOnce(true);
@@ -898,6 +918,7 @@ public void testRetryHighAbortRate() {
898918
AbortInterceptor interceptor = new AbortInterceptor(0.25D);
899919
try (ITConnection connection =
900920
createConnection(interceptor, new CountTransactionRetryListener())) {
921+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
901922
// insert test records
902923
for (int i = 0; i < NUMBER_OF_TEST_RECORDS; i++) {
903924
connection.bufferedWrite(

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITCommitResponseTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.Assert.assertTrue;
2424
import static org.junit.Assume.assumeFalse;
2525

26+
import com.google.cloud.spanner.BackupInfo.State;
2627
import com.google.cloud.spanner.KeySet;
2728
import com.google.cloud.spanner.Mutation;
2829
import com.google.cloud.spanner.ParallelIntegrationTest;
@@ -51,7 +52,10 @@ public boolean doCreateDefaultTestTable() {
5152
@Before
5253
public void clearTestData() {
5354
try (ITConnection connection = createConnection()) {
55+
connection.execute(Statement.of("SELECT 1"));
56+
connection.commit();
5457
connection.bufferedWrite(Mutation.delete("TEST", KeySet.all()));
58+
//connection.executeUpdate(Statement.of("DELETE FROM TEST WHERE TRUE"));
5559
connection.commit();
5660
}
5761
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITDelayBeginTransactionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public boolean doCreateDefaultTestTable() {
5353
@Before
5454
public void setupTestData() {
5555
try (ITConnection connection = createConnection()) {
56+
connection.execute(Statement.of("SELECT 1"));
57+
connection.commit();
5658
connection.bufferedWrite(Mutation.delete("TEST", KeySet.all()));
5759
connection.commit();
5860

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITExplainTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.cloud.spanner.Statement;
2929
import com.google.cloud.spanner.connection.Connection;
3030
import com.google.cloud.spanner.connection.ITAbstractSpannerTest;
31+
import com.google.common.collect.ImmutableList;
3132
import java.util.Arrays;
3233
import java.util.Collections;
3334
import org.junit.Before;
@@ -64,12 +65,19 @@ public void createTestTable() {
6465
connection.runBatch();
6566
}
6667
}
68+
try {
69+
Thread.sleep(3000);
70+
} catch (Exception e) {
71+
System.out.println(e);
72+
}
6773
}
6874

6975
@Test
7076
public void testExplainStatement() {
7177
assumeFalse("Emulator does not support PostgreSQL Dialect", isUsingEmulator());
7278
try (ITConnection connection = createConnection()) {
79+
connection.execute(Statement.of("SELECT 1"));
80+
connection.commit();
7381
connection.bufferedWrite(
7482
Arrays.asList(
7583
Mutation.newInsertBuilder("TEST").set("ID").to(3L).set("NAME").to("TEST-3").build(),
@@ -89,6 +97,8 @@ public void testExplainStatement() {
8997
public void testExplainAnalyzeStatement() {
9098
assumeFalse("Emulator does not support PostgreSQL Dialect", isUsingEmulator());
9199
try (ITConnection connection = createConnection()) {
100+
connection.execute(Statement.of("SELECT 1"));
101+
connection.commit();
92102
connection.bufferedWrite(
93103
Arrays.asList(
94104
Mutation.newInsertBuilder("TEST").set("ID").to(1L).set("NAME").to("TEST-1").build(),

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITSavepointTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public boolean doCreateDefaultTestTable() {
5151
@Before
5252
public void clearTestData() {
5353
try (ITConnection connection = createConnection()) {
54+
connection.execute(Statement.of("SELECT 1"));
55+
connection.commit();
5456
connection.bufferedWrite(Mutation.delete("TEST", KeySet.all()));
5557
connection.commit();
5658
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITSqlMusicScriptTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void test02_RunAbortedTest() {
7171
long numberOfSongs = 0L;
7272
AbortInterceptor interceptor = new AbortInterceptor(0.0D);
7373
try (ITConnection connection = createConnection(interceptor)) {
74+
interceptor.setUsingMultiplexedSession(isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
7475
connection.setAutocommit(false);
7576
connection.setRetryAbortsInternally(true);
7677
// Read all data from the different music tables in the transaction

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITTransactionModeTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public void testSqlScript() throws Exception {
6060
public void testDoAllowBufferedWriteInReadWriteTransaction() {
6161
try (ITConnection connection = createConnection()) {
6262
assertThat(connection.isAutocommit(), is(false));
63+
connection.execute(Statement.of("SELECT 1"));
64+
connection.commit();
6365
connection.bufferedWrite(
6466
Mutation.newInsertBuilder("TEST").set("ID").to(1L).set("NAME").to("TEST").build());
6567
connection.commit();

0 commit comments

Comments
 (0)