Search in sources :

Example 11 with WatchTargetChange

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());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 12 with WatchTargetChange

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));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) ByteString(com.google.protobuf.ByteString) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 13 with WatchTargetChange

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);
}
Also used : WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 14 with WatchTargetChange

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));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 15 with WatchTargetChange

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);
}
Also used : WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Aggregations

WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)26 Test (org.junit.Test)18 TargetData (com.google.firebase.firestore.local.TargetData)16 MutableDocument (com.google.firebase.firestore.model.MutableDocument)9 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)9 ExistenceFilterWatchChange (com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange)4 ByteString (com.google.protobuf.ByteString)4 HashMap (java.util.HashMap)4 DocumentKey (com.google.firebase.firestore.model.DocumentKey)3 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)2 WatchChange (com.google.firebase.firestore.remote.WatchChange)2 Status (io.grpc.Status)2 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1 WatchTargetChangeType (com.google.firebase.firestore.remote.WatchChange.WatchTargetChangeType)1 DocumentChange (com.google.firestore.v1.DocumentChange)1 DocumentDelete (com.google.firestore.v1.DocumentDelete)1 DocumentRemove (com.google.firestore.v1.DocumentRemove)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1