Search in sources :

Example 1 with User

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());
}
Also used : User(com.google.firebase.firestore.auth.User) Test(org.junit.Test)

Example 2 with User

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));
}
Also used : User(com.google.firebase.firestore.auth.User)

Example 3 with User

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;
}
Also used : User(com.google.firebase.firestore.auth.User) FirebaseAppCheckTokenProvider(com.google.firebase.firestore.auth.FirebaseAppCheckTokenProvider) DatabaseId(com.google.firebase.firestore.model.DatabaseId) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) FirebaseAuthCredentialsProvider(com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider) NonNull(androidx.annotation.NonNull)

Example 4 with User

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();
}
Also used : User(com.google.firebase.firestore.auth.User)

Example 5 with User

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());
}
Also used : User(com.google.firebase.firestore.auth.User) AsyncQueue(com.google.firebase.firestore.util.AsyncQueue) Test(org.junit.Test)

Aggregations

User (com.google.firebase.firestore.auth.User)6 AsyncQueue (com.google.firebase.firestore.util.AsyncQueue)2 Test (org.junit.Test)2 NonNull (androidx.annotation.NonNull)1 FirebaseAppCheckTokenProvider (com.google.firebase.firestore.auth.FirebaseAppCheckTokenProvider)1 FirebaseAuthCredentialsProvider (com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider)1 DatabaseId (com.google.firebase.firestore.model.DatabaseId)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)1 HashSet (java.util.HashSet)1