Search in sources :

Example 11 with MutationBatch

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

the class LocalStoreTestCase method rejectMutation.

private void rejectMutation() {
    MutationBatch batch = batches.get(0);
    batches.remove(0);
    lastChanges = localStore.rejectBatch(batch.getBatchId());
}
Also used : MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch)

Example 12 with MutationBatch

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

the class LocalStoreTestCase method writeMutations.

private void writeMutations(List<Mutation> mutations) {
    LocalDocumentsResult result = localStore.writeLocally(mutations);
    batches.add(new MutationBatch(result.getBatchId(), Timestamp.now(), Collections.emptyList(), mutations));
    lastChanges = result.getDocuments();
}
Also used : MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch)

Example 13 with MutationBatch

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

the class LocalStoreTestCase method testMutationBatchKeys.

@Test
public void testMutationBatchKeys() {
    SetMutation set1 = setMutation("foo/bar", map("foo", "bar"));
    SetMutation set2 = setMutation("foo/baz", map("foo", "baz"));
    MutationBatch batch = new MutationBatch(1, Timestamp.now(), Collections.emptyList(), asList(set1, set2));
    Set<DocumentKey> keys = batch.getKeys();
    assertEquals(2, keys.size());
}
Also used : MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) DocumentKey(com.google.firebase.firestore.model.DocumentKey) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation) Test(org.junit.Test)

Example 14 with MutationBatch

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

the class MutationQueueTestCase method testNextMutationBatchAfterBatchId.

@Test
public void testNextMutationBatchAfterBatchId() {
    List<MutationBatch> batches = createBatches(10);
    List<MutationBatch> removed = removeFirstBatches(3, batches);
    for (int i = 0; i < batches.size() - 1; i++) {
        MutationBatch current = batches.get(i);
        MutationBatch next = batches.get(i + 1);
        MutationBatch found = mutationQueue.getNextMutationBatchAfterBatchId(current.getBatchId());
        assertNotNull(found);
        assertEquals(next.getBatchId(), found.getBatchId());
    }
    for (int i = 0; i < removed.size(); i++) {
        MutationBatch current = removed.get(i);
        MutationBatch next = batches.get(0);
        MutationBatch found = mutationQueue.getNextMutationBatchAfterBatchId(current.getBatchId());
        assertNotNull(found);
        assertEquals(next.getBatchId(), found.getBatchId());
    }
    MutationBatch first = batches.get(0);
    MutationBatch found = mutationQueue.getNextMutationBatchAfterBatchId(first.getBatchId() - 42);
    assertNotNull(found);
    assertEquals(first.getBatchId(), found.getBatchId());
    MutationBatch last = batches.get(batches.size() - 1);
    MutationBatch notFound = mutationQueue.getNextMutationBatchAfterBatchId(last.getBatchId());
    assertNull(notFound);
}
Also used : MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) Test(org.junit.Test)

Example 15 with MutationBatch

use of com.google.firebase.firestore.model.mutation.MutationBatch 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)

Aggregations

MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)40 Test (org.junit.Test)15 Mutation (com.google.firebase.firestore.model.mutation.Mutation)13 ArrayList (java.util.ArrayList)12 DocumentKey (com.google.firebase.firestore.model.DocumentKey)11 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)8 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)7 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)6 Write (com.google.firestore.v1.Write)5 ByteString (com.google.protobuf.ByteString)5 HashSet (java.util.HashSet)5 WriteBatch (com.google.firebase.firestore.proto.WriteBatch)4 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)4 MutableDocument (com.google.firebase.firestore.model.MutableDocument)3 Timestamp (com.google.firebase.Timestamp)2 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)2 Query (com.google.firebase.firestore.core.Query)2 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)2 MutationBatchResult (com.google.firebase.firestore.model.mutation.MutationBatchResult)2 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)2