use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class TestUtil method viewChanges.
public static LocalViewChanges viewChanges(int targetId, boolean fromCache, List<String> addedKeys, List<String> removedKeys) {
ImmutableSortedSet<DocumentKey> added = DocumentKey.emptyKeySet();
for (String keyPath : addedKeys) {
added = added.insert(key(keyPath));
}
ImmutableSortedSet<DocumentKey> removed = DocumentKey.emptyKeySet();
for (String keyPath : removedKeys) {
removed = removed.insert(key(keyPath));
}
return new LocalViewChanges(targetId, fromCache, added, removed);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class RemoteEventTest method testTracksLimboDocuments.
@Test
public void testTracksLimboDocuments() {
Map<Integer, TargetData> listens = activeQueries(1);
listens.putAll(activeLimboQueries("doc/2", 2));
// Add 3 docs: 1 is limbo and non-limbo, 2 is limbo-only, 3 is non-limbo
MutableDocument doc1 = doc("docs/1", 1, map("key", "value"));
MutableDocument doc2 = doc("docs/2", 1, map("key", "value"));
MutableDocument doc3 = doc("docs/3", 1, map("key", "value"));
// Target 2 is a limbo target
DocumentChange docChange1 = new DocumentChange(asList(1, 2), emptyList(), doc1.getKey(), doc1);
DocumentChange docChange2 = new DocumentChange(asList(2), emptyList(), doc2.getKey(), doc2);
DocumentChange docChange3 = new DocumentChange(asList(1), emptyList(), doc3.getKey(), doc3);
WatchTargetChange targetsChange = new WatchTargetChange(WatchTargetChangeType.Current, asList(1, 2));
RemoteEvent event = createRemoteEvent(3, listens, noOutstandingResponses, noExistingKeys, docChange1, docChange2, docChange3, targetsChange);
Set<DocumentKey> limboDocuments = event.getResolvedLimboDocuments();
// Doc1 is in both limbo and non-limbo targets, therefore not tracked as limbo
assertFalse(limboDocuments.contains(doc1.getKey()));
// Doc2 is only in the limbo target, so is tracked as a limbo document
assertTrue(limboDocuments.contains(doc2.getKey()));
// Doc3 is only in the non-limbo target, therefore not tracked as limbo
assertFalse(limboDocuments.contains(doc3.getKey()));
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class DocumentOverlayCacheTestCase method testCanReadSavedOverlaysInBatches.
@Test
public void testCanReadSavedOverlaysInBatches() {
Mutation m1 = setMutation("coll1/a", map("a", 1));
Mutation m2 = setMutation("coll1/b", map("b", 2));
Mutation m3 = setMutation("coll2/c", map("c", 3));
saveOverlays(3, m1, m2, m3);
Map<DocumentKey, Overlay> overlays = cache.getOverlays(new TreeSet<>(Arrays.asList(key("coll1/a"), key("coll1/b"), key("coll2/c"))));
assertEquals(m1, overlays.get(key("coll1/a")).getMutation());
assertEquals(m2, overlays.get(key("coll1/b")).getMutation());
assertEquals(m3, overlays.get(key("coll2/c")).getMutation());
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class IndexBackfillerTest method testBackfillAppliesDeleteToRemoteDoc.
@Test
public void testBackfillAppliesDeleteToRemoteDoc() {
addFieldIndex("coll", "foo");
addDoc("coll/doc", version(5), "foo", 1);
int documentsProcessed = backfiller.backfill();
assertEquals(1, documentsProcessed);
Mutation delete = deleteMutation("coll/doc");
addMutationToOverlay("coll/doc", delete);
documentsProcessed = backfiller.backfill();
assertEquals(1, documentsProcessed);
Target target = query("coll").filter(filter("foo", "==", 2)).toTarget();
List<DocumentKey> matching = indexManager.getDocumentsMatchingTarget(target);
assertTrue(matching.isEmpty());
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class ViewSnapshotTest method testConstructor.
@Test
public void testConstructor() {
Query query = Query.atPath(ResourcePath.fromString("a"));
DocumentSet docs = DocumentSet.emptySet(Document.KEY_COMPARATOR).add(doc("c/foo", 1, map()));
DocumentSet oldDocs = DocumentSet.emptySet(Document.KEY_COMPARATOR);
List<DocumentViewChange> changes = Arrays.asList(DocumentViewChange.create(Type.ADDED, doc("c/foo", 1, map())));
ImmutableSortedSet<DocumentKey> mutatedKeys = keySet(key("c/foo"));
boolean fromCache = true;
boolean hasPendingWrites = true;
boolean syncStateChanges = true;
boolean excludesMetadataChanges = true;
ViewSnapshot snapshot = new ViewSnapshot(query, docs, oldDocs, changes, fromCache, mutatedKeys, syncStateChanges, excludesMetadataChanges);
assertEquals(query, snapshot.getQuery());
assertEquals(docs, snapshot.getDocuments());
assertEquals(oldDocs, snapshot.getOldDocuments());
assertEquals(changes, snapshot.getChanges());
assertEquals(fromCache, snapshot.isFromCache());
assertEquals(mutatedKeys, snapshot.getMutatedKeys());
assertEquals(hasPendingWrites, snapshot.hasPendingWrites());
assertEquals(syncStateChanges, snapshot.didSyncStateChange());
assertEquals(excludesMetadataChanges, snapshot.excludesMetadataChanges());
}
Aggregations