Search in sources :

Example 1 with MutationBatchResult

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();
}
Also used : MutationBatchResult(com.google.firebase.firestore.model.mutation.MutationBatchResult) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch)

Example 2 with MutationBatchResult

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);
}
Also used : Status(io.grpc.Status) IndexBackfiller(com.google.firebase.firestore.local.IndexBackfiller) MutationBatchResult(com.google.firebase.firestore.model.mutation.MutationBatchResult) Semaphore(java.util.concurrent.Semaphore) QueryEngine(com.google.firebase.firestore.local.QueryEngine) LocalStore(com.google.firebase.firestore.local.LocalStore) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Persistence(com.google.firebase.firestore.local.Persistence) MemoryPersistence(com.google.firebase.firestore.local.MemoryPersistence) OnlineState(com.google.firebase.firestore.core.OnlineState) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Test(org.junit.Test)

Example 3 with MutationBatchResult

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);
}
Also used : MutationBatchResult(com.google.firebase.firestore.model.mutation.MutationBatchResult) MutationBatch(com.google.firebase.firestore.model.mutation.MutationBatch) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) MutationResult(com.google.firebase.firestore.model.mutation.MutationResult)

Aggregations

MutationBatchResult (com.google.firebase.firestore.model.mutation.MutationBatchResult)3 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)2 OnlineState (com.google.firebase.firestore.core.OnlineState)1 IndexBackfiller (com.google.firebase.firestore.local.IndexBackfiller)1 LocalStore (com.google.firebase.firestore.local.LocalStore)1 MemoryPersistence (com.google.firebase.firestore.local.MemoryPersistence)1 Persistence (com.google.firebase.firestore.local.Persistence)1 QueryEngine (com.google.firebase.firestore.local.QueryEngine)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)1 MutationResult (com.google.firebase.firestore.model.mutation.MutationResult)1 AsyncQueue (com.google.firebase.firestore.util.AsyncQueue)1 Status (io.grpc.Status)1 Semaphore (java.util.concurrent.Semaphore)1 Test (org.junit.Test)1