use of com.google.firebase.firestore.core.OnlineState 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);
}
Aggregations