Search in sources :

Example 11 with AsyncQueue

use of com.google.firebase.firestore.util.AsyncQueue in project firebase-android-sdk by firebase.

the class SQLiteOverlayMigrationManagerTest method testCreateOverlayFromSet.

@Test
public void testCreateOverlayFromSet() {
    writeRemoteDocument(doc("foo/bar", 2, map("it", "original")));
    writeMutation(setMutation("foo/bar", map("foo", "bar")));
    // Switch to new persistence and run migrations
    this.persistence.shutdown();
    persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration");
    IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
    localStore = new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED);
    localStore.start();
    assertEquals(setMutation("foo/bar", map("foo", "bar")), persistence.getDocumentOverlayCache(User.UNAUTHENTICATED).getOverlay(key("foo/bar")).getMutation());
    // Version is 0 because of remote document elision.
    assertContains(doc("foo/bar", 2, map("foo", "bar")).setHasLocalMutations());
    SQLiteOverlayMigrationManager migrationManager = (SQLiteOverlayMigrationManager) persistence.getOverlayMigrationManager();
    assertFalse(migrationManager.hasPendingOverlayMigration());
}
Also used : AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Example 12 with AsyncQueue

use of com.google.firebase.firestore.util.AsyncQueue in project firebase-android-sdk by firebase.

the class SQLiteOverlayMigrationManagerTest method setUp.

@Before
public void setUp() {
    // Setup persistence to version 12, which is before Overlay.
    persistence = PersistenceTestHelpers.createSQLitePersistenceForVersion("test-data-migration", 12);
    IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
    localStore = new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED);
    localStore.start();
}
Also used : AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Before(org.junit.Before)

Example 13 with AsyncQueue

use of com.google.firebase.firestore.util.AsyncQueue in project firebase-android-sdk by firebase.

the class StreamTest method testStreamRefreshesTokenUponExpiration.

@Test
public void testStreamRefreshesTokenUponExpiration() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    MockCredentialsProvider mockCredentialsProvider = new MockCredentialsProvider();
    Datastore datastore = new Datastore(IntegrationTestUtil.testEnvDatabaseInfo(), testQueue, mockCredentialsProvider, new EmptyAppCheckTokenProvider(), ApplicationProvider.getApplicationContext(), null);
    StreamStatusCallback callback = new StreamStatusCallback();
    WriteStream writeStream = datastore.createWriteStream(callback);
    waitForWriteStreamOpen(testQueue, writeStream, callback);
    // Simulate callback from GRPC with an unauthenticated error -- this should invalidate the
    // token.
    testQueue.runSync(() -> writeStream.handleServerClose(Status.UNAUTHENTICATED));
    waitForWriteStreamOpen(testQueue, writeStream, callback);
    // Simulate a different error -- token should not be invalidated this time.
    testQueue.runSync(() -> writeStream.handleServerClose(Status.UNAVAILABLE));
    waitForWriteStreamOpen(testQueue, writeStream, callback);
    assertThat(mockCredentialsProvider.observedStates()).containsExactly("getToken", "invalidateToken", "getToken", "getToken").inOrder();
}
Also used : EmptyAppCheckTokenProvider(com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Example 14 with AsyncQueue

use of com.google.firebase.firestore.util.AsyncQueue in project firebase-android-sdk by firebase.

the class StreamTest method testStreamStaysIdle.

@Test
public void testStreamStaysIdle() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    WriteStream writeStream = createAndOpenWriteStream(testQueue, new StreamStatusCallback());
    testQueue.runSync(() -> {
        writeStream.markIdle();
        writeStream.markIdle();
    });
    assertTrue(testQueue.containsDelayedTask(TimerId.WRITE_STREAM_IDLE));
}
Also used : AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Example 15 with AsyncQueue

use of com.google.firebase.firestore.util.AsyncQueue in project firebase-android-sdk by firebase.

the class StreamTest method testStreamClosesWhenIdle.

@Test
public void testStreamClosesWhenIdle() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    StreamStatusCallback callback = new StreamStatusCallback();
    WriteStream writeStream = createAndOpenWriteStream(testQueue, callback);
    testQueue.enqueueAndForget(() -> {
        writeStream.markIdle();
        assertTrue(testQueue.containsDelayedTask(TimerId.WRITE_STREAM_IDLE));
    });
    testQueue.runDelayedTasksUntil(TimerId.WRITE_STREAM_IDLE);
    waitFor(callback.closeSemaphore);
    testQueue.runSync(() -> assertFalse(writeStream.isOpen()));
}
Also used : AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Aggregations

AsyncQueue (com.google.firebase.firestore.util.AsyncQueue)19 Test (org.junit.Test)15 EmptyAppCheckTokenProvider (com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider)5 EmptyCredentialsProvider (com.google.firebase.firestore.testutil.EmptyCredentialsProvider)3 User (com.google.firebase.firestore.auth.User)2 DatabaseId (com.google.firebase.firestore.model.DatabaseId)2 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 FirebaseAppCheckTokenProvider (com.google.firebase.firestore.auth.FirebaseAppCheckTokenProvider)1 FirebaseAuthCredentialsProvider (com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider)1 ComponentProvider (com.google.firebase.firestore.core.ComponentProvider)1 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