use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testCountBatches.
@Test
public void testCountBatches() {
assertEquals(0, batchCount());
assertTrue(mutationQueue.isEmpty());
MutationBatch batch1 = addMutationBatch();
assertEquals(1, batchCount());
assertFalse(mutationQueue.isEmpty());
MutationBatch batch2 = addMutationBatch();
assertEquals(2, batchCount());
assertFalse(mutationQueue.isEmpty());
removeMutationBatches(batch1);
assertEquals(1, batchCount());
removeMutationBatches(batch2);
assertEquals(0, batchCount());
assertTrue(mutationQueue.isEmpty());
}
use of com.google.firebase.firestore.model.mutation.MutationBatch 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.MutationBatch 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();
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testLookupMutationBatch.
@Test
public void testLookupMutationBatch() {
// Searching on an empty queue should not find a non-existent batch
MutationBatch notFound = mutationQueue.lookupMutationBatch(42);
assertNull(notFound);
List<MutationBatch> batches = createBatches(10);
List<MutationBatch> removed = removeFirstBatches(3, batches);
// After removing, a batch should not be found
for (MutationBatch batch : removed) {
notFound = mutationQueue.lookupMutationBatch(batch.getBatchId());
assertNull(notFound);
}
// Remaining entries should still be found
for (MutationBatch batch : batches) {
MutationBatch found = mutationQueue.lookupMutationBatch(batch.getBatchId());
assertNotNull(found);
assertEquals(batch.getBatchId(), found.getBatchId());
}
// Even on a nonempty queue searching should not find a non-existent batch
notFound = mutationQueue.lookupMutationBatch(42);
assertNull(notFound);
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class QueryEngineTestCase method addMutation.
/**
* Adds a mutation to the mutation queue.
*/
protected void addMutation(Mutation mutation) {
persistence.runTransaction("addMutation", () -> {
MutationBatch batch = mutationQueue.addMutationBatch(Timestamp.now(), Collections.emptyList(), Collections.singletonList(mutation));
Map<DocumentKey, Mutation> overlayMap = Collections.singletonMap(mutation.getKey(), mutation);
documentOverlayCache.saveOverlays(batch.getBatchId(), overlayMap);
});
}
Aggregations