diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ITTransactionRetryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ITTransactionRetryTest.java index da48f661790..2f82421fd21 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ITTransactionRetryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ITTransactionRetryTest.java @@ -18,8 +18,10 @@ import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; import org.junit.ClassRule; import org.junit.Test; @@ -36,6 +38,10 @@ public class ITTransactionRetryTest { @Test public void TestRetryInfo() { assumeFalse("emulator does not support parallel transaction", isUsingEmulator()); + // TODO(sakthivelmani) - Re-enable once b/422916293 is resolved + assumeFalse( + "Skipping the test due to a known bug b/422916293", + env.getTestHelper().getOptions().isEnableDirectAccess()); // Creating a database with the table which contains INT64 columns Database db = @@ -80,4 +86,56 @@ public void TestRetryInfo() { assertTrue("Transaction is not aborted with the trailers", isAbortedWithRetryInfo); } + + @Test + public void TestRetryInfoWithDirectPath() { + assumeFalse("emulator does not support parallel transaction", isUsingEmulator()); + // TODO(sakthivelmani) - Re-enable once b/422916293 is resolved + assumeTrue( + "Enabling this test due to bug b/422916293", + env.getTestHelper().getOptions().isEnableDirectAccess()); + + // Creating a database with the table which contains INT64 columns + Database db = + env.getTestHelper() + .createTestDatabase("CREATE TABLE Test(ID INT64, " + "EMPID INT64) PRIMARY KEY (ID)"); + DatabaseClient databaseClient = env.getTestHelper().getClient().getDatabaseClient(db.getId()); + + // Inserting one row + databaseClient + .readWriteTransaction() + .run( + transaction -> { + transaction.buffer( + Mutation.newInsertBuilder("Test").set("ID").to(1).set("EMPID").to(1).build()); + return null; + }); + + int numRetries = 10; + boolean isAbortedWithRetryInfo = false; + while (numRetries-- > 0) { + try (TransactionManager transactionManager1 = databaseClient.transactionManager()) { + try (TransactionManager transactionManager2 = databaseClient.transactionManager()) { + try { + TransactionContext transaction1 = transactionManager1.begin(); + TransactionContext transaction2 = transactionManager2.begin(); + transaction1.executeUpdate( + Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1")); + transaction2.executeUpdate( + Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1")); + transactionManager1.commit(); + transactionManager2.commit(); + } catch (AbortedException abortedException) { + assertThat(abortedException.getErrorCode()).isEqualTo(ErrorCode.ABORTED); + if (abortedException.getRetryDelayInMillis() > 0) { + isAbortedWithRetryInfo = true; + break; + } + } + } + } + } + + assertFalse("Transaction is aborted with the trailers", isAbortedWithRetryInfo); + } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITRetryDmlAsPartitionedDmlTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITRetryDmlAsPartitionedDmlTest.java index 476cf824013..fce97ab6ab8 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITRetryDmlAsPartitionedDmlTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITRetryDmlAsPartitionedDmlTest.java @@ -86,6 +86,10 @@ public static void setupTestData() { @Test public void testDmlFailsIfMutationLimitExceeded() { + // TODO(sakthivelmani) - Re-enable once b/422916293 is resolved + assumeFalse( + "Skipping the test due to a known bug b/422916293", + env.getTestHelper().getOptions().isEnableDirectAccess()); try (Connection connection = createConnection()) { connection.setAutocommit(true); assertThrows( @@ -98,6 +102,10 @@ public void testDmlFailsIfMutationLimitExceeded() { @Test public void testRetryDmlAsPartitionedDml() throws Exception { + // TODO(sakthivelmani) - Re-enable once b/422916293 is resolved + assumeFalse( + "Skipping the test due to a known bug b/422916293", + env.getTestHelper().getOptions().isEnableDirectAccess()); try (Connection connection = createConnection()) { connection.setAutocommit(true); connection.setAutocommitDmlMode( @@ -138,6 +146,10 @@ public void retryDmlAsPartitionedDmlFinished( @Test public void testRetryDmlAsPartitionedDml_failsForLargeInserts() throws Exception { + // TODO(sakthivelmani) - Re-enable once b/422916293 is resolved + assumeFalse( + "Skipping the test due to a known bug b/422916293", + env.getTestHelper().getOptions().isEnableDirectAccess()); try (Connection connection = createConnection()) { connection.setAutocommit(true); connection.setAutocommitDmlMode(