本文整理汇总了Java中com.google.firebase.database.DatabaseReference.setValueAsync方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseReference.setValueAsync方法的具体用法?Java DatabaseReference.setValueAsync怎么用?Java DatabaseReference.setValueAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.database.DatabaseReference
的用法示例。
在下文中一共展示了DatabaseReference.setValueAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNullPrioritiesIncludedInStartAt
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testNullPrioritiesIncludedInStartAt() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.setValueAsync(
new MapBuilder()
.put("a", new MapBuilder().put(".priority", null).put(".value", 0).build())
.put("b", new MapBuilder().put(".priority", null).put(".value", 1).build())
.put("c", new MapBuilder().put(".priority", 2).put(".value", 2).build())
.put("d", new MapBuilder().put(".priority", 3).put(".value", 3).build())
.put("e", new MapBuilder().put(".priority", "hi").put(".value", 4).build()).build());
DataSnapshot snap = TestHelpers.getSnap(ref.startAt(2));
Object result = snap.getValue();
Map<String, Object> expected = MapBuilder.of("c", 2L, "d", 3L, "e", 4L);
TestHelpers.assertDeepEquals(expected, result);
}
示例2: testStartAtEndAtWithPriorityAndNameUsingServerData2
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testStartAtEndAtWithPriorityAndNameUsingServerData2() throws
InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.setValueAsync(
new MapBuilder()
.put("c", MapBuilder.of(".value", 3, ".priority", 1))
.put("d", MapBuilder.of(".value", 4, ".priority", 1))
.put("a", MapBuilder.of(".value", 1, ".priority", 2))
.put("b", MapBuilder.of(".value", 2, ".priority", 2)).build());
ValueExpectationHelper helper = new ValueExpectationHelper();
helper.add(ref.startAt(1, "c").endAt(2, "b"),
new MapBuilder().put("a", 1L).put("b", 2L).put("c", 3L).put("d", 4L).build());
helper.add(ref.startAt(1, "d").endAt(2, "a"),
MapBuilder.of("d", 4L, "a", 1L));
helper.add(ref.startAt(1, "e").endAt(2),
MapBuilder.of("a", 1L, "b", 2L));
helper.waitForEvents();
}
示例3: testWriteFloatValueThenChangeToInteger
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testWriteFloatValueThenChangeToInteger() throws InterruptedException {
List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 1);
DatabaseReference node = refs.get(0);
final EventHelper readHelper =
new EventHelper()
.addValueExpectation(node, 1337)
.addValueExpectation(node, 1337.1)
.startListening(true);
ZombieVerifier.verifyRepoZombies(refs);
node.setValueAsync((float) 1337.0);
node.setValueAsync(1337); // This does not fire events.
node.setValueAsync((float) 1337.0); // This does not fire events.
node.setValueAsync(1337.1);
TestHelpers.waitForRoundtrip(node);
assertTrue(readHelper.waitForEvents());
ZombieVerifier.verifyRepoZombies(refs);
readHelper.cleanup();
}
示例4: testNullPrioritiesIncludedInEndAt
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testNullPrioritiesIncludedInEndAt() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.setValueAsync(
new MapBuilder()
.put("a", MapBuilder.of(".priority", null, ".value", 0))
.put("b", MapBuilder.of(".priority", null, ".value", 1))
.put("c", MapBuilder.of(".priority", 2, ".value", 2))
.put("d", MapBuilder.of(".priority", 3, ".value", 3))
.put("e", MapBuilder.of(".priority", "hi", ".value", 4)).build());
DataSnapshot snap = TestHelpers.getSnap(ref.endAt(2));
Map<String, Object> expected = MapBuilder.of("a", 0L, "b", 1L, "c", 2L);
Object result = snap.getValue();
TestHelpers.assertDeepEquals(expected, result);
}
示例5: testStartAtEndAtWithPriorityAndName2
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testStartAtEndAtWithPriorityAndName2() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ValueExpectationHelper helper = new ValueExpectationHelper();
helper.add(ref.startAt(1, "c").endAt(2, "b"),
new MapBuilder().put("a", 1L).put("b", 2L).put("c", 3L).put("d", 4L).build());
helper.add(ref.startAt(1, "d").endAt(2, "a"),
MapBuilder.of("d", 4L, "a", 1L));
helper.add(ref.startAt(1, "e").endAt(2),
MapBuilder.of("a", 1L, "b", 2L));
ref.setValueAsync(
new MapBuilder()
.put("c", MapBuilder.of(".value", 3, ".priority", 1))
.put("d", MapBuilder.of(".value", 4, ".priority", 1))
.put("a", MapBuilder.of(".value", 1, ".priority", 2))
.put("b", MapBuilder.of(".value", 2, ".priority", 2)).build());
helper.waitForEvents();
}
示例6: testStartAtEndAtWithPriorityAndNameUsingServerData
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testStartAtEndAtWithPriorityAndNameUsingServerData() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.setValueAsync(
new MapBuilder()
.put("a", MapBuilder.of(".value", 1, ".priority", 1))
.put("b", MapBuilder.of(".value", 2, ".priority", 1))
.put("c", MapBuilder.of(".value", 3, ".priority", 2))
.put("d", MapBuilder.of(".value", 4, ".priority", 2)).build());
ValueExpectationHelper helper = new ValueExpectationHelper();
helper.add(ref.startAt(1, "a").endAt(2, "d"),
new MapBuilder().put("a", 1L).put("b", 2L).put("c", 3L).put("d", 4L).build());
helper.add(ref.startAt(1, "b").endAt(2, "c"),
MapBuilder.of("b", 2L, "c", 3L));
helper.add(ref.startAt(1, "c").endAt(2),
MapBuilder.of("c", 3L, "d", 4L));
helper.waitForEvents();
}
示例7: testWriteLargeLongValueThenIncrement
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testWriteLargeLongValueThenIncrement() throws InterruptedException {
List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 1);
DatabaseReference node = refs.get(0);
final EventHelper readHelper =
new EventHelper()
.addValueExpectation(node, Long.MAX_VALUE)
.addValueExpectation(node, Long.MAX_VALUE * 2.0)
.startListening(true);
ZombieVerifier.verifyRepoZombies(refs);
node.setValueAsync(Long.MAX_VALUE);
node.setValueAsync(Long.MAX_VALUE * 2.0);
TestHelpers.waitForRoundtrip(node);
assertTrue(readHelper.waitForEvents());
ZombieVerifier.verifyRepoZombies(refs);
readHelper.cleanup();
}
示例8: testSetDataMultipleTimesEnsureValueIsCalledAppropriately
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testSetDataMultipleTimesEnsureValueIsCalledAppropriately()
throws TestFailure, TimeoutException, InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
ReadFuture readFuture = ReadFuture.untilEquals(ref, 2L, /*ignoreFirstNull=*/ true);
ZombieVerifier.verifyRepoZombies(ref);
for (int i = 0; i < 3; ++i) {
ref.setValueAsync(i);
}
List<EventRecord> events = readFuture.timedGet();
for (long i = 0; i < 3; ++i) {
DataSnapshot snap = events.get((int) i).getSnapshot();
assertEquals(i, snap.getValue());
}
ZombieVerifier.verifyRepoZombies(ref);
}
示例9: testStartAtEndAtWithPriorityAndName
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testStartAtEndAtWithPriorityAndName() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ValueExpectationHelper helper = new ValueExpectationHelper();
helper.add(ref.startAt(1, "a").endAt(2, "d"),
new MapBuilder().put("a", 1L).put("b", 2L).put("c", 3L).put("d", 4L).build());
helper.add(ref.startAt(1, "b").endAt(2, "c"),
MapBuilder.of("b", 2L, "c", 3L));
helper.add(ref.startAt(1, "c").endAt(2),
MapBuilder.of("c", 3L, "d", 4L));
ref.setValueAsync(
new MapBuilder()
.put("a", MapBuilder.of(".value", 1, ".priority", 1))
.put("b", MapBuilder.of(".value", 2, ".priority", 1))
.put("c", MapBuilder.of(".value", 3, ".priority", 2))
.put("d", MapBuilder.of(".value", 4, ".priority", 2)).build());
helper.waitForEvents();
}
示例10: testMultipleLimitQueriesWithStartAt
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testMultipleLimitQueriesWithStartAt() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ValueExpectationHelper expectations = new ValueExpectationHelper();
expectations.add(ref.startAt(null).limitToFirst(1),
MapBuilder.of("a", 1L));
expectations.add(ref.startAt(null, "c").limitToFirst(1),
MapBuilder.of("c", 3L));
expectations.add(ref.startAt(null, "b").limitToFirst(1),
MapBuilder.of("b", 2L));
expectations.add(ref.startAt(null, "b").limitToFirst(2),
MapBuilder.of("b", 2L, "c", 3L));
expectations.add(ref.startAt(null, "b").limitToFirst(3),
MapBuilder.of("b", 2L, "c", 3L));
ref.setValueAsync(MapBuilder.of("a", 1, "b", 2, "c", 3));
expectations.waitForEvents();
}
示例11: testKeepSyncedWithExistingListener
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testKeepSyncedWithExistingListener() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ReadFuture readFuture;
ref.keepSynced(true);
try {
assertIsKeptSynced(ref);
readFuture =
new ReadFuture(ref, new ReadFuture.CompletionCondition() {
@Override
public boolean isComplete(List<EventRecord> events) {
return events.get(events.size() - 1).getSnapshot().getValue().equals("done");
}
});
} finally {
// cleanup
ref.keepSynced(false);
}
// Should trigger our listener.
ref.setValueAsync("done");
readFuture.timedGet();
}
示例12: testUpdateAffectPriorityLocally
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUpdateAffectPriorityLocally()
throws TestFailure, TimeoutException, InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ReadFuture readFuture = ReadFuture.untilCountAfterNull(ref, 2);
ref.setValueAsync(new MapBuilder().put("a", 1).put("b", 2).put("c", 3).build(), "testpri");
ref.updateChildrenAsync(MapBuilder.of("a", 4));
List<EventRecord> events = readFuture.timedGet();
DataSnapshot snap = events.get(0).getSnapshot();
assertEquals("testpri", snap.getPriority());
snap = events.get(1).getSnapshot();
assertEquals(4L, snap.child("a").getValue());
assertEquals("testpri", snap.getPriority());
}
示例13: testExportFormatIncludesPriorities
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testExportFormatIncludesPriorities()
throws TimeoutException, InterruptedException, TestFailure {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
Map<String, Object> expected = new MapBuilder().put("foo",
new MapBuilder()
.put("bar", new MapBuilder().put(".priority", 7.0).put(".value", 5L).build())
.put(".priority", "hi").build())
.build();
ReadFuture readFuture = ReadFuture.untilNonNull(ref);
ref.setValueAsync(expected);
DataSnapshot snap = readFuture.timedGet().get(0).getSnapshot();
Object result = snap.getValue(true);
TestHelpers.assertDeepEquals(expected, result);
}
示例14: testMultipleLimitQueries
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testMultipleLimitQueries() throws InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ValueExpectationHelper expectations = new ValueExpectationHelper();
expectations.add(ref.limitToLast(1), MapBuilder.of("c", 3L));
expectations.add(ref.endAt(null).limitToLast(1), MapBuilder.of("c", 3L));
expectations.add(ref.limitToLast(2), MapBuilder.of("b", 2L, "c", 3L));
expectations.add(ref.limitToLast(3),
MapBuilder.of("a", 1L, "b", 2L, "c", 3L));
expectations.add(ref.limitToLast(4),
MapBuilder.of("a", 1L, "b", 2L, "c", 3L));
ref.setValueAsync(MapBuilder.of("a", 1L, "b", 2L, "c", 3L));
expectations.waitForEvents();
}
示例15: testRemoveListener
import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testRemoveListener()
throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
final Semaphore semaphore = new Semaphore(0);
ValueEventListener listener = ref.limitToLast(5)
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
semaphore.release();
}
@Override
public void onCancelled(DatabaseError error) {
}
});
ref.setValueAsync(MapBuilder.of("a", 5, "b", 6));
TestHelpers.waitFor(semaphore, 1);
ref.limitToLast(5).removeEventListener(listener);
new WriteFuture(ref, MapBuilder.of("a", 6, "b", 5)).timedGet();
TestHelpers.waitForQueue(ref);
assertEquals(0, semaphore.availablePermits());
}