Search in sources :

Example 1 with LocalStore

use of com.google.firebase.firestore.local.LocalStore 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)

Aggregations

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 MutationBatchResult (com.google.firebase.firestore.model.mutation.MutationBatchResult)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