use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class LocalDocumentsView method getDocumentsMatchingDocumentQuery.
/**
* Performs a simple document lookup for the given path.
*/
private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingDocumentQuery(ResourcePath path) {
ImmutableSortedMap<DocumentKey, Document> result = emptyDocumentMap();
// Just do a simple document lookup.
Document doc = getDocument(DocumentKey.fromPath(path));
if (doc.isFoundDocument()) {
result = result.insert(doc.getKey(), doc);
}
return result;
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class SyncEngine method trackLimboChange.
private void trackLimboChange(LimboDocumentChange change) {
DocumentKey key = change.getKey();
if (!activeLimboTargetsByKey.containsKey(key) && !enqueuedLimboResolutions.contains(key)) {
Logger.debug(TAG, "New document in limbo: %s", key);
enqueuedLimboResolutions.add(key);
pumpEnqueuedLimboResolutions();
}
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class TestCaseConverter method convertDatabaseContents.
private List<Collection> convertDatabaseContents(DatastoreTestTrace.FirestoreV1Action action) {
LinkedHashMap<String, List<Document>> collections = new LinkedHashMap<>();
List<RunQueryResponse> responses = action.getDatabaseContentsBeforeAction().getResponseList();
for (RunQueryResponse response : responses) {
if (response.hasDocument()) {
Document document = response.getDocument();
DocumentKey documentKey = DocumentKey.fromName(document.getName());
String collectionId = documentKey.getCollectionGroup();
List<Document> documents = collections.computeIfAbsent(collectionId, name -> new ArrayList<>());
documents.add(document);
}
}
return collections.entrySet().stream().map(entry -> Collection.Builder.builder().setName(entry.getKey()).setDocuments(entry.getValue()).build()).collect(Collectors.toList());
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class SpecTestCase method doMutation.
private void doMutation(Mutation mutation) throws Exception {
DocumentKey documentKey = mutation.getKey();
TaskCompletionSource<Void> callback = new TaskCompletionSource<>();
Task<Void> writeProcessed = callback.getTask().continueWith(backgroundExecutor, task -> {
if (task.isSuccessful()) {
SpecTestCase.this.acknowledgedDocs.add(documentKey);
} else {
SpecTestCase.this.rejectedDocs.add(documentKey);
}
return null;
});
getCurrentOutstandingWrites().add(new Pair<>(mutation, writeProcessed));
log(" Sending this write: " + mutation);
queue.runSync(() -> syncEngine.writeMutations(singletonList(mutation), callback));
}
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()));
}
Aggregations