use of com.google.firebase.firestore.model.mutation.SetMutation in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeMutation.
public Mutation decodeMutation(com.google.firestore.v1.Write mutation) {
Precondition precondition = mutation.hasCurrentDocument() ? decodePrecondition(mutation.getCurrentDocument()) : Precondition.NONE;
List<FieldTransform> fieldTransforms = new ArrayList<>();
for (DocumentTransform.FieldTransform fieldTransform : mutation.getUpdateTransformsList()) {
fieldTransforms.add(decodeFieldTransform(fieldTransform));
}
switch(mutation.getOperationCase()) {
case UPDATE:
if (mutation.hasUpdateMask()) {
return new PatchMutation(decodeKey(mutation.getUpdate().getName()), ObjectValue.fromMap(mutation.getUpdate().getFieldsMap()), decodeDocumentMask(mutation.getUpdateMask()), precondition, fieldTransforms);
} else {
return new SetMutation(decodeKey(mutation.getUpdate().getName()), ObjectValue.fromMap(mutation.getUpdate().getFieldsMap()), precondition, fieldTransforms);
}
case DELETE:
return new DeleteMutation(decodeKey(mutation.getDelete()), precondition);
case VERIFY:
return new VerifyMutation(decodeKey(mutation.getVerify()), precondition);
default:
throw fail("Unknown mutation operation: %d", mutation.getOperationCase());
}
}
use of com.google.firebase.firestore.model.mutation.SetMutation 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);
}
}
use of com.google.firebase.firestore.model.mutation.SetMutation 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());
}
use of com.google.firebase.firestore.model.mutation.SetMutation in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testAllMutationBatchesAffectingQuery.
@Test
public void testAllMutationBatchesAffectingQuery() {
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)));
}
});
List<MutationBatch> expected = asList(batches.get(1), batches.get(2), batches.get(4));
Query query = Query.atPath(path("foo"));
List<MutationBatch> matches = mutationQueue.getAllMutationBatchesAffectingQuery(query);
assertEquals(expected, matches);
}
use of com.google.firebase.firestore.model.mutation.SetMutation 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);
}
Aggregations