Search in sources :

Example 56 with DocumentKey

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

the class MutationQueueTestCase method testAllMutationBatchesAffectingDocumentKeys.

@Test
public void testAllMutationBatchesAffectingDocumentKeys() {
    List<Mutation> mutations = asList(setMutation("fob/bar", map("a", 1)), setMutation("foo/bar", map("a", 1)), patchMutation("foo/bar", map("b", 1)), setMutation("foo/bar/suffix/key", map("a", 1)), setMutation("foo/baz", map("a", 1)), setMutation("food/bar", map("a", 1)));
    // Store all the mutations.
    List<MutationBatch> batches = new ArrayList<>();
    persistence.runTransaction("New mutation batch", () -> {
        for (Mutation mutation : mutations) {
            batches.add(mutationQueue.addMutationBatch(Timestamp.now(), Collections.emptyList(), asList(mutation)));
        }
    });
    ImmutableSortedSet<DocumentKey> keys = DocumentKey.emptyKeySet().insert(key("foo/bar")).insert(key("foo/baz"));
    List<MutationBatch> expected = asList(batches.get(1), batches.get(2), batches.get(4));
    List<MutationBatch> matches = mutationQueue.getAllMutationBatchesAffectingDocumentKeys(keys);
    assertEquals(expected, matches);
}
Also used : MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) ArrayList(java.util.ArrayList) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Mutation(com.google.firebase.firestore.model.mutation.Mutation) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation) Test(org.junit.Test)

Example 57 with DocumentKey

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

the class RemoteDocumentCacheTestCase method testGetAllFromSinceReadTimeAndNanoseconds.

@Test
public void testGetAllFromSinceReadTimeAndNanoseconds() {
    add(doc("b/old", 1, DOC_DATA), version(1, 1));
    add(doc("b/current", 1, DOC_DATA), version(1, 2));
    add(doc("b/new", 1, DOC_DATA), version(1, 3));
    ResourcePath collection = path("b");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.createSuccessor(version(1, 2), -1));
    assertThat(results.values()).containsExactly(doc("b/new", 1, DOC_DATA));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 58 with DocumentKey

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

the class RemoteDocumentCacheTestCase method testGetAllFromExcludesSubcollections.

@Test
public void testGetAllFromExcludesSubcollections() {
    addTestDocumentAtPath("a/1");
    addTestDocumentAtPath("a/1/b/1");
    addTestDocumentAtPath("a/2");
    ResourcePath collection = path("a");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.NONE);
    assertThat(results.values()).containsExactly(doc("a/1", 42, DOC_DATA), doc("a/2", 42, DOC_DATA));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 59 with DocumentKey

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

the class RemoteDocumentCacheTestCase method testGetAllFromSinceReadTimeAndDocumentKey.

@Test
public void testGetAllFromSinceReadTimeAndDocumentKey() {
    addTestDocumentAtPath("b/a", /* updateTime= */
    1, /* readTime= */
    11);
    addTestDocumentAtPath("b/b", /* updateTime= */
    2, /*  readTime= = */
    11);
    addTestDocumentAtPath("b/c", /* updateTime= */
    3, /*  readTime= = */
    11);
    addTestDocumentAtPath("b/d", /* updateTime= */
    4, /*  readTime= = */
    12);
    ResourcePath collection = path("b");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.create(version(11), key("b/b"), -1));
    assertThat(results.values()).containsExactly(doc("b/c", 3, DOC_DATA), doc("b/d", 4, DOC_DATA));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 60 with DocumentKey

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

the class RemoteDocumentCacheTestCase method testGetAllFromCollection.

@Test
public void testGetAllFromCollection() {
    addTestDocumentAtPath("a/1");
    addTestDocumentAtPath("b/1");
    addTestDocumentAtPath("b/2");
    addTestDocumentAtPath("c/1");
    ResourcePath collection = path("b");
    Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.NONE);
    assertThat(results.values()).containsExactly(doc("b/1", 42, DOC_DATA), doc("b/2", 42, DOC_DATA));
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) 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