Search in sources :

Example 6 with EmptyAppCheckTokenProvider

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

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