|
18 | 18 |
|
19 | 19 | import static org.junit.Assert.assertEquals;
|
20 | 20 | import static org.junit.Assert.assertFalse;
|
| 21 | +import static org.junit.Assert.assertNotNull; |
21 | 22 | import static org.junit.Assert.assertThrows;
|
22 | 23 | import static org.junit.Assert.assertTrue;
|
23 | 24 |
|
|
26 | 27 | import com.google.cloud.spanner.MockSpannerServiceImpl;
|
27 | 28 | import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
|
28 | 29 | import com.google.cloud.spanner.ResultSet;
|
| 30 | +import com.google.cloud.spanner.SpannerBatchUpdateException; |
29 | 31 | import com.google.cloud.spanner.SpannerException;
|
30 | 32 | import com.google.cloud.spanner.Statement;
|
31 | 33 | import com.google.cloud.spanner.TransactionMutationLimitExceededException;
|
|
34 | 36 | import com.google.rpc.Help.Link;
|
35 | 37 | import com.google.spanner.v1.BeginTransactionRequest;
|
36 | 38 | import com.google.spanner.v1.CommitRequest;
|
| 39 | +import com.google.spanner.v1.ExecuteBatchDmlRequest; |
37 | 40 | import com.google.spanner.v1.ExecuteSqlRequest;
|
38 | 41 | import io.grpc.Metadata;
|
39 | 42 | import io.grpc.Status;
|
@@ -219,4 +222,29 @@ public void testSqlStatements() {
|
219 | 222 | }
|
220 | 223 | }
|
221 | 224 | }
|
| 225 | + |
| 226 | + @Test |
| 227 | + public void testTransactionMutationLimitExceeded_isWrappedAsCauseOfBatchUpdateException() { |
| 228 | + String sql = "update test set value=1 where true"; |
| 229 | + Statement statement = Statement.of(sql); |
| 230 | + mockSpanner.putStatementResult( |
| 231 | + MockSpannerServiceImpl.StatementResult.exception( |
| 232 | + statement, createTransactionMutationLimitExceededException())); |
| 233 | + |
| 234 | + try (Connection connection = createConnection()) { |
| 235 | + connection.setAutocommit(true); |
| 236 | + assertEquals(AutocommitDmlMode.TRANSACTIONAL, connection.getAutocommitDmlMode()); |
| 237 | + |
| 238 | + connection.startBatchDml(); |
| 239 | + connection.execute(statement); |
| 240 | + SpannerBatchUpdateException batchUpdateException = |
| 241 | + assertThrows(SpannerBatchUpdateException.class, connection::runBatch); |
| 242 | + assertNotNull(batchUpdateException.getCause()); |
| 243 | + assertEquals( |
| 244 | + TransactionMutationLimitExceededException.class, |
| 245 | + batchUpdateException.getCause().getClass()); |
| 246 | + } |
| 247 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteBatchDmlRequest.class)); |
| 248 | + assertEquals(0, mockSpanner.countRequestsOfType(CommitRequest.class)); |
| 249 | + } |
222 | 250 | }
|
0 commit comments