use of com.google.firebase.firestore.model.mutation.MutationBatch 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);
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testEncodesMutationBatch.
@Test
public void testEncodesMutationBatch() {
Mutation baseWrite = new PatchMutation(key("foo/bar"), TestUtil.wrapObject(map("a", "b")), FieldMask.fromSet(Collections.singleton(field("a"))), com.google.firebase.firestore.model.mutation.Precondition.NONE);
Mutation set = setMutation("foo/bar", map("a", "b", "num", 1));
Mutation patch = new PatchMutation(key("bar/baz"), TestUtil.wrapObject(map("a", "b", "num", 1)), fieldMask("a"), com.google.firebase.firestore.model.mutation.Precondition.exists(true));
Mutation del = deleteMutation("baz/quux");
MutationBatch model = new MutationBatch(42, writeTime, Collections.singletonList(baseWrite), asList(set, patch, del));
Write baseWriteProto = Write.newBuilder().setUpdate(com.google.firestore.v1.Document.newBuilder().setName("projects/p/databases/d/documents/foo/bar").putFields("a", Value.newBuilder().setStringValue("b").build())).setUpdateMask(DocumentMask.newBuilder().addFieldPaths("a")).build();
com.google.firebase.firestore.proto.WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addBaseWrites(baseWriteProto).addAllWrites(asList(setProto, patchProto, deleteProto)).setLocalWriteTime(writeTimeProto).build();
assertEquals(batchProto, serializer.encodeMutationBatch(model));
MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
assertEquals(model.getBatchId(), decoded.getBatchId());
assertEquals(model.getLocalWriteTime(), decoded.getLocalWriteTime());
assertEquals(model.getMutations(), decoded.getMutations());
assertEquals(model.getBaseMutations(), decoded.getBaseMutations());
assertEquals(model.getKeys(), decoded.getKeys());
}
use of com.google.firebase.firestore.model.mutation.MutationBatch 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);
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method acknowledgeMutationWithTransformResults.
private void acknowledgeMutationWithTransformResults(long documentVersion, Object... transformResult) {
MutationBatch batch = batches.remove(0);
SnapshotVersion version = version(documentVersion);
List<MutationResult> mutationResults = Collections.singletonList(new MutationResult(version, emptyList()));
if (transformResult.length != 0) {
mutationResults = Arrays.stream(transformResult).map(r -> new MutationResult(version, Collections.singletonList(TestUtil.wrap(r)))).collect(Collectors.toList());
}
MutationBatchResult result = MutationBatchResult.create(batch, version, mutationResults, WriteStream.EMPTY_STREAM_TOKEN);
lastChanges = localStore.acknowledgeBatch(result);
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method removeFirstBatches.
/**
* Removes the first n entries from the given <tt>batches</tt> and returns them.
*
* @param n The number of batches to remove..
* @param batches The list to mutate, removing entries from it.
* @return A new list containing all the entries that were removed from @a batches.
*/
private List<MutationBatch> removeFirstBatches(int n, List<MutationBatch> batches) {
List<MutationBatch> removed = new ArrayList<>();
for (int i = 0; i < n; i++) {
MutationBatch batch = batches.get(0);
removeMutationBatches(batch);
batches.remove(0);
removed.add(batch);
}
return removed;
}
Aggregations