Search in sources :

Example 1 with EmptyAppCheckTokenProvider

use of com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider in project firebase-android-sdk by firebase.

the class StreamTest method testTokenIsNotInvalidatedOnceStreamIsHealthy.

@Test
public void testTokenIsNotInvalidatedOnceStreamIsHealthy() 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);
    testQueue.runDelayedTasksUntil(TimerId.HEALTH_CHECK_TIMEOUT);
    // Simulate callback from GRPC with an unauthenticated error -- this should NOT invalidate the
    // token.
    testQueue.runSync(() -> writeStream.handleServerClose(Status.UNAUTHENTICATED));
    assertThat(mockCredentialsProvider.observedStates()).containsExactly("getToken");
}
Also used : EmptyAppCheckTokenProvider(com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Example 2 with EmptyAppCheckTokenProvider

use of com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider in project firebase-android-sdk by firebase.

the class StreamTest method testWriteStreamStopPartial.

/**
 * Verifies that the stream issues an onClose callback after a call to stop().
 */
@Test
public void testWriteStreamStopPartial() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    Datastore datastore = new Datastore(IntegrationTestUtil.testEnvDatabaseInfo(), testQueue, new EmptyCredentialsProvider(), new EmptyAppCheckTokenProvider(), ApplicationProvider.getApplicationContext(), null);
    StreamStatusCallback streamCallback = new StreamStatusCallback() {
    };
    final WriteStream writeStream = datastore.createWriteStream(streamCallback);
    testQueue.enqueueAndForget(writeStream::start);
    waitFor(streamCallback.openSemaphore);
    // Don't start the handshake
    testQueue.runSync(writeStream::stop);
    assertThat(streamCallback.closeSemaphore.availablePermits()).isEqualTo(1);
}
Also used : EmptyAppCheckTokenProvider(com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) EmptyCredentialsProvider(com.google.firebase.firestore.testutil.EmptyCredentialsProvider) Test(org.junit.Test)

Example 3 with EmptyAppCheckTokenProvider

use of com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider 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 4 with EmptyAppCheckTokenProvider

use of com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider in project firebase-android-sdk by firebase.

the class StreamTest method testWatchStreamStopBeforeHandshake.

@Test
public void testWatchStreamStopBeforeHandshake() throws Exception {
    AsyncQueue testQueue = new AsyncQueue();
    GrpcMetadataProvider mockGrpcProvider = mock(GrpcMetadataProvider.class);
    Datastore datastore = new Datastore(IntegrationTestUtil.testEnvDatabaseInfo(), testQueue, new EmptyCredentialsProvider(), new EmptyAppCheckTokenProvider(), ApplicationProvider.getApplicationContext(), mockGrpcProvider);
    StreamStatusCallback streamCallback = new StreamStatusCallback() {
    };
    final WatchStream watchStream = datastore.createWatchStream(streamCallback);
    testQueue.enqueueAndForget(watchStream::start);
    waitFor(streamCallback.openSemaphore);
    // Stop should call watchStreamStreamDidClose.
    testQueue.runSync(watchStream::stop);
    assertThat(streamCallback.closeSemaphore.availablePermits()).isEqualTo(1);
    verify(mockGrpcProvider, times(1)).updateMetadata(any());
}
Also used : EmptyAppCheckTokenProvider(com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) EmptyCredentialsProvider(com.google.firebase.firestore.testutil.EmptyCredentialsProvider) Test(org.junit.Test)

Example 5 with EmptyAppCheckTokenProvider

use of com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider in project firebase-android-sdk by firebase.

the class StreamTest method createAndOpenWriteStream.

/**
 * Creates a WriteStream and gets it in a state that accepts mutations.
 */
private WriteStream createAndOpenWriteStream(AsyncQueue testQueue, StreamStatusCallback callback) {
    Datastore datastore = new Datastore(IntegrationTestUtil.testEnvDatabaseInfo(), testQueue, new EmptyCredentialsProvider(), new EmptyAppCheckTokenProvider(), ApplicationProvider.getApplicationContext(), null);
    final WriteStream writeStream = datastore.createWriteStream(callback);
    waitForWriteStreamOpen(testQueue, writeStream, callback);
    return writeStream;
}
Also used : EmptyAppCheckTokenProvider(com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider) EmptyCredentialsProvider(com.google.firebase.firestore.testutil.EmptyCredentialsProvider)

Aggregations

EmptyAppCheckTokenProvider (com.google.firebase.firestore.testutil.EmptyAppCheckTokenProvider)6 AsyncQueue (com.google.firebase.firestore.util.AsyncQueue)5 Test (org.junit.Test)5 EmptyCredentialsProvider (com.google.firebase.firestore.testutil.EmptyCredentialsProvider)4 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1