use of com.google.firebase.firestore.auth.User in project firebase-android-sdk by firebase.
the class FirestoreTest method testWaitForPendingWritesFailsWhenUserChanges.
@Test
public void testWaitForPendingWritesFailsWhenUserChanges() {
DocumentReference documentReference = testCollection("abc").document("123");
FirebaseFirestore firestore = documentReference.getFirestore();
Map<String, Object> data = map("foo", "bar");
// Prevent pending writes receiving acknowledgement.
waitFor(firestore.disableNetwork());
Task<Void> pendingWrite = documentReference.set(data);
Task<Void> awaitsPendingWrites = firestore.waitForPendingWrites();
assertTrue(!pendingWrite.isComplete());
assertTrue(!awaitsPendingWrites.isComplete());
testChangeUserTo(new User("new user"));
assertTrue(!pendingWrite.isComplete());
assertEquals("'waitForPendingWrites' task is cancelled due to User change.", waitForException(awaitsPendingWrites).getMessage());
}
use of com.google.firebase.firestore.auth.User in project firebase-android-sdk by firebase.
the class SpecTestCase method doChangeUser.
private void doChangeUser(@Nullable String uid) throws Exception {
currentUser = new User(uid);
queue.runSync(() -> syncEngine.handleCredentialChange(currentUser));
}
use of com.google.firebase.firestore.auth.User in project firebase-android-sdk by firebase.
the class FirebaseFirestore method newInstance.
@NonNull
static FirebaseFirestore newInstance(@NonNull Context context, @NonNull FirebaseApp app, @NonNull Deferred<InternalAuthProvider> deferredAuthProvider, @NonNull Deferred<InternalAppCheckTokenProvider> deferredAppCheckTokenProvider, @NonNull String database, @NonNull InstanceRegistry instanceRegistry, @Nullable GrpcMetadataProvider metadataProvider) {
String projectId = app.getOptions().getProjectId();
if (projectId == null) {
throw new IllegalArgumentException("FirebaseOptions.getProjectId() cannot be null");
}
DatabaseId databaseId = DatabaseId.forDatabase(projectId, database);
AsyncQueue queue = new AsyncQueue();
CredentialsProvider<User> authProvider = new FirebaseAuthCredentialsProvider(deferredAuthProvider);
CredentialsProvider<String> appCheckProvider = new FirebaseAppCheckTokenProvider(deferredAppCheckTokenProvider);
// Firestore uses a different database for each app name. Note that we don't use
// app.getPersistenceKey() here because it includes the application ID which is related
// to the project ID. We already include the project ID when resolving the database,
// so there is no need to include it in the persistence key.
String persistenceKey = app.getName();
FirebaseFirestore firestore = new FirebaseFirestore(context, databaseId, persistenceKey, authProvider, appCheckProvider, queue, app, instanceRegistry, metadataProvider);
return firestore;
}
use of com.google.firebase.firestore.auth.User in project firebase-android-sdk by firebase.
the class LruGarbageCollectorTestCase method newTestResources.
private void newTestResources(LruGarbageCollector.Params params) {
persistence = createPersistence(params);
persistence.getReferenceDelegate().setInMemoryPins(new ReferenceSet());
targetCache = persistence.getTargetCache();
documentCache = persistence.getRemoteDocumentCache();
documentCache.setIndexManager(new MemoryIndexManager());
User user = new User("user");
IndexManager indexManager = persistence.getIndexManager(user);
mutationQueue = persistence.getMutationQueue(user, indexManager);
initialSequenceNumber = targetCache.getHighestListenSequenceNumber();
garbageCollector = ((LruDelegate) persistence.getReferenceDelegate()).getGarbageCollector();
lruParams = params;
indexManager.start();
}
use of com.google.firebase.firestore.auth.User in project firebase-android-sdk by firebase.
the class SQLiteOverlayMigrationManagerTest method testCreateOverlayForDifferentUsers.
@Test
public void testCreateOverlayForDifferentUsers() {
writeRemoteDocument(doc("foo/bar", 2, map("it", "original")));
writeMutation(setMutation("foo/bar", map("foo", "set-by-unauthenticated")));
// Switch to a different user
IndexBackfiller indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
localStore = new LocalStore(persistence, indexBackfiller, new QueryEngine(), new User("another_user"));
localStore.start();
writeMutation(setMutation("foo/bar", map("foo", "set-by-another_user")));
// Switch to new persistence and run migrations
this.persistence.shutdown();
persistence = PersistenceTestHelpers.createSQLitePersistence("test-data-migration");
indexBackfiller = new IndexBackfiller(persistence, new AsyncQueue());
localStore = new LocalStore(persistence, indexBackfiller, new QueryEngine(), User.UNAUTHENTICATED);
localStore.start();
assertEquals(setMutation("foo/bar", map("foo", "set-by-unauthenticated")), persistence.getDocumentOverlay(User.UNAUTHENTICATED).getOverlay(key("foo/bar")).getMutation());
assertEquals(setMutation("foo/bar", map("foo", "set-by-another_user")), persistence.getDocumentOverlay(new User("another_user")).getOverlay(key("foo/bar")).getMutation());
SQLiteOverlayMigrationManager migrationManager = (SQLiteOverlayMigrationManager) persistence.getOverlayMigrationManager();
assertFalse(migrationManager.hasPendingOverlayMigration());
}
Aggregations