Java Code Examples for com.google.firebase.database.Query#getRef()
The following examples show how to use
com.google.firebase.database.Query#getRef() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeepSyncedTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
private void assertIsKeptSynced(Query query) throws Exception { DatabaseReference ref = query.getRef(); // First set a unique value to the value of a child. long counter = globalKeepSyncedTestCounter++; final Map<String, Object> value = new MapBuilder().put("child", counter).build(); new WriteFuture(ref, value).timedGet(); // Next go offline, if it's kept synced we should have kept the value, after going offline no // way to get the value except from cache ref.getDatabase().goOffline(); new ReadFuture( query, (List<EventRecord> events) -> { assertEquals(1, events.size()); assertEquals(value, events.get(0).getSnapshot().getValue()); return true; }) .timedGet(); // All good, go back online ref.getDatabase().goOnline(); }
Example 2
Source File: KeepSyncedTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
private void assertNotKeptSynced(Query query) throws Exception { DatabaseReference ref = query.getRef(); // First set a unique value to the value of a child. long current = globalKeepSyncedTestCounter++; final Map<String, Object> oldValue = new MapBuilder().put("child", current).build(); long next = globalKeepSyncedTestCounter++; final Map<String, Object> nextValue = new MapBuilder().put("child", next).build(); new WriteFuture(ref, oldValue).timedGet(); // Next go offline, if it's kept synced we should have kept the value and we'll get an even // with the *old* value. ref.getDatabase().goOffline(); ReadFuture readFuture = new ReadFuture( query, (List<EventRecord> events) -> { // We expect this to get called with the next value, not the old value. assertEquals(1, events.size()); assertEquals(nextValue, events.get(0).getSnapshot().getValue()); return true; }); // By now, if we had it synced we should have gotten an event with the wrong value // Write a new value so the value event listener will be triggered ref.setValue(nextValue); readFuture.timedGet(); // All good, go back online ref.getDatabase().goOnline(); }
Example 3
Source File: KeepSyncedTestIT.java From firebase-admin-java with Apache License 2.0 | 5 votes |
private void assertIsKeptSynced(Query query) throws Exception { DatabaseReference ref = query.getRef(); // First set a unique value to the value of a child. long counter = globalKeepSyncedTestCounter++; final Map<String, Object> value = ImmutableMap.<String, Object>of("child", counter); new WriteFuture(ref, value).timedGet(); // Next go offline, if it's kept synced we should have kept the value. // After going offline no way to get the value except from cache. ref.getDatabase().goOffline(); try { new ReadFuture( query, new ReadFuture.CompletionCondition() { @Override public boolean isComplete(List<EventRecord> events) { assertEquals(1, events.size()); assertEquals(value, events.get(0).getSnapshot().getValue()); return true; } }) .timedGet(); } finally { // All good, go back online ref.getDatabase().goOnline(); } }
Example 4
Source File: KeepSyncedTestIT.java From firebase-admin-java with Apache License 2.0 | 5 votes |
private void assertNotKeptSynced(Query query) throws Exception { DatabaseReference ref = query.getRef(); // First set a unique value to the value of a child. long current = globalKeepSyncedTestCounter++; final Map<String, Object> oldValue = ImmutableMap.<String, Object>of("child", current); long next = globalKeepSyncedTestCounter++; final Map<String, Object> nextValue = ImmutableMap.<String, Object>of("child", next); new WriteFuture(ref, oldValue).timedGet(); // Next go offline, if it's kept synced we should have kept the value and we'll get an even // with the *old* value. ref.getDatabase().goOffline(); try { ReadFuture readFuture = new ReadFuture(query, new ReadFuture.CompletionCondition() { @Override public boolean isComplete(List<EventRecord> events) { // We expect this to get called with the next value, not the old value. assertEquals(1, events.size()); assertEquals(nextValue, events.get(0).getSnapshot().getValue()); return true; } }); // By now, if we had it synced we should have gotten an event with the wrong value // Write a new value so the value event listener will be triggered ref.setValueAsync(nextValue); readFuture.timedGet(); } finally { // All good, go back online ref.getDatabase().goOnline(); } }