Search in sources :

Example 41 with DocumentKey

use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.

the class TestUtil method viewChanges.

public static LocalViewChanges viewChanges(int targetId, boolean fromCache, List<String> addedKeys, List<String> removedKeys) {
    ImmutableSortedSet<DocumentKey> added = DocumentKey.emptyKeySet();
    for (String keyPath : addedKeys) {
        added = added.insert(key(keyPath));
    }
    ImmutableSortedSet<DocumentKey> removed = DocumentKey.emptyKeySet();
    for (String keyPath : removedKeys) {
        removed = removed.insert(key(keyPath));
    }
    return new LocalViewChanges(targetId, fromCache, added, removed);
}
Also used : LocalViewChanges(com.google.firebase.firestore.local.LocalViewChanges) DocumentKey(com.google.firebase.firestore.model.DocumentKey) ByteString(com.google.protobuf.ByteString)

Example 42 with DocumentKey

use of com.google.firebase.firestore.model.DocumentKey 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 43 with DocumentKey

use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.

the class DocumentOverlayCacheTestCase method testCanReadSavedOverlaysInBatches.

@Test
public void testCanReadSavedOverlaysInBatches() {
    Mutation m1 = setMutation("coll1/a", map("a", 1));
    Mutation m2 = setMutation("coll1/b", map("b", 2));
    Mutation m3 = setMutation("coll2/c", map("c", 3));
    saveOverlays(3, m1, m2, m3);
    Map<DocumentKey, Overlay> overlays = cache.getOverlays(new TreeSet<>(Arrays.asList(key("coll1/a"), key("coll1/b"), key("coll2/c"))));
    assertEquals(m1, overlays.get(key("coll1/a")).getMutation());
    assertEquals(m2, overlays.get(key("coll1/b")).getMutation());
    assertEquals(m3, overlays.get(key("coll2/c")).getMutation());
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) Overlay(com.google.firebase.firestore.model.mutation.Overlay) Test(org.junit.Test)

Example 44 with DocumentKey

use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.

the class IndexBackfillerTest method testBackfillAppliesDeleteToRemoteDoc.

@Test
public void testBackfillAppliesDeleteToRemoteDoc() {
    addFieldIndex("coll", "foo");
    addDoc("coll/doc", version(5), "foo", 1);
    int documentsProcessed = backfiller.backfill();
    assertEquals(1, documentsProcessed);
    Mutation delete = deleteMutation("coll/doc");
    addMutationToOverlay("coll/doc", delete);
    documentsProcessed = backfiller.backfill();
    assertEquals(1, documentsProcessed);
    Target target = query("coll").filter(filter("foo", "==", 2)).toTarget();
    List<DocumentKey> matching = indexManager.getDocumentsMatchingTarget(target);
    assertTrue(matching.isEmpty());
}
Also used : Target(com.google.firebase.firestore.core.Target) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) Test(org.junit.Test)

Example 45 with DocumentKey

use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.

the class ViewSnapshotTest method testConstructor.

@Test
public void testConstructor() {
    Query query = Query.atPath(ResourcePath.fromString("a"));
    DocumentSet docs = DocumentSet.emptySet(Document.KEY_COMPARATOR).add(doc("c/foo", 1, map()));
    DocumentSet oldDocs = DocumentSet.emptySet(Document.KEY_COMPARATOR);
    List<DocumentViewChange> changes = Arrays.asList(DocumentViewChange.create(Type.ADDED, doc("c/foo", 1, map())));
    ImmutableSortedSet<DocumentKey> mutatedKeys = keySet(key("c/foo"));
    boolean fromCache = true;
    boolean hasPendingWrites = true;
    boolean syncStateChanges = true;
    boolean excludesMetadataChanges = true;
    ViewSnapshot snapshot = new ViewSnapshot(query, docs, oldDocs, changes, fromCache, mutatedKeys, syncStateChanges, excludesMetadataChanges);
    assertEquals(query, snapshot.getQuery());
    assertEquals(docs, snapshot.getDocuments());
    assertEquals(oldDocs, snapshot.getOldDocuments());
    assertEquals(changes, snapshot.getChanges());
    assertEquals(fromCache, snapshot.isFromCache());
    assertEquals(mutatedKeys, snapshot.getMutatedKeys());
    assertEquals(hasPendingWrites, snapshot.hasPendingWrites());
    assertEquals(syncStateChanges, snapshot.didSyncStateChange());
    assertEquals(excludesMetadataChanges, snapshot.excludesMetadataChanges());
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Aggregations

DocumentKey (com.google.firebase.firestore.model.DocumentKey)139 MutableDocument (com.google.firebase.firestore.model.MutableDocument)53 Test (org.junit.Test)36 HashMap (java.util.HashMap)34 ArrayList (java.util.ArrayList)24 Document (com.google.firebase.firestore.model.Document)20 Mutation (com.google.firebase.firestore.model.mutation.Mutation)18 Map (java.util.Map)18 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)16 ResourcePath (com.google.firebase.firestore.model.ResourcePath)13 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)11 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)10 Overlay (com.google.firebase.firestore.model.mutation.Overlay)10 HashSet (java.util.HashSet)10 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)8 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)8 ByteString (com.google.protobuf.ByteString)7 Target (com.google.firebase.firestore.core.Target)6 ObjectValue (com.google.firebase.firestore.model.ObjectValue)6 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)6