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