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());
}
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()));
}
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));
}
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());
}
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));
}
Aggregations