Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 519e870

Browse files
Add tests to fail if gRPC trailers are present
1 parent b35e892 commit 519e870

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ITTransactionRetryTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
2020
import static com.google.common.truth.Truth.assertThat;
21+
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertTrue;
2223
import static org.junit.Assume.assumeFalse;
24+
import static org.junit.Assume.assumeTrue;
2325

2426
import org.junit.ClassRule;
2527
import org.junit.Test;
@@ -84,4 +86,56 @@ public void TestRetryInfo() {
8486

8587
assertTrue("Transaction is not aborted with the trailers", isAbortedWithRetryInfo);
8688
}
89+
90+
@Test
91+
public void TestRetryInfoWithDirectPath() {
92+
assumeFalse("emulator does not support parallel transaction", isUsingEmulator());
93+
// TODO(sakthivelmani) - Re-enable once b/422916293 is resolved
94+
assumeTrue(
95+
"Enabling this test due to bug b/422916293",
96+
env.getTestHelper().getOptions().isEnableDirectAccess());
97+
98+
// Creating a database with the table which contains INT64 columns
99+
Database db =
100+
env.getTestHelper()
101+
.createTestDatabase("CREATE TABLE Test(ID INT64, " + "EMPID INT64) PRIMARY KEY (ID)");
102+
DatabaseClient databaseClient = env.getTestHelper().getClient().getDatabaseClient(db.getId());
103+
104+
// Inserting one row
105+
databaseClient
106+
.readWriteTransaction()
107+
.run(
108+
transaction -> {
109+
transaction.buffer(
110+
Mutation.newInsertBuilder("Test").set("ID").to(1).set("EMPID").to(1).build());
111+
return null;
112+
});
113+
114+
int numRetries = 10;
115+
boolean isAbortedWithRetryInfo = false;
116+
while (numRetries-- > 0) {
117+
try (TransactionManager transactionManager1 = databaseClient.transactionManager()) {
118+
try (TransactionManager transactionManager2 = databaseClient.transactionManager()) {
119+
try {
120+
TransactionContext transaction1 = transactionManager1.begin();
121+
TransactionContext transaction2 = transactionManager2.begin();
122+
transaction1.executeUpdate(
123+
Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1"));
124+
transaction2.executeUpdate(
125+
Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1"));
126+
transactionManager1.commit();
127+
transactionManager2.commit();
128+
} catch (AbortedException abortedException) {
129+
assertThat(abortedException.getErrorCode()).isEqualTo(ErrorCode.ABORTED);
130+
if (abortedException.getRetryDelayInMillis() > 0) {
131+
isAbortedWithRetryInfo = true;
132+
break;
133+
}
134+
}
135+
}
136+
}
137+
}
138+
139+
assertFalse("Transaction is aborted with the trailers", isAbortedWithRetryInfo);
140+
}
87141
}

0 commit comments

Comments
 (0)