use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchReset.
private void doWatchReset(JSONArray targetIds) throws Exception {
List<Integer> targets = parseIntList(targetIds);
WatchChange change = new WatchTargetChange(WatchTargetChangeType.Reset, targets);
writeWatchChange(change, SnapshotVersion.NONE);
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchCurrent.
private void doWatchCurrent(JSONArray currentSpec) throws Exception {
List<Integer> currentTargets = parseIntList(currentSpec.getJSONArray(0));
ByteString resumeToken = ByteString.copyFromUtf8(currentSpec.getString(1));
WatchTargetChange change = new WatchTargetChange(WatchTargetChangeType.Current, currentTargets, resumeToken);
writeWatchChange(change, SnapshotVersion.NONE);
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class SpecTestCase method doWatchSnapshot.
private void doWatchSnapshot(JSONObject watchSnapshot) throws Exception {
// The client will only respond to watchSnapshots if they are on a target change with an empty
// set of target IDs.
List<Integer> targets = watchSnapshot.has("targetIds") ? parseIntList(watchSnapshot.getJSONArray("targetIds")) : Collections.emptyList();
String resumeToken = watchSnapshot.optString("resumeToken");
WatchChange change = new WatchTargetChange(WatchTargetChangeType.NoChange, targets, ByteString.copyFromUtf8(resumeToken));
writeWatchChange(change, version(watchSnapshot.getLong("version")));
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method createAggregator.
/**
* Creates an aggregator initialized with the set of provided WatchChanges. Tests can add further
* changes via `handleDocumentChange`, `handleTargetChange` and `handleExistenceFilterChange`.
*
* @param targetMap A map of query data for all active targets. The map must include an entry for
* every target referenced by any of the watch changes.
* @param outstandingResponses The number of outstanding ACKs a target has to receive before it is
* considered active, or `noOutstandingResponses` if all targets are already active.
* @param existingKeys The set of documents that are considered synced with the test targets as
* part of a previous listen. To modify this set during test execution, invoke
* `targetMetadataProvider.setSyncedKeys()`.
* @param watchChanges The watch changes to apply before returning the aggregator. Supported
* changes are DocumentWatchChange and WatchTargetChange.
*/
private WatchChangeAggregator createAggregator(Map<Integer, TargetData> targetMap, Map<Integer, Integer> outstandingResponses, ImmutableSortedSet<DocumentKey> existingKeys, WatchChange... watchChanges) {
WatchChangeAggregator aggregator = new WatchChangeAggregator(targetMetadataProvider);
List<Integer> targetIds = new ArrayList<>();
for (Map.Entry<Integer, TargetData> entry : targetMap.entrySet()) {
targetIds.add(entry.getKey());
targetMetadataProvider.setSyncedKeys(entry.getValue(), existingKeys);
}
for (Map.Entry<Integer, Integer> entry : outstandingResponses.entrySet()) {
for (int i = 0; i < entry.getValue(); ++i) {
aggregator.recordPendingTargetRequest(entry.getKey());
}
}
for (WatchChange watchChange : watchChanges) {
if (watchChange instanceof DocumentChange) {
aggregator.handleDocumentChange((DocumentChange) watchChange);
} else if (watchChange instanceof WatchTargetChange) {
aggregator.handleTargetChange((WatchTargetChange) watchChange);
} else {
fail("Encountered unexpected type of WatchChange");
}
}
aggregator.handleTargetChange(new WatchTargetChange(WatchTargetChangeType.NoChange, targetIds, resumeToken));
return aggregator;
}
use of com.google.firebase.firestore.remote.WatchChange.WatchTargetChange in project firebase-android-sdk by firebase.
the class RemoteEventTest method testExistenceFilterMismatchRemovesCurrentChanges.
@Test
public void testExistenceFilterMismatchRemovesCurrentChanges() {
Map<Integer, TargetData> targetMap = activeQueries(1);
WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
WatchTargetChange markCurrent = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
aggregator.handleTargetChange(markCurrent);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
DocumentChange addDoc = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
aggregator.handleDocumentChange(addDoc);
// The existence filter mismatch will remove the document from target 1, but not synthesize a
// document delete.
WatchChange.ExistenceFilterWatchChange existenceFilter = new WatchChange.ExistenceFilterWatchChange(1, new ExistenceFilter(0));
aggregator.handleExistenceFilter(existenceFilter);
RemoteEvent event = aggregator.createRemoteEvent(version(3));
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(1, event.getDocumentUpdates().size());
assertEquals(1, event.getTargetMismatches().size());
assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
assertEquals(1, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(ByteString.EMPTY, false, null, null, null);
assertEquals(mapping1, event.getTargetChanges().get(1));
}
Aggregations