Search in sources :

Example 6 with DocumentSet

use of com.google.firebase.firestore.model.DocumentSet in project firebase-android-sdk by firebase.

the class QueryEngineTestCase method doesNotUseInitialResultsForLimitToLastQueryWithDocumentRemoval.

@Test
public void doesNotUseInitialResultsForLimitToLastQueryWithDocumentRemoval() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true)).orderBy(orderBy("order", "desc")).limitToLast(1);
    // While the backend would never add DocA to the set of remote keys, this allows us to easily
    // simulate what would happen when a document no longer matches due to an out-of-band update.
    addDocument(NON_MATCHING_DOC_A);
    persistQueryMapping(NON_MATCHING_DOC_A.getKey());
    addDocument(MATCHING_DOC_B);
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 7 with DocumentSet

use of com.google.firebase.firestore.model.DocumentSet in project firebase-android-sdk by firebase.

the class QueryEngineTestCase method doesNotUseInitialResultsWithoutLimboFreeSnapshotVersion.

@Test
public void doesNotUseInitialResultsWithoutLimboFreeSnapshotVersion() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true));
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, MISSING_LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator()), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 8 with DocumentSet

use of com.google.firebase.firestore.model.DocumentSet in project firebase-android-sdk by firebase.

the class QueryEngineTestCase method doesNotUseInitialResultsForLimitQueryWithDocumentRemoval.

@Test
public void doesNotUseInitialResultsForLimitQueryWithDocumentRemoval() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true)).limitToFirst(1);
    // While the backend would never add DocA to the set of remote keys, this allows us to easily
    // simulate what would happen when a document no longer matches due to an out-of-band update.
    addDocument(NON_MATCHING_DOC_A);
    persistQueryMapping(NON_MATCHING_DOC_A.getKey());
    addDocument(MATCHING_DOC_B);
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 9 with DocumentSet

use of com.google.firebase.firestore.model.DocumentSet in project firebase-android-sdk by firebase.

the class QueryEngineTestCase method filtersNonMatchingInitialResults.

@Test
public void filtersNonMatchingInitialResults() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true));
    addDocument(MATCHING_DOC_A, MATCHING_DOC_B);
    persistQueryMapping(MATCHING_DOC_A.getKey(), MATCHING_DOC_B.getKey());
    // Add a mutated document that is not yet part of query's set of remote keys.
    addDocumentWithEventVersion(version(1), NON_MATCHING_DOC_A);
    DocumentSet docs = expectOptimizedCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 10 with DocumentSet

use of com.google.firebase.firestore.model.DocumentSet in project firebase-android-sdk by firebase.

the class QueryEngineTestCase method doesNotUseInitialResultsForLimitQueryWhenLastDocumentHasBeenUpdatedOutOfBand.

@Test
public void doesNotUseInitialResultsForLimitQueryWhenLastDocumentHasBeenUpdatedOutOfBand() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true)).orderBy(orderBy("order", "desc")).limitToFirst(1);
    // Add a query mapping for a document that matches, but that sorts below another document based
    // due to an update that the SDK received after the query's snapshot was persisted.
    addDocument(UPDATED_DOC_A);
    persistQueryMapping(UPDATED_DOC_A.getKey());
    addDocument(MATCHING_DOC_B);
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Aggregations

DocumentSet (com.google.firebase.firestore.model.DocumentSet)18 Test (org.junit.Test)14 Query (com.google.firebase.firestore.core.Query)12 DocumentViewChange (com.google.firebase.firestore.core.DocumentViewChange)3 DocumentKey (com.google.firebase.firestore.model.DocumentKey)3 ViewSnapshot (com.google.firebase.firestore.core.ViewSnapshot)2 Document (com.google.firebase.firestore.model.Document)2 MutableDocument (com.google.firebase.firestore.model.MutableDocument)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)1 SyncState (com.google.firebase.firestore.core.ViewSnapshot.SyncState)1 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1