@Test
public void testChildAddedEvents() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
Map<String, Object> initial =
new MapBuilder()
.put("a", MapBuilder.of("value", 5L))
.put("c", MapBuilder.of("value", 3L))
.build();
final List<String> snapshotNames = new ArrayList<>();
final List<String> prevNames = new ArrayList<>();
final Semaphore semaphore = new Semaphore(0);
final ChildEventListener testListener =
ref.orderByChild("value")
.addChildEventListener(
new TestChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snap, String prevName) {
snapshotNames.add(snap.getKey());
prevNames.add(prevName);
semaphore.release();
}
});
ref.setValueAsync(initial);
TestHelpers.waitFor(semaphore, 2);
Assert.assertEquals(Arrays.asList("c", "a"), snapshotNames);
Assert.assertEquals(Arrays.asList(null, "c"), prevNames);
Map<String, Object> updates = new HashMap<>();
updates.put("b", MapBuilder.of("value", 4));
updates.put("d", MapBuilder.of("value", 2));
ref.updateChildrenAsync(updates);
TestHelpers.waitFor(semaphore, 2);
Assert.assertEquals(Arrays.asList("c", "a", "d", "b"), snapshotNames);
Assert.assertEquals(Arrays.asList(null, "c", null, "c"), prevNames);
ref.removeEventListener(testListener);
}
OrderByTestIT.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:firebase-admin-java
作者:
评论列表
文章目录