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 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.util.AsyncQueue in project firebase-android-sdk by firebase.
the class IntegrationTestUtil method testFirestore.
public static FirebaseFirestore testFirestore(String projectId, Logger.Level logLevel, FirebaseFirestoreSettings settings, String persistenceKey) {
// This unfortunately is a global setting that affects existing Firestore clients.
Logger.setLogLevel(logLevel);
Context context = ApplicationProvider.getApplicationContext();
DatabaseId databaseId = DatabaseId.forDatabase(projectId, DatabaseId.DEFAULT_DATABASE_ID);
ensureStrictMode();
AsyncQueue asyncQueue = new AsyncQueue();
FirebaseFirestore firestore = AccessHelper.newFirebaseFirestore(context, databaseId, persistenceKey, MockCredentialsProvider.instance(), new EmptyAppCheckTokenProvider(), asyncQueue, /*firebaseApp=*/
null, /*instanceRegistry=*/
(dbId) -> {
});
waitFor(firestore.clearPersistence());
firestore.setFirestoreSettings(settings);
firestoreStatus.put(firestore, true);
return firestore;
}
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 testCreateOverlayFromPatches.
@Test
public void testCreateOverlayFromPatches() {
writeRemoteDocument(doc("foo/bar", 2, map("it", "original")));
writeMutation(patchMutation("foo/bar", map("it", FieldValue.increment(1))));
writeMutations(asList(patchMutation("foo/bar", map("it", FieldValue.increment(1))), mergeMutation("foo/newBar", map("it", FieldValue.arrayUnion(1)), Collections.emptyList())));
// Switch to new persistence and run migrations
this.persistence.shutdown();
persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration");
IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
localStore = new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED);
localStore.start();
DocumentOverlayCache overlay = persistence.getDocumentOverlayCache(User.UNAUTHENTICATED);
assertEquals(mergeMutation("foo/bar", map("it", 2), Collections.emptyList()), overlay.getOverlay(key("foo/bar")).getMutation());
assertEquals(mergeMutation("foo/newBar", map("it", asList(1)), Collections.emptyList()), overlay.getOverlay(key("foo/newBar")).getMutation());
assertContains(doc("foo/bar", 2, map("it", 2)).setHasLocalMutations());
assertContains(doc("foo/newBar", 0, map("it", asList(1))).setHasLocalMutations());
SQLiteOverlayMigrationManager migrationManager = (SQLiteOverlayMigrationManager) persistence.getOverlayMigrationManager();
assertFalse(migrationManager.hasPendingOverlayMigration());
}
Aggregations