use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testDoesNotSynthesizeDeleteInWrongState.
@Test
public void testDoesNotSynthesizeDeleteInWrongState() {
Map<Integer, TargetData> targetMap = activeLimboQueries("foo/doc", 1);
WatchTargetChange wrongState = new WatchTargetChange(WatchTargetChangeType.NoChange, asList(1));
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, noExistingKeys, wrongState);
assertEquals(0, event.getDocumentUpdates().size());
assertEquals(0, event.getResolvedLimboDocuments().size());
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testLastResumeTokenWins.
@Test
public void testLastResumeTokenWins() {
Map<Integer, TargetData> targetMap = activeQueries(1, 2);
WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
WatchTargetChange change1 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
aggregator.handleTargetChange(change1);
ByteString resumeToken2 = ByteString.copyFromUtf8("resumeToken2");
WatchTargetChange change2 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1), resumeToken2);
aggregator.handleTargetChange(change2);
ByteString resumeToken3 = ByteString.copyFromUtf8("resumeToken3");
WatchTargetChange change3 = new WatchTargetChange(WatchTargetChangeType.Current, asList(2), resumeToken3);
aggregator.handleTargetChange(change3);
RemoteEvent event = aggregator.createRemoteEvent(version(3));
assertEquals(2, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(resumeToken2, true, null, null, null);
assertEquals(mapping1, event.getTargetChanges().get(1));
TargetChange mapping2 = targetChange(resumeToken3, true, null, null, null);
assertEquals(mapping2, event.getTargetChanges().get(2));
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testConvertsTargetChangeWithNoChange.
@Test
public void testConvertsTargetChangeWithNoChange() {
WatchTargetChange expected = new WatchTargetChange(WatchTargetChangeType.NoChange, asList(1, 4));
WatchTargetChange actual = (WatchTargetChange) serializer.decodeWatchChange(ListenResponse.newBuilder().setTargetChange(TargetChange.newBuilder().setTargetChangeType(TargetChangeType.NO_CHANGE).addTargetIds(1).addTargetIds(4)).build());
assertEquals(expected, actual);
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testWillKeepResetMappingEvenWithUpdates.
@Test
public void testWillKeepResetMappingEvenWithUpdates() {
Map<Integer, TargetData> targetMap = activeQueries(1);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
MutableDocument doc3 = doc("docs/3", 3, map("value", 3));
WatchChange change1 = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
// Reset stream, ignoring doc1
WatchChange change2 = new WatchTargetChange(WatchTargetChangeType.Reset, asList(1));
// Add doc2, doc3
WatchChange change3 = new DocumentChange(asList(1), emptyList(), doc2.getKey(), doc2);
WatchChange change4 = new DocumentChange(asList(1), emptyList(), doc3.getKey(), doc3);
// Remove doc2 again, should not show up in reset mapping.
WatchChange change5 = new DocumentChange(emptyList(), asList(1), doc2.getKey(), doc2);
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, keySet(doc1.getKey()), change1, change2, change3, change4, change5);
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(3, event.getDocumentUpdates().size());
assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
assertEquals(doc3, event.getDocumentUpdates().get(doc3.getKey()));
assertEquals(1, event.getTargetChanges().size());
// Only doc3 is part of the new mapping.
TargetChange expected = targetChange(resumeToken, false, asList(doc3), null, asList(doc1));
assertEquals(expected, event.getTargetChanges().get(1));
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testConvertsTargetChangeWithAdded.
@Test
public void testConvertsTargetChangeWithAdded() {
WatchTargetChange expected = new WatchTargetChange(WatchTargetChangeType.Added, asList(1, 4));
WatchTargetChange actual = (WatchTargetChange) serializer.decodeWatchChange(ListenResponse.newBuilder().setTargetChange(TargetChange.newBuilder().setTargetChangeType(TargetChangeType.ADD).addTargetIds(1).addTargetIds(4)).build());
assertEquals(expected, actual);
}
Aggregations