use of com.google.firebase.firestore.model.mutation.MutationBatch 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.MutationBatch in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testAcknowledgeThenRemove.
@Test
public void testAcknowledgeThenRemove() {
MutationBatch batch1 = addMutationBatch();
persistence.runTransaction(name.getMethodName(), () -> {
mutationQueue.acknowledgeBatch(batch1, WriteStream.EMPTY_STREAM_TOKEN);
mutationQueue.removeMutationBatch(batch1);
});
assertEquals(0, batchCount());
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testAllMutationBatchesAffectingQuery_withCompoundBatches.
@Test
public void testAllMutationBatchesAffectingQuery_withCompoundBatches() {
Map<String, Object> value = map("a", 1);
// Store all the mutations.
List<MutationBatch> batches = new ArrayList<>();
persistence.runTransaction("New mutation batch", () -> {
batches.add(mutationQueue.addMutationBatch(Timestamp.now(), Collections.emptyList(), asList(setMutation("foo/bar", value), setMutation("foo/bar/baz/quux", value))));
batches.add(mutationQueue.addMutationBatch(Timestamp.now(), Collections.emptyList(), asList(setMutation("foo/bar", value), setMutation("foo/baz", value))));
});
List<MutationBatch> expected = asList(batches.get(0), batches.get(1));
Query query = Query.atPath(path("foo"));
List<MutationBatch> matches = mutationQueue.getAllMutationBatchesAffectingQuery(query);
assertEquals(expected, matches);
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class MutationQueueTestCase method testStreamToken.
@Test
public void testStreamToken() {
ByteString streamToken1 = streamToken("token1");
ByteString streamToken2 = streamToken("token2");
persistence.runTransaction("initial stream token", () -> mutationQueue.setLastStreamToken(streamToken1));
MutationBatch batch1 = addMutationBatch();
addMutationBatch();
assertEquals(streamToken1, mutationQueue.getLastStreamToken());
persistence.runTransaction("acknowledgeBatchId", () -> mutationQueue.acknowledgeBatch(batch1, streamToken2));
assertEquals(streamToken2, mutationQueue.getLastStreamToken());
}
use of com.google.firebase.firestore.model.mutation.MutationBatch in project firebase-android-sdk by firebase.
the class RemoteStore method fillWritePipeline.
// Write Stream
/**
* Attempts to fill our write pipeline with writes from the LocalStore.
*
* <p>Called internally to bootstrap or refill the write pipeline and by SyncEngine whenever there
* are new mutations to process.
*
* <p>Starts the write stream if necessary.
*/
public void fillWritePipeline() {
int lastBatchIdRetrieved = writePipeline.isEmpty() ? MutationBatch.UNKNOWN : writePipeline.getLast().getBatchId();
while (canAddToWritePipeline()) {
MutationBatch batch = localStore.getNextMutationBatch(lastBatchIdRetrieved);
if (batch == null) {
if (writePipeline.size() == 0) {
writeStream.markIdle();
}
break;
}
addToWritePipeline(batch);
lastBatchIdRetrieved = batch.getBatchId();
}
if (shouldStartWriteStream()) {
startWriteStream();
}
}
Aggregations