Search in sources :

Example 6 with WatchTargetChange

use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.

the class RemoteEventTest method testWillHandleSingleReset.

@Test
public void testWillHandleSingleReset() {
    Map<Integer, TargetData> targetMap = activeQueries(1);
    WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
    // Reset target
    WatchTargetChange change = new WatchTargetChange(WatchTargetChangeType.Reset, asList(1));
    aggregator.handleTargetChange(change);
    RemoteEvent event = aggregator.createRemoteEvent(version(3));
    assertEquals(version(3), event.getSnapshotVersion());
    assertEquals(0, event.getDocumentUpdates().size());
    assertEquals(1, event.getTargetChanges().size());
    // Reset mapping is empty.
    TargetChange expected = targetChange(ByteString.EMPTY, false, null, null, null);
    assertEquals(expected, event.getTargetChanges().get(1));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 7 with WatchTargetChange

use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.

the class RemoteEventTest method testNoChangeWillStillMarkTheAffectedTargets.

@Test
public void testNoChangeWillStillMarkTheAffectedTargets() {
    Map<Integer, TargetData> targetMap = activeQueries(1);
    WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
    WatchTargetChange change = new WatchTargetChange(WatchTargetChangeType.NoChange, asList(1));
    aggregator.handleTargetChange(change);
    RemoteEvent event = aggregator.createRemoteEvent(version(3));
    assertEquals(version(3), event.getSnapshotVersion());
    assertEquals(0, event.getDocumentUpdates().size());
    assertEquals(1, event.getTargetChanges().size());
    TargetChange expected = targetChange(resumeToken, false, null, null, null);
    assertEquals(expected, event.getTargetChanges().get(1));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 8 with WatchTargetChange

use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.

the class RemoteEventTest method testTargetAddedChangeWillResetPreviousState.

@Test
public void testTargetAddedChangeWillResetPreviousState() {
    Map<Integer, TargetData> targetMap = activeQueries(1, 3);
    MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
    MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
    WatchChange change1 = new DocumentChange(asList(1, 3), asList(2), doc1.getKey(), doc1);
    WatchChange change2 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1, 2, 3));
    WatchChange change3 = new WatchTargetChange(WatchTargetChangeType.Removed, asList(1));
    WatchChange change4 = new WatchTargetChange(WatchTargetChangeType.Removed, asList(2));
    WatchChange change5 = new WatchTargetChange(WatchTargetChangeType.Added, asList(1));
    WatchChange change6 = new DocumentChange(asList(1), asList(3), doc2.getKey(), doc2);
    Map<Integer, Integer> outstanding = new HashMap<>();
    outstanding.put(1, 2);
    outstanding.put(2, 1);
    RemoteEvent event = createRemoteEvent(3, targetMap, outstanding, keySet(doc2.getKey()), change1, change2, change3, change4, change5, change6);
    assertEquals(version(3), event.getSnapshotVersion());
    assertEquals(2, event.getDocumentUpdates().size());
    assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
    assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
    // target 1 and 3 are affected (1 because of re-add), target 2 is not because of remove.
    assertEquals(2, event.getTargetChanges().size());
    // doc1 was before the remove, so it does not show up in the mapping.
    // Current was before the remove.
    TargetChange mapping1 = targetChange(resumeToken, false, null, asList(doc2), null);
    assertEquals(mapping1, event.getTargetChanges().get(1));
    // Doc1 was before the remove.
    // Current was after the remove
    TargetChange mapping3 = targetChange(resumeToken, true, asList(doc1), null, asList(doc2));
    assertEquals(mapping3, event.getTargetChanges().get(3));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) HashMap(java.util.HashMap) 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 9 with WatchTargetChange

use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.

the class RemoteEventTest method testTracksLimboDocuments.

@Test
public void testTracksLimboDocuments() {
    Map<Integer, TargetData> listens = activeQueries(1);
    listens.putAll(activeLimboQueries("doc/2", 2));
    // Add 3 docs: 1 is limbo and non-limbo, 2 is limbo-only, 3 is non-limbo
    MutableDocument doc1 = doc("docs/1", 1, map("key", "value"));
    MutableDocument doc2 = doc("docs/2", 1, map("key", "value"));
    MutableDocument doc3 = doc("docs/3", 1, map("key", "value"));
    // Target 2 is a limbo target
    DocumentChange docChange1 = new DocumentChange(asList(1, 2), emptyList(), doc1.getKey(), doc1);
    DocumentChange docChange2 = new DocumentChange(asList(2), emptyList(), doc2.getKey(), doc2);
    DocumentChange docChange3 = new DocumentChange(asList(1), emptyList(), doc3.getKey(), doc3);
    WatchTargetChange targetsChange = new WatchTargetChange(WatchTargetChangeType.Current, asList(1, 2));
    RemoteEvent event = createRemoteEvent(3, listens, noOutstandingResponses, noExistingKeys, docChange1, docChange2, docChange3, targetsChange);
    Set<DocumentKey> limboDocuments = event.getResolvedLimboDocuments();
    // Doc1 is in both limbo and non-limbo targets, therefore not tracked as limbo
    assertFalse(limboDocuments.contains(doc1.getKey()));
    // Doc2 is only in the limbo target, so is tracked as a limbo document
    assertTrue(limboDocuments.contains(doc2.getKey()));
    // Doc3 is only in the non-limbo target, therefore not tracked as limbo
    assertFalse(limboDocuments.contains(doc3.getKey()));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentKey(com.google.firebase.firestore.model.DocumentKey) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 10 with WatchTargetChange

use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.

the class RemoteEventTest method testTargetCurrentChangeWillMarkTheTargetCurrent.

@Test
public void testTargetCurrentChangeWillMarkTheTargetCurrent() {
    Map<Integer, TargetData> targetMap = activeQueries(1);
    WatchChange change = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
    RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, noExistingKeys, change);
    assertEquals(version(3), event.getSnapshotVersion());
    assertEquals(0, event.getDocumentUpdates().size());
    assertEquals(1, event.getTargetChanges().size());
    TargetChange mapping = targetChange(resumeToken, true, null, null, null);
    assertEquals(mapping, event.getTargetChanges().get(1));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) 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