use of com.google.firebase.firestore.local.IndexBackfiller 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.local.IndexBackfiller in project firebase-android-sdk by firebase.
the class FirestoreClient method initialize.
private void initialize(Context context, User user, FirebaseFirestoreSettings settings) {
// Note: The initialization work must all be synchronous (we can't dispatch more work) since
// external write/listen operations could get queued to run before that subsequent work
// completes.
Logger.debug(LOG_TAG, "Initializing. user=%s", user.getUid());
Datastore datastore = new Datastore(databaseInfo, asyncQueue, authProvider, appCheckProvider, context, metadataProvider);
ComponentProvider.Configuration configuration = new ComponentProvider.Configuration(context, asyncQueue, databaseInfo, datastore, user, MAX_CONCURRENT_LIMBO_RESOLUTIONS, settings);
ComponentProvider provider = settings.isPersistenceEnabled() ? new SQLiteComponentProvider() : new MemoryComponentProvider();
provider.initialize(configuration);
persistence = provider.getPersistence();
gcScheduler = provider.getGarbageCollectionScheduler();
localStore = provider.getLocalStore();
remoteStore = provider.getRemoteStore();
syncEngine = provider.getSyncEngine();
eventManager = provider.getEventManager();
IndexBackfiller indexBackfiller = provider.getIndexBackfiller();
if (gcScheduler != null) {
gcScheduler.start();
}
if (indexBackfiller != null) {
indexBackfillScheduler = indexBackfiller.getScheduler();
indexBackfillScheduler.start();
}
}
Aggregations