use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class DocumentChangeTest method testModifications.
@Test
public void testModifications() {
Query query = Query.atPath(path("c"));
List<MutableDocument> initialDocs = asList(doc("c/a", 1, map("value", "a-1")), doc("c/b", 1, map("value", "b-1")), doc("c/c", 1, map("value", "c-1")));
List<MutableDocument> updates = asList(doc("c/a", 2, map("value", "a-2")), doc("c/c", 2, map("value", "c-2")));
validatePositions(query, initialDocs, Collections.emptyList(), updates, Collections.emptyList());
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class DocumentChangeTest method testAdditions.
@Test
public void testAdditions() {
Query query = Query.atPath(path("c"));
List<MutableDocument> initialDocs = asList(doc("c/a", 1, map()), doc("c/c", 1, map()), doc("c/e", 1, map()));
List<MutableDocument> adds = asList(doc("c/d", 2, map()), doc("c/b", 2, map()));
validatePositions(query, initialDocs, adds, asList(), Collections.emptyList());
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class DocumentChangeTest method randomTests.
@Test
public void randomTests() {
for (int run = 0; run < 100; run++) {
Query query = Query.atPath(path("c")).orderBy(orderBy("sort"));
Map<DocumentKey, MutableDocument> initialDocs = new HashMap<>();
List<MutableDocument> adds = new ArrayList<>();
List<MutableDocument> updates = new ArrayList<>();
List<MutableDocument> deletes = new ArrayList<>();
int numDocs = 100;
for (int i = 0; i < numDocs; i++) {
String docKey = "c/test-doc-" + i;
// Skip 20% of the docs
if (Math.random() > 0.8) {
initialDocs.put(key(docKey), doc(docKey, 1, map("sort", Math.random())));
}
}
for (int i = 0; i < numDocs; i++) {
String docKey = "c/test-doc-" + i;
// Only update 20% of the docs
if (Math.random() < 0.2) {
// 30% deletes, rest updates and/or additions
if (Math.random() < 0.3) {
deletes.add(deletedDoc(docKey, 2));
} else {
if (initialDocs.containsKey(key(docKey))) {
updates.add(doc(docKey, 2, map("sort", Math.random())));
} else {
adds.add(doc(docKey, 2, map("sort", Math.random())));
}
}
}
}
validatePositions(query, initialDocs.values(), adds, updates, deletes);
}
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class SQLiteRemoteDocumentCache method getAll.
@Override
public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKeys) {
Map<DocumentKey, MutableDocument> results = new HashMap<>();
List<Object> bindVars = new ArrayList<>();
for (DocumentKey key : documentKeys) {
bindVars.add(EncodedPath.encode(key.getPath()));
// Make sure each key has a corresponding entry, which is null in case the document is not
// found.
results.put(key, MutableDocument.newInvalidDocument(key));
}
SQLitePersistence.LongQuery longQuery = new SQLitePersistence.LongQuery(db, "SELECT contents, read_time_seconds, read_time_nanos FROM remote_documents " + "WHERE path IN (", bindVars, ") ORDER BY path");
BackgroundQueue backgroundQueue = new BackgroundQueue();
while (longQuery.hasMoreSubqueries()) {
longQuery.performNextSubquery().forEach(row -> processRowInBackground(backgroundQueue, results, row));
}
backgroundQueue.drain();
return results;
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class SyncEngine method handleRejectedListen.
/**
* Called by FirestoreClient to notify us of a rejected listen.
*/
@Override
public void handleRejectedListen(int targetId, Status error) {
assertCallback("handleRejectedListen");
LimboResolution limboResolution = activeLimboResolutionsByTarget.get(targetId);
DocumentKey limboKey = limboResolution != null ? limboResolution.key : null;
if (limboKey != null) {
// Since this query failed, we won't want to manually unlisten to it.
// So go ahead and remove it from bookkeeping.
activeLimboTargetsByKey.remove(limboKey);
activeLimboResolutionsByTarget.remove(targetId);
pumpEnqueuedLimboResolutions();
// TODO: Retry on transient errors?
// It's a limbo doc. Create a synthetic event saying it was deleted. This is kind of a hack.
// Ideally, we would have a method in the local store to purge a document. However, it would
// be tricky to keep all of the local store's invariants with another method.
MutableDocument result = MutableDocument.newNoDocument(limboKey, SnapshotVersion.NONE);
Map<DocumentKey, MutableDocument> documentUpdates = Collections.singletonMap(limboKey, result);
Set<DocumentKey> limboDocuments = Collections.singleton(limboKey);
RemoteEvent event = new RemoteEvent(SnapshotVersion.NONE, /* targetChanges= */
Collections.emptyMap(), /* targetMismatches= */
Collections.emptySet(), documentUpdates, limboDocuments);
handleRemoteEvent(event);
} else {
localStore.releaseTarget(targetId);
removeAndCleanupTarget(targetId, error);
}
}
Aggregations