Search in sources :

Example 11 with Mutation

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

the class SpecTestCase method doFailWrite.

private void doFailWrite(JSONObject writeFailureSpec) throws Exception {
    JSONObject errorSpec = writeFailureSpec.getJSONObject("error");
    boolean keepInQueue = writeFailureSpec.optBoolean("keepInQueue", false);
    int code = errorSpec.getInt("code");
    Status error = Status.fromCodeValue(code);
    Pair<Mutation, Task<Void>> write = getCurrentOutstandingWrites().get(0);
    validateNextWriteSent(write.first);
    // If this is a permanent error, the write is not expected to be sent again.
    if (!keepInQueue) {
        getCurrentOutstandingWrites().remove(0);
    }
    log("      Failing a write.");
    queue.runSync(() -> datastore.failWrite(error));
}
Also used : Status(io.grpc.Status) Task(com.google.android.gms.tasks.Task) LoadBundleTask(com.google.firebase.firestore.LoadBundleTask) JSONObject(org.json.JSONObject) Mutation(com.google.firebase.firestore.model.mutation.Mutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.patchMutation(com.google.firebase.firestore.testutil.TestUtil.patchMutation)

Example 12 with Mutation

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

the class DocumentOverlayCacheTestCase method testDeleteRepeatedlyWorks.

@Test
public void testDeleteRepeatedlyWorks() {
    Mutation m = patchMutation("coll/doc1", map("foo", "bar"));
    saveOverlays(2, m);
    cache.removeOverlaysForBatchId(2);
    assertNull(cache.getOverlay(key("coll/doc1")));
    // Repeat
    cache.removeOverlaysForBatchId(2);
    assertNull(cache.getOverlay(key("coll/doc1")));
}
Also used : 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 13 with Mutation

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

the class DocumentOverlayCacheTestCase method testCanReadSavedOverlay.

@Test
public void testCanReadSavedOverlay() {
    Mutation m = patchMutation("coll/doc1", map("foo", "bar"));
    saveOverlays(2, m);
    assertEquals(m, cache.getOverlay(key("coll/doc1")).getMutation());
}
Also used : 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 14 with Mutation

use of com.google.firebase.firestore.model.mutation.Mutation 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 15 with Mutation

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

the class DocumentOverlayCacheTestCase method testSavingOverlayOverwrites.

@Test
public void testSavingOverlayOverwrites() {
    Mutation m1 = patchMutation("coll/doc1", map("foo", "bar"));
    Mutation m2 = setMutation("coll/doc1", map("foo", "set", "bar", 42));
    saveOverlays(2, m1);
    saveOverlays(2, m2);
    assertEquals(m2, cache.getOverlay(key("coll/doc1")).getMutation());
}
Also used : 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)

Aggregations

Mutation (com.google.firebase.firestore.model.mutation.Mutation)46 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)29 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)27 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)25 Test (org.junit.Test)25 DocumentKey (com.google.firebase.firestore.model.DocumentKey)18 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)13 Write (com.google.firestore.v1.Write)12 TestUtil.mergeMutation (com.google.firebase.firestore.testutil.TestUtil.mergeMutation)8 TestUtil.verifyMutation (com.google.firebase.firestore.testutil.TestUtil.verifyMutation)8 ArrayList (java.util.ArrayList)8 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)7 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)5 Map (java.util.Map)4 Timestamp (com.google.firebase.Timestamp)3 MutableDocument (com.google.firebase.firestore.model.MutableDocument)3 Overlay (com.google.firebase.firestore.model.mutation.Overlay)3 SQLiteStatement (android.database.sqlite.SQLiteStatement)2