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 @@ -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;
Expand All @@ -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 =
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading