Search in sources :

Example 91 with DocumentKey

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

the class LocalStoreTestCase method assertNotContains.

/**
 * Asserts that the given local store does not contain the given document.
 */
private void assertNotContains(String keyPathString) {
    DocumentKey key = DocumentKey.fromPathString(keyPathString);
    Document actual = localStore.readDocument(key);
    assertFalse(actual.isValidDocument());
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Document(com.google.firebase.firestore.model.Document) MutableDocument(com.google.firebase.firestore.model.MutableDocument)

Example 92 with DocumentKey

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

the class SQLiteQueryEngineTest method combinesIndexedWithNonIndexedResults.

@Test
public void combinesIndexedWithNonIndexedResults() throws Exception {
    MutableDocument doc1 = doc("coll/a", 1, map("foo", true));
    MutableDocument doc2 = doc("coll/b", 2, map("foo", true));
    MutableDocument doc3 = doc("coll/c", 3, map("foo", true));
    MutableDocument doc4 = doc("coll/d", 3, map("foo", true));
    indexManager.addFieldIndex(fieldIndex("coll", "foo", Kind.ASCENDING));
    addDocument(doc1);
    addDocument(doc2);
    indexManager.updateIndexEntries(docMap(doc1, doc2));
    indexManager.updateCollectionGroup("coll", IndexOffset.fromDocument(doc2));
    addDocument(doc3);
    addMutation(setMutation("coll/d", map("foo", true)));
    Query queryWithFilter = query("coll").filter(filter("foo", "==", true));
    ImmutableSortedMap<DocumentKey, Document> results = expectOptimizedCollectionScan(() -> queryEngine.getDocumentsMatchingQuery(queryWithFilter, SnapshotVersion.NONE, DocumentKey.emptyKeySet()));
    assertTrue(results.containsKey(doc1.getKey()));
    assertTrue(results.containsKey(doc2.getKey()));
    assertTrue(results.containsKey(doc3.getKey()));
    assertTrue(results.containsKey(doc4.getKey()));
}
Also used : Query(com.google.firebase.firestore.core.Query) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Document(com.google.firebase.firestore.model.Document) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 93 with DocumentKey

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

the class TargetCacheTestCase method testAddOrRemoveMatchingKeys.

@Test
public void testAddOrRemoveMatchingKeys() {
    DocumentKey key = key("foo/bar");
    assertFalse(targetCache.containsKey(key));
    addMatchingKey(key, 1);
    assertTrue(targetCache.containsKey(key));
    addMatchingKey(key, 2);
    assertTrue(targetCache.containsKey(key));
    removeMatchingKey(key, 1);
    assertTrue(targetCache.containsKey(key));
    removeMatchingKey(key, 2);
    assertFalse(targetCache.containsKey(key));
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Test(org.junit.Test)

Example 94 with DocumentKey

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

the class TargetCacheTestCase method testHighestTargetId.

@Test
public void testHighestTargetId() {
    assertEquals(0, targetCache.getHighestTargetId());
    TargetData query1 = new TargetData(query("rooms").toTarget(), 1, 10, QueryPurpose.LISTEN);
    addTargetData(query1);
    DocumentKey key1 = key("rooms/bar");
    DocumentKey key2 = key("rooms/foo");
    addMatchingKey(key1, 1);
    addMatchingKey(key2, 1);
    TargetData query2 = new TargetData(query("halls").toTarget(), 2, 20, QueryPurpose.LISTEN);
    addTargetData(query2);
    DocumentKey key3 = key("halls/foo");
    addMatchingKey(key3, 2);
    assertEquals(2, targetCache.getHighestTargetId());
    // TargetIDs never come down.
    removeTargetData(query2);
    assertEquals(2, targetCache.getHighestTargetId());
    // A query with an empty result set still counts.
    TargetData query3 = new TargetData(query("garages").toTarget(), 42, 100, QueryPurpose.LISTEN);
    addTargetData(query3);
    assertEquals(42, targetCache.getHighestTargetId());
    removeTargetData(query1);
    assertEquals(42, targetCache.getHighestTargetId());
    removeTargetData(query3);
    assertEquals(42, targetCache.getHighestTargetId());
    // Verify that the highestTargetID even survives restarts.
    persistence.shutdown();
    persistence.start();
    targetCache = persistence.getTargetCache();
    assertEquals(42, targetCache.getHighestTargetId());
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Test(org.junit.Test)

Example 95 with DocumentKey

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

the class LruGarbageCollectorTestCase method testSequenceNumbersWithMutationsInQueries.

@Test
public void testSequenceNumbersWithMutationsInQueries() {
    // Add mutated docs, then add one of them to a query target so it doesn't get GC'd.
    // Expect 3 past the initial value: the mutations not part of a query, and two queries
    DocumentKey docInQuery = nextTestDocumentKey();
    persistence.runTransaction("mark mutations", () -> {
        // Adding 9 doc keys in a transaction. If we remove one of them, we'll have room for two
        // actual queries.
        markDocumentEligibleForGcInTransaction(docInQuery);
        for (int i = 0; i < 8; i++) {
            markADocumentEligibleForGcInTransaction();
        }
    });
    for (int i = 0; i < 49; i++) {
        addNextQuery();
    }
    persistence.runTransaction("query with a mutation", () -> {
        TargetData targetData = addNextQueryInTransaction();
        addDocumentToTarget(docInQuery, targetData.getTargetId());
    });
    // This should catch the remaining 8 documents, plus the first two queries we added.
    assertEquals(3 + initialSequenceNumber, garbageCollector.getNthSequenceNumber(10));
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) Test(org.junit.Test)

Aggregations

DocumentKey (com.google.firebase.firestore.model.DocumentKey)134 MutableDocument (com.google.firebase.firestore.model.MutableDocument)52 Test (org.junit.Test)36 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)25 Document (com.google.firebase.firestore.model.Document)23 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)16 Mutation (com.google.firebase.firestore.model.mutation.Mutation)15 Map (java.util.Map)15 ResourcePath (com.google.firebase.firestore.model.ResourcePath)13 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)11 HashSet (java.util.HashSet)11 Overlay (com.google.firebase.firestore.model.mutation.Overlay)10 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)9 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)7 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)7 ByteString (com.google.protobuf.ByteString)7 Query (com.google.firebase.firestore.core.Query)6 ObjectValue (com.google.firebase.firestore.model.ObjectValue)6 Timestamp (com.google.firebase.Timestamp)5