use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesServerTimestampMutation.
@Test
public void testEncodesServerTimestampMutation() {
Mutation mutation = setMutation("docs/1", map("a", com.google.firebase.firestore.FieldValue.serverTimestamp(), "bar", com.google.firebase.firestore.FieldValue.serverTimestamp()));
Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1")).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("a").setSetToServerValue(ServerValue.REQUEST_TIME)).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("bar").setSetToServerValue(ServerValue.REQUEST_TIME)).build();
assertRoundTripForMutation(mutation, expected);
mutation = patchMutation("docs/1", map("a", com.google.firebase.firestore.FieldValue.serverTimestamp(), "bar.baz", com.google.firebase.firestore.FieldValue.serverTimestamp()));
expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1")).setUpdateMask(DocumentMask.newBuilder().build()).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("a").setSetToServerValue(ServerValue.REQUEST_TIME)).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("bar.baz").setSetToServerValue(ServerValue.REQUEST_TIME)).setCurrentDocument(Precondition.newBuilder().setExists(true)).build();
assertRoundTripForMutation(mutation, expected);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class SpecTestCase method validateNextWriteSent.
//
// Methods for mocking out the grpc streams.
//
/**
* Validates that a write was sent and matches the expected write.
*/
private void validateNextWriteSent(Mutation expectedWrite) {
List<Mutation> request = datastore.waitForWriteSend();
// TODO: Batch writes not supported yet
assertEquals(1, request.size());
Mutation actualWrite = request.get(0);
assertEquals(expectedWrite, actualWrite);
log(" This write was sent: " + actualWrite);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class SpecTestCase method doWriteAck.
private void doWriteAck(JSONObject writeAckSpec) throws Exception {
long version = writeAckSpec.getLong("version");
boolean keepInQueue = writeAckSpec.optBoolean("keepInQueue", false);
assertFalse("'keepInQueue=true' is not supported on Android and should only be set in multi-client tests", keepInQueue);
Pair<Mutation, Task<Void>> write = getCurrentOutstandingWrites().remove(0);
validateNextWriteSent(write.first);
MutationResult mutationResult = new MutationResult(version(version), /*transformResults=*/
Collections.emptyList());
queue.runSync(() -> datastore.ackWrite(version(version), singletonList(mutationResult)));
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testAllMutationBatchesAffectingDocumentKey.
@Test
public void testAllMutationBatchesAffectingDocumentKey() {
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));
List<MutationBatch> matches = mutationQueue.getAllMutationBatchesAffectingDocumentKey(key("foo/bar"));
assertEquals(expected, matches);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testAllMutationBatchesAffectingDocumentLotsOfDocumentKeys.
// PORTING NOTE: this test only applies to Android, because it's the only platform where the
// implementation of getAllMutationBatchesAffectingDocumentKeys might split the input into several
// queries.
@Test
public void testAllMutationBatchesAffectingDocumentLotsOfDocumentKeys() {
List<Mutation> mutations = new ArrayList<>();
// Make sure to force SQLite implementation to split the large query into several smaller ones.
int lotsOfMutations = 2000;
for (int i = 0; i < lotsOfMutations; i++) {
mutations.add(setMutation("foo/" + i, map("a", 1)));
}
List<MutationBatch> batches = new ArrayList<>();
persistence.runTransaction("New mutation batch", () -> {
for (Mutation mutation : mutations) {
batches.add(mutationQueue.addMutationBatch(Timestamp.now(), Collections.emptyList(), asList(mutation)));
}
});
// To make it easier validating the large resulting set, use a simple criteria to evaluate --
// query all keys with an even number in them and make sure the corresponding batches make it
// into the results.
ImmutableSortedSet<DocumentKey> evenKeys = DocumentKey.emptyKeySet();
List<MutationBatch> expected = new ArrayList<>();
for (int i = 2; i < lotsOfMutations; i += 2) {
evenKeys = evenKeys.insert(key("foo/" + i));
expected.add(batches.get(i));
}
List<MutationBatch> matches = mutationQueue.getAllMutationBatchesAffectingDocumentKeys(evenKeys);
assertThat(matches).containsExactlyElementsIn(expected).inOrder();
}
Aggregations