Skip to content

Commit 67bf0ce

Browse files
committed
Addressed comments
1 parent a590590 commit 67bf0ce

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

firebase-database/src/androidTest/java/com/google/firebase/database/IntegrationTestHelpers.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ public static void waitFor(Semaphore semaphore, int count, long timeout, TimeUni
334334
assertTrue("Operation timed out", success);
335335
}
336336

337+
// Note: This assumes that the key is at the root. If the key is nested, then another solution
338+
// needs to be found.
339+
public static DatabaseReference translateReference(DatabaseReference node, FirebaseDatabase db) {
340+
return db.getReference().child(node.getKey());
341+
}
342+
343+
public static DataSnapshot referenceAtPath(DatabaseReference node, EventRecord record) {
344+
return record.getSnapshot().child(node.getKey());
345+
}
346+
337347
public static DataSnapshot getSnap(Query ref) throws InterruptedException {
338348

339349
final Semaphore semaphore = new Semaphore(0);

firebase-database/src/androidTest/java/com/google/firebase/database/QueryTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4608,6 +4608,8 @@ public void testGetResolvesToPersistentCacheWhenOfflineAndNoListeners()
46084608
}
46094609
}
46104610

4611+
4612+
46114613
@Test
46124614
public void testGetResolvesToCacheWhenOnlineAndParentListener()
46134615
throws DatabaseException, InterruptedException {
@@ -4620,8 +4622,7 @@ public void testGetResolvesToCacheWhenOnlineAndParentListener()
46204622
FirebaseDatabase readDb = FirebaseDatabase.getInstance(readApp);
46214623
long val = 34;
46224624
DatabaseReference writeNode = writeDb.getReference().push();
4623-
String writeKey = writeNode.getKey();
4624-
DatabaseReference readNode = readDb.getReference().child(writeKey);
4625+
DatabaseReference readNode = IntegrationTestHelpers.translateReference(writeNode, readDb);
46254626

46264627
try {
46274628
await(writeNode.setValue(val));
@@ -4631,13 +4632,13 @@ public void testGetResolvesToCacheWhenOnlineAndParentListener()
46314632
topLevelNode,
46324633
events -> {
46334634
assertEquals(1, events.size());
4634-
DataSnapshot childNode = events.get(0).getSnapshot().child(writeKey);
4635+
DataSnapshot childNode = IntegrationTestHelpers.referenceAtPath(writeNode, events.get(0));
46354636
assertEquals(val, childNode.getValue());
46364637
return true;
46374638
});
46384639
readFuture.timedGet();
4639-
DataSnapshot snapshot = null;
4640-
snapshot = await(readNode.get());
4640+
DataSnapshot snapshot = await(readNode.get());
4641+
;
46414642
assertEquals(val, Objects.requireNonNull(snapshot.getValue()));
46424643
} catch (TestFailure | TimeoutException | ExecutionException e) {
46434644
e.printStackTrace();
@@ -4656,10 +4657,9 @@ public void testGetResolvesToCacheWhenOnlineAndSameLevelListener()
46564657
FirebaseDatabase writeDb = FirebaseDatabase.getInstance(writeApp);
46574658
FirebaseDatabase readDb = FirebaseDatabase.getInstance(readApp);
46584659
long val = 34;
4659-
String writeKey = Objects.requireNonNull(writeDb.getReference().push().getKey());
4660-
DatabaseReference writeNode = writeDb.getReference().child(writeKey);
4660+
DatabaseReference writeNode = writeDb.getReference().push();
46614661
await(writeNode.setValue(val));
4662-
DatabaseReference readNode = readDb.getReference().child(writeKey);
4662+
DatabaseReference readNode = IntegrationTestHelpers.translateReference(writeNode, readDb);
46634663
new ReadFuture(
46644664
readNode,
46654665
events -> {
@@ -4747,14 +4747,7 @@ public void onCancelled(@NonNull DatabaseError error) {
47474747

47484748
try {
47494749
await(childWriteNode.setValue(val));
4750-
new ReadFuture(
4751-
childReadNode,
4752-
events -> {
4753-
assertEquals(1, events.size());
4754-
assertEquals(val, events.get(0).getSnapshot().getValue());
4755-
return true;
4756-
})
4757-
.timedGet();
4750+
ReadFuture.untilEquals(childReadNode, val).timedGet();
47584751
childReadNode.addValueEventListener(listener);
47594752
DatabaseReference parentReadNode = readDb.getReference().child(parentNodeKey);
47604753
IntegrationTestHelpers.waitFor(semaphore);

0 commit comments

Comments
 (0)