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