@@ -4594,6 +4594,7 @@ public void testGetResolvesToPersistentCacheWhenOfflineAndNoListeners()
4594
4594
db .setPersistenceEnabled (true );
4595
4595
DatabaseReference node = db .getReference ().push ();
4596
4596
long val = 34 ;
4597
+ Thread .currentThread ().getId ();
4597
4598
4598
4599
try {
4599
4600
await (node .setValue (val ));
@@ -4602,6 +4603,7 @@ public void testGetResolvesToPersistentCacheWhenOfflineAndNoListeners()
4602
4603
DataSnapshot snapshot =
4603
4604
await (node .get ()); // This does not time out. We need to get it to do so.
4604
4605
assertEquals (val , snapshot .getValue ());
4606
+ db .goOnline ();
4605
4607
} catch (ExecutionException e ) {
4606
4608
fail ("get threw an exception: " + e );
4607
4609
}
@@ -4615,38 +4617,39 @@ public void testGetResolvesToCacheWhenOnlineAndParentListener()
4615
4617
// To ensure that we don't read the cached results, we need a separate app.
4616
4618
FirebaseApp readApp =
4617
4619
appForDatabaseUrl (IntegrationTestValues .getDatabaseUrl (), UUID .randomUUID ().toString ());
4620
+ // String topLevelKey = UUID.randomUUID().toString();
4618
4621
FirebaseDatabase writeDb = FirebaseDatabase .getInstance (writeApp );
4619
4622
FirebaseDatabase readDb = FirebaseDatabase .getInstance (readApp );
4620
4623
long val = 34 ;
4621
- DatabaseReference node = writeDb .getReference ().push ();
4624
+ DatabaseReference writeNode = writeDb .getReference ().push ();
4625
+ String writeKey = writeNode .getKey ();
4626
+ DatabaseReference readNode = readDb .getReference ().child (writeKey );
4622
4627
4623
4628
try {
4624
- await (node .setValue (val ));
4629
+ await (writeNode .setValue (val ));
4625
4630
DatabaseReference topLevelNode = readDb .getReference ();
4626
- new ReadFuture (
4631
+ ReadFuture readFuture =
4632
+ new ReadFuture (
4627
4633
topLevelNode ,
4628
4634
events -> {
4629
4635
assertEquals (1 , events .size ());
4630
- DataSnapshot childNode = events .get (0 ).getSnapshot ().child (node . getKey () );
4636
+ DataSnapshot childNode = events .get (0 ).getSnapshot ().child (writeKey );
4631
4637
assertEquals (34L , childNode .getValue ());
4632
- DataSnapshot snapshot = null ;
4633
- try {
4634
- snapshot = await (node .get ());
4635
- } catch (ExecutionException | InterruptedException e ) {
4636
- e .printStackTrace ();
4637
- }
4638
- assertEquals (val , Objects .requireNonNull (snapshot .getValue ()));
4638
+
4639
4639
return true ;
4640
- })
4641
- .timedGet ();
4640
+ });
4641
+ readFuture .timedGet ();
4642
+ DataSnapshot snapshot = null ;
4643
+ snapshot = await (readNode .get ());
4644
+ assertEquals (val , Objects .requireNonNull (snapshot .getValue ()));
4642
4645
} catch (TestFailure | TimeoutException | ExecutionException e ) {
4643
4646
e .printStackTrace ();
4644
4647
}
4645
4648
}
4646
4649
4647
4650
@ Test
4648
4651
public void testGetResolvesToCacheWhenOnlineAndSameLevelListener ()
4649
- throws DatabaseException , InterruptedException , ExecutionException {
4652
+ throws DatabaseException , InterruptedException , ExecutionException {
4650
4653
FirebaseApp writeApp =
4651
4654
appForDatabaseUrl (IntegrationTestValues .getDatabaseUrl (), UUID .randomUUID ().toString ());
4652
4655
// To ensure that we don't read the cached results, we need a separate app.
@@ -4720,7 +4723,7 @@ public void onCancelled(@NonNull DatabaseError error) {
4720
4723
db .goOffline ();
4721
4724
DataSnapshot snapshot = await (node .get ());
4722
4725
assertEquals (val , snapshot .getValue ());
4723
- // need to rewrite it
4726
+ db . goOnline ();
4724
4727
} catch (ExecutionException e ) {
4725
4728
fail ("get threw an exception: " + e );
4726
4729
}
0 commit comments