Search in sources :

Example 1 with IndexBackfiller

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);
}
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 2 with IndexBackfiller

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();
    }
}
Also used : IndexBackfiller(com.google.firebase.firestore.local.IndexBackfiller) Datastore(com.google.firebase.firestore.remote.Datastore)

Aggregations

IndexBackfiller (com.google.firebase.firestore.local.IndexBackfiller)2 OnlineState (com.google.firebase.firestore.core.OnlineState)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 Datastore (com.google.firebase.firestore.remote.Datastore)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