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());
}
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();
}
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();
}
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));
}
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()));
}
Aggregations