@@ -525,6 +525,44 @@ public void testWrite() {
525
525
assertEquals (Priority .PRIORITY_UNSPECIFIED , commit .getRequestOptions ().getPriority ());
526
526
}
527
527
528
+ @ Test
529
+ public void testWriteAborted () {
530
+ DatabaseClient client =
531
+ spanner .getDatabaseClient (DatabaseId .of (TEST_PROJECT , TEST_INSTANCE , TEST_DATABASE ));
532
+ // Force the Commit RPC to return Aborted the first time it is called. The exception is cleared
533
+ // after the first call, so the retry should succeed.
534
+ mockSpanner .setCommitExecutionTime (
535
+ SimulatedExecutionTime .ofException (
536
+ mockSpanner .createAbortedException (ByteString .copyFromUtf8 ("test" ))));
537
+ Timestamp timestamp =
538
+ client .write (
539
+ Collections .singletonList (
540
+ Mutation .newInsertBuilder ("FOO" ).set ("ID" ).to (1L ).set ("NAME" ).to ("Bar" ).build ()));
541
+ assertNotNull (timestamp );
542
+
543
+ List <CommitRequest > commitRequests = mockSpanner .getRequestsOfType (CommitRequest .class );
544
+ assertEquals (2 , commitRequests .size ());
545
+ }
546
+
547
+ @ Test
548
+ public void testWriteAtLeastOnceAborted () {
549
+ DatabaseClient client =
550
+ spanner .getDatabaseClient (DatabaseId .of (TEST_PROJECT , TEST_INSTANCE , TEST_DATABASE ));
551
+ // Force the Commit RPC to return Aborted the first time it is called. The exception is cleared
552
+ // after the first call, so the retry should succeed.
553
+ mockSpanner .setCommitExecutionTime (
554
+ SimulatedExecutionTime .ofException (
555
+ mockSpanner .createAbortedException (ByteString .copyFromUtf8 ("test" ))));
556
+ Timestamp timestamp =
557
+ client .writeAtLeastOnce (
558
+ Collections .singletonList (
559
+ Mutation .newInsertBuilder ("FOO" ).set ("ID" ).to (1L ).set ("NAME" ).to ("Bar" ).build ()));
560
+ assertNotNull (timestamp );
561
+
562
+ List <CommitRequest > commitRequests = mockSpanner .getRequestsOfType (CommitRequest .class );
563
+ assertEquals (2 , commitRequests .size ());
564
+ }
565
+
528
566
@ Test
529
567
public void testWriteWithOptions () {
530
568
DatabaseClient client =
0 commit comments