|
21 | 21 | import static org.junit.Assert.assertTrue; |
22 | 22 | import static org.junit.Assume.assumeFalse; |
23 | 23 |
|
24 | | -import org.junit.Assert; |
25 | 24 | import org.junit.ClassRule; |
26 | 25 | import org.junit.Test; |
27 | 26 | import org.junit.experimental.categories.Category; |
@@ -54,23 +53,31 @@ public void TestRetryInfo() { |
54 | 53 | return null; |
55 | 54 | }); |
56 | 55 |
|
57 | | - try (TransactionManager transactionManager1 = databaseClient.transactionManager()) { |
58 | | - try (TransactionManager transactionManager2 = databaseClient.transactionManager()) { |
59 | | - TransactionContext transaction1 = transactionManager1.begin(); |
60 | | - TransactionContext transaction2 = transactionManager2.begin(); |
61 | | - transaction1.executeUpdate(Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1")); |
62 | | - transaction2.executeUpdate(Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1")); |
63 | | - |
64 | | - AbortedException abortedException = |
65 | | - Assert.assertThrows( |
66 | | - AbortedException.class, |
67 | | - () -> { |
68 | | - transactionManager1.commit(); |
69 | | - transactionManager2.commit(); |
70 | | - }); |
71 | | - assertThat(abortedException.getErrorCode()).isEqualTo(ErrorCode.ABORTED); |
72 | | - assertTrue(abortedException.getRetryDelayInMillis() > 0); |
| 56 | + int numRetries = 10; |
| 57 | + boolean isAbortedWithRetryInfo = false; |
| 58 | + while(numRetries-- > 0) { |
| 59 | + try (TransactionManager transactionManager1 = databaseClient.transactionManager()) { |
| 60 | + try (TransactionManager transactionManager2 = databaseClient.transactionManager()) { |
| 61 | + try { |
| 62 | + TransactionContext transaction1 = transactionManager1.begin(); |
| 63 | + TransactionContext transaction2 = transactionManager2.begin(); |
| 64 | + transaction1.executeUpdate( |
| 65 | + Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1")); |
| 66 | + transaction2.executeUpdate( |
| 67 | + Statement.of("UPDATE Test SET EMPID = EMPID + 1 WHERE ID = 1")); |
| 68 | + transactionManager1.commit(); |
| 69 | + transactionManager2.commit(); |
| 70 | + } catch (AbortedException abortedException) { |
| 71 | + assertThat(abortedException.getErrorCode()).isEqualTo(ErrorCode.ABORTED); |
| 72 | + if(abortedException.getRetryDelayInMillis() > 0) { |
| 73 | + isAbortedWithRetryInfo = true; |
| 74 | + break; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
73 | 78 | } |
74 | 79 | } |
| 80 | + |
| 81 | + assertTrue("Transaction is not aborted with the trailers", isAbortedWithRetryInfo); |
75 | 82 | } |
76 | 83 | } |
0 commit comments