Search in sources :

Example 1 with AsyncQueue

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

the class StreamTest method testWriteStreamStop.

@Test
public void testWriteStreamStop() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    StreamStatusCallback streamCallback = new StreamStatusCallback();
    WriteStream writeStream = createAndOpenWriteStream(testQueue, streamCallback);
    // Stop should call watchStreamStreamDidClose.
    testQueue.runSync(writeStream::stop);
    assertThat(streamCallback.closeSemaphore.availablePermits()).isEqualTo(1);
}
Also used : AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Example 2 with AsyncQueue

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

the class StreamTest method testWriteStreamStopAfterHandshake.

@Test
public void testWriteStreamStopAfterHandshake() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    Datastore datastore = new Datastore(IntegrationTestUtil.testEnvDatabaseInfo(), testQueue, new EmptyCredentialsProvider(), new EmptyAppCheckTokenProvider(), ApplicationProvider.getApplicationContext(), null);
    final WriteStream[] writeStreamWrapper = new WriteStream[1];
    StreamStatusCallback streamCallback = new StreamStatusCallback() {

        @Override
        public void onHandshakeComplete() {
            assertThat(writeStreamWrapper[0].getLastStreamToken()).isNotEmpty();
            super.onHandshakeComplete();
        }

        @Override
        public void onWriteResponse(SnapshotVersion commitVersion, List<MutationResult> mutationResults) {
            assertThat(mutationResults).hasSize(1);
            assertThat(writeStreamWrapper[0].getLastStreamToken()).isNotEmpty();
            super.onWriteResponse(commitVersion, mutationResults);
        }
    };
    WriteStream writeStream = writeStreamWrapper[0] = datastore.createWriteStream(streamCallback);
    testQueue.enqueueAndForget(writeStream::start);
    waitFor(streamCallback.openSemaphore);
    // Writing before the handshake should throw
    testQueue.enqueueAndForget(() -> assertThrows(Throwable.class, () -> writeStream.writeMutations(mutations)));
    // Handshake should always be called
    testQueue.enqueueAndForget(writeStream::writeHandshake);
    waitFor(streamCallback.handshakeSemaphore);
    // Now writes should succeed
    testQueue.enqueueAndForget(() -> writeStream.writeMutations(mutations));
    waitFor(streamCallback.responseReceivedSemaphore);
    testQueue.runSync(writeStream::stop);
}
Also used : EmptyAppCheckTokenProvider(com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) ArrayList(java.util.ArrayList) List(java.util.List) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) EmptyCredentialsProvider(com.google.firebase.firestore.testutil.EmptyCredentialsProvider) Test(org.junit.Test)

Example 3 with AsyncQueue

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

the class StreamTest method testStreamCancelsIdleOnWrite.

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

Example 4 with AsyncQueue

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

the class SpecTestCase method initClient.

/**
 * Sets up a new client. Is used to initially setup the client initially and after every restart.
 */
private void initClient() {
    queue = new AsyncQueue();
    datastore = new MockDatastore(databaseInfo, queue, ApplicationProvider.getApplicationContext());
    ComponentProvider.Configuration configuration = new ComponentProvider.Configuration(ApplicationProvider.getApplicationContext(), queue, databaseInfo, datastore, currentUser, maxConcurrentLimboResolutions, new FirebaseFirestoreSettings.Builder().build());
    ComponentProvider provider = initializeComponentProvider(configuration, garbageCollectionEnabled);
    localPersistence = provider.getPersistence();
    remoteStore = provider.getRemoteStore();
    syncEngine = provider.getSyncEngine();
    eventManager = provider.getEventManager();
}
Also used : ComponentProvider(com.google.firebase.firestore.core.ComponentProvider) MockDatastore(com.google.firebase.firestore.remote.MockDatastore) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue)

Example 5 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)

Aggregations

AsyncQueue (com.google.firebase.firestore.util.AsyncQueue)18 Test (org.junit.Test)14 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