Search in sources :

Example 1 with WriteBatch

use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.

the class LocalSerializerTest method testMultipleMutationsAreSquashed.

// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testMultipleMutationsAreSquashed() {
    // INPUT:
    // SetMutation -> SetMutation -> TransformMutation -> DeleteMutation -> PatchMutation ->
    // TransformMutation -> PatchMutation
    // OUTPUT (squashed):
    // SetMutation -> SetMutation -> DeleteMutation -> PatchMutation -> PatchMutation
    WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(setProto, setProto, transformProto, deleteProto, patchProto, transformProto, patchProto)).setLocalWriteTime(writeTimeProto).build();
    MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
    assertEquals(5, decoded.getMutations().size());
    List<Write> allExpected = asList(new TestWriteBuilder().addSet().build(), new TestWriteBuilder().addSet().addUpdateTransforms().build(), new TestWriteBuilder().addDelete().build(), new TestWriteBuilder().addPatch().addUpdateTransforms().build(), new TestWriteBuilder().addPatch().build());
    for (int i = 0; i < decoded.getMutations().size(); i++) {
        Mutation mutation = decoded.getMutations().get(i);
        Write encoded = remoteSerializer.encodeMutation(mutation);
        assertEquals(allExpected.get(i), encoded);
    }
}
Also used : Write(com.google.firestore.v1.Write) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) Mutation(com.google.firebase.firestore.model.mutation.Mutation) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation) TestUtil.deleteMutation(com.google.firebase.firestore.testutil.TestUtil.deleteMutation) TestUtil.setMutation(com.google.firebase.firestore.testutil.TestUtil.setMutation) WriteBatch(com.google.firebase.firestore.proto.WriteBatch) Test(org.junit.Test)

Example 2 with WriteBatch

use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.

the class LocalSerializerTest method testDeleteAndTransformThrowError.

// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testDeleteAndTransformThrowError() {
    WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(deleteProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
    assertThrows(AssertionError.class, () -> serializer.decodeMutationBatch(batchProto));
}
Also used : WriteBatch(com.google.firebase.firestore.proto.WriteBatch) Test(org.junit.Test)

Example 3 with WriteBatch

use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.

the class LocalSerializerTest method testSetMutationAndTransFormMutationAreSquashed.

// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testSetMutationAndTransFormMutationAreSquashed() {
    WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(setProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
    MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
    assertEquals(1, decoded.getMutations().size());
    assertTrue(decoded.getMutations().get(0) instanceof SetMutation);
    Write encoded = remoteSerializer.encodeMutation(decoded.getMutations().get(0));
    Write expected = new TestWriteBuilder().addSet().addUpdateTransforms().build();
    assertEquals(expected, encoded);
}
Also used : Write(com.google.firestore.v1.Write) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) WriteBatch(com.google.firebase.firestore.proto.WriteBatch) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation) Test(org.junit.Test)

Example 4 with WriteBatch

use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.

the class LocalSerializerTest method testPatchMutationAndTransFormMutationAreSquashed.

// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testPatchMutationAndTransFormMutationAreSquashed() {
    WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(patchProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
    MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
    assertEquals(1, decoded.getMutations().size());
    assertTrue(decoded.getMutations().get(0) instanceof PatchMutation);
    Write encoded = remoteSerializer.encodeMutation(decoded.getMutations().get(0));
    Write expected = new TestWriteBuilder().addPatch().addUpdateTransforms().build();
    assertEquals(expected, encoded);
}
Also used : Write(com.google.firestore.v1.Write) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) WriteBatch(com.google.firebase.firestore.proto.WriteBatch) Test(org.junit.Test)

Example 5 with WriteBatch

use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.

the class LocalSerializerTest method testTransformAndTransformThrowError.

// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testTransformAndTransformThrowError() {
    WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(transformProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
    assertThrows(AssertionError.class, () -> serializer.decodeMutationBatch(batchProto));
}
Also used : WriteBatch(com.google.firebase.firestore.proto.WriteBatch) Test(org.junit.Test)

Aggregations

WriteBatch (com.google.firebase.firestore.proto.WriteBatch)5 Test (org.junit.Test)5 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)3 Write (com.google.firestore.v1.Write)3 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)2 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)2 Mutation (com.google.firebase.firestore.model.mutation.Mutation)1 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)1 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)1