use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testExistenceFilterMismatchClearsTarget.
@Test
public void testExistenceFilterMismatchClearsTarget() {
Map<Integer, TargetData> targetMap = activeQueries(1, 2);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
WatchChange change1 = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
WatchChange change2 = new DocumentChange(asList(1), emptyList(), doc2.getKey(), doc2);
WatchChange change3 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, keySet(doc1.getKey(), doc2.getKey()), change1, change2, change3);
RemoteEvent event = aggregator.createRemoteEvent(version(3));
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(2, event.getDocumentUpdates().size());
assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
assertEquals(2, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(resumeToken, true, null, asList(doc1, doc2), null);
assertEquals(mapping1, event.getTargetChanges().get(1));
TargetChange mapping2 = targetChange(resumeToken, false, null, null, null);
assertEquals(mapping2, event.getTargetChanges().get(2));
WatchChange.ExistenceFilterWatchChange watchChange = new WatchChange.ExistenceFilterWatchChange(1, new ExistenceFilter(1));
aggregator.handleExistenceFilter(watchChange);
event = aggregator.createRemoteEvent(version(3));
TargetChange mapping3 = targetChange(ByteString.EMPTY, false, null, null, asList(doc1, doc2));
assertEquals(1, event.getTargetChanges().size());
assertEquals(mapping3, event.getTargetChanges().get(1));
assertEquals(1, event.getTargetMismatches().size());
assertEquals(0, event.getDocumentUpdates().size());
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testWillIgnoreEventsForPendingTargets.
@Test
public void testWillIgnoreEventsForPendingTargets() {
Map<Integer, TargetData> targetMap = activeQueries(1);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
// We're waiting for the watch and unwatch ack
Map<Integer, Integer> outstanding = new HashMap<>();
outstanding.put(1, 2);
WatchChange change1 = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
WatchChange change2 = new WatchTargetChange(WatchTargetChangeType.Removed, asList(1));
WatchChange change3 = new WatchTargetChange(WatchTargetChangeType.Added, asList(1));
WatchChange change4 = new DocumentChange(asList(1), emptyList(), doc2.getKey(), doc2);
RemoteEvent event = createRemoteEvent(3, targetMap, outstanding, noExistingKeys, change1, change2, change3, change4);
assertEquals(version(3), event.getSnapshotVersion());
// doc1 is ignored because the target was not active at the time, but for
// doc2 the target is active.
assertEquals(1, event.getDocumentUpdates().size());
assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
assertEquals(1, event.getTargetChanges().size());
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testSynthesizeDeletes.
@Test
public void testSynthesizeDeletes() {
Map<Integer, TargetData> targetMap = activeLimboQueries("foo/doc", 1);
WatchTargetChange shouldSynthesize = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, noExistingKeys, shouldSynthesize);
DocumentKey synthesized = key("docs/2");
assertNull(event.getDocumentUpdates().get(synthesized));
MutableDocument expected = deletedDoc("foo/doc", 3);
assertEquals(expected, event.getDocumentUpdates().get(expected.getKey()));
assertTrue(event.getResolvedLimboDocuments().contains(expected.getKey()));
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testConvertsTargetChangeWithRemoved.
@Test
public void testConvertsTargetChangeWithRemoved() {
WatchTargetChange expected = new WatchTargetChange(WatchTargetChangeType.Removed, asList(1, 4), ByteString.copyFrom(new byte[] { 0, 1, 2 }), Status.PERMISSION_DENIED);
WatchTargetChange actual = (WatchTargetChange) serializer.decodeWatchChange(ListenResponse.newBuilder().setTargetChange(TargetChange.newBuilder().setTargetChangeType(TargetChangeType.REMOVE).addTargetIds(1).addTargetIds(4).setCause(com.google.rpc.Status.newBuilder().setCode(7)).setResumeToken(ByteString.copyFrom(new byte[] { 0, 1, 2 }))).build());
assertEquals(expected, actual);
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchRemove.
private void doWatchRemove(JSONObject watchRemoveSpec) throws Exception {
Status error = null;
JSONObject cause = watchRemoveSpec.optJSONObject("cause");
if (cause != null) {
int code = cause.optInt("code");
if (code != 0) {
error = Status.fromCodeValue(code);
}
}
List<Integer> targetIds = parseIntList(watchRemoveSpec.getJSONArray("targetIds"));
WatchTargetChange change = new WatchTargetChange(WatchTargetChangeType.Removed, targetIds, WatchStream.EMPTY_RESUME_TOKEN, error);
writeWatchChange(change, SnapshotVersion.NONE);
// Unlike web, the MockDatastore detects a watch removal with cause and will remove active
// targets
}
Aggregations