use of com.google.firebase.firestore.model.mutation.MutationBatchResult in project firebase-android-sdk by firebase.
the class RemoteStore method handleWriteStreamMutationResults.
/**
* Handles a successful StreamingWriteResponse from the server that contains a mutation result.
*/
private void handleWriteStreamMutationResults(SnapshotVersion commitVersion, List<MutationResult> results) {
// This is a response to a write containing mutations and should be correlated to the first
// write in our write pipeline.
MutationBatch batch = writePipeline.poll();
MutationBatchResult mutationBatchResult = MutationBatchResult.create(batch, commitVersion, results, writeStream.getLastStreamToken());
remoteStoreCallback.handleSuccessfulWrite(mutationBatchResult);
// It's possible that with the completion of this mutation another slot has freed up.
fillWritePipeline();
}
use of com.google.firebase.firestore.model.mutation.MutationBatchResult in project firebase-android-sdk by firebase.
the class RemoteStoreTest method testRemoteStoreStreamStopsWhenNetworkUnreachable.
@Test
public void testRemoteStoreStreamStopsWhenNetworkUnreachable() {
AsyncQueue testQueue = new AsyncQueue();
Datastore datastore = new Datastore(IntegrationTestUtil.testEnvDatabaseInfo(), testQueue, null, null, ApplicationProvider.getApplicationContext(), null);
Semaphore networkChangeSemaphore = new Semaphore(0);
RemoteStore.RemoteStoreCallback callback = new RemoteStore.RemoteStoreCallback() {
@Override
public void handleRemoteEvent(RemoteEvent remoteEvent) {
}
@Override
public void handleRejectedListen(int targetId, Status error) {
}
@Override
public void handleSuccessfulWrite(MutationBatchResult successfulWrite) {
}
@Override
public void handleRejectedWrite(int batchId, Status error) {
}
@Override
public void handleOnlineStateChange(OnlineState onlineState) {
networkChangeSemaphore.release();
}
@Override
public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
return null;
}
};
FakeConnectivityMonitor connectivityMonitor = new FakeConnectivityMonitor();
QueryEngine queryEngine = new QueryEngine();
Persistence persistence = MemoryPersistence.createEagerGcMemoryPersistence();
persistence.start();
IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
LocalStore localStore = new LocalStore(persistence, indexBackfiller, queryEngine, User.UNAUTHENTICATED);
RemoteStore remoteStore = new RemoteStore(callback, localStore, datastore, testQueue, connectivityMonitor);
waitFor(testQueue.enqueue(remoteStore::forceEnableNetwork));
drain(testQueue);
networkChangeSemaphore.drainPermits();
connectivityMonitor.goOffline();
waitFor(networkChangeSemaphore);
drain(testQueue);
networkChangeSemaphore.drainPermits();
waitFor(testQueue.enqueue(remoteStore::forceEnableNetwork));
connectivityMonitor.goOnline();
waitFor(networkChangeSemaphore);
}
use of com.google.firebase.firestore.model.mutation.MutationBatchResult 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);
}
Aggregations