@@ -82,8 +82,8 @@ private enum FromDocumentType {
82
82
* Used for testing that all possible combinations of executing transactions result in the desired
83
83
* document value or error.
84
84
*
85
- * <p>`run()`, `withExistingDoc()`,`withNonexistentDoc()` and `withDeletedDoc()` don't actually do
86
- * anything except assign variables into the TransactionTester.
85
+ * <p>`run()`, `withExistingDoc()`, `withNonexistentDoc()` and `withDeletedDoc()` don't actually
86
+ * do anything except assign variables into the TransactionTester.
87
87
*
88
88
* <p>`expectDoc()`, `expectNoDoc()`, and `expectError()` will trigger the transaction to run and
89
89
* assert that the end result matches the input.
@@ -188,7 +188,7 @@ private void prepareDoc() {
188
188
waitFor (docRef .delete ());
189
189
break ;
190
190
default :
191
- throw new Error ("invalid fromDocumentType: " + fromDocumentType );
191
+ throw new RuntimeException ("invalid fromDocumentType: " + fromDocumentType );
192
192
}
193
193
}
194
194
@@ -709,23 +709,23 @@ public void testDoesNotRetryOnPermanentError() {
709
709
public void testRetryOnAlreadyExistsError () {
710
710
final FirebaseFirestore firestore = testFirestore ();
711
711
DocumentReference doc = firestore .collection ("foo" ).document ();
712
- CountDownLatch latch = new CountDownLatch ( 2 );
712
+ AtomicInteger retryCount = new AtomicInteger ( 0 );
713
713
waitFor (
714
714
firestore .runTransaction (
715
715
transaction -> {
716
- latch . countDown ();
716
+ retryCount . getAndIncrement ();
717
717
transaction .get (doc );
718
718
// Do a write outside of the transaction.
719
- waitFor (doc .set (map ("count" , 1 )));
720
- // Now try to set the doc within the transaction.This should fail once
719
+ if ( retryCount . get () == 1 ) waitFor (doc .set (map ("count" , retryCount . get () )));
720
+ // Now try to set the doc within the transaction. This should fail once
721
721
// with ALREADY_EXISTS error.
722
- transaction .set (doc , map ("count" , 2 ));
722
+ transaction .set (doc , map ("count" , 22 ));
723
723
return null ;
724
724
}));
725
725
DocumentSnapshot snapshot = waitFor (doc .get ());
726
- assertEquals (0 , latch . getCount ());
726
+ assertEquals (2 , retryCount . get ());
727
727
assertTrue (snapshot .exists ());
728
- assertEquals (2L , snapshot .getData ().get ("count" ));
728
+ assertEquals (22L , snapshot .getData ().get ("count" ));
729
729
}
730
730
731
731
@ Test
0 commit comments