Search in sources :

Example 1 with WatchChange

use of com.google.firebase.firestore.remote.WatchChange 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);
}
Also used : WatchChange(com.google.firebase.firestore.remote.WatchChange) ExistenceFilterWatchChange(com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)

Example 2 with WatchChange

use of com.google.firebase.firestore.remote.WatchChange in project firebase-android-sdk by firebase.

the class SpecTestCase method doWatchEntity.

private void doWatchEntity(JSONObject watchEntity) throws Exception {
    if (watchEntity.has("docs")) {
        Assert.hardAssert(!watchEntity.has("doc"), "Exactly one of |doc| or |docs| needs to be set.");
        JSONArray docs = watchEntity.getJSONArray("docs");
        for (int i = 0; i < docs.length(); ++i) {
            JSONObject doc = docs.getJSONObject(i);
            JSONObject watchSpec = new JSONObject();
            watchSpec.put("doc", doc);
            if (watchEntity.has("targets")) {
                watchSpec.put("targets", watchEntity.get("targets"));
            }
            if (watchEntity.has("removedTargets")) {
                watchSpec.put("removedTargets", watchEntity.get("removedTargets"));
            }
            doWatchEntity(watchSpec);
        }
    } else if (watchEntity.has("doc")) {
        JSONObject docSpec = watchEntity.getJSONObject("doc");
        String key = docSpec.getString("key");
        @Nullable Map<String, Object> value = !docSpec.isNull("value") ? parseMap(docSpec.getJSONObject("value")) : null;
        long version = docSpec.getLong("version");
        MutableDocument doc = value != null ? doc(key, version, value) : deletedDoc(key, version);
        List<Integer> updated = parseIntList(watchEntity.optJSONArray("targets"));
        List<Integer> removed = parseIntList(watchEntity.optJSONArray("removedTargets"));
        WatchChange change = new DocumentChange(updated, removed, doc.getKey(), doc);
        writeWatchChange(change, SnapshotVersion.NONE);
    } else if (watchEntity.has("key")) {
        String key = watchEntity.getString("key");
        List<Integer> removed = parseIntList(watchEntity.optJSONArray("removedTargets"));
        WatchChange change = new DocumentChange(Collections.emptyList(), removed, key(key), null);
        writeWatchChange(change, SnapshotVersion.NONE);
    } else {
        throw Assert.fail("Either key, doc or docs must be set.");
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) MutableDocument(com.google.firebase.firestore.model.MutableDocument) WatchChange(com.google.firebase.firestore.remote.WatchChange) ExistenceFilterWatchChange(com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with WatchChange

use of com.google.firebase.firestore.remote.WatchChange 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")));
}
Also used : WatchChange(com.google.firebase.firestore.remote.WatchChange) ExistenceFilterWatchChange(com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange) ByteString(com.google.protobuf.ByteString) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)

Example 4 with WatchChange

use of com.google.firebase.firestore.remote.WatchChange in project firebase-android-sdk by firebase.

the class TestUtil method noChangeEvent.

public static RemoteEvent noChangeEvent(int targetId, int version, ByteString resumeToken) {
    TargetData targetData = TestUtil.targetData(targetId, QueryPurpose.LISTEN, "foo/bar");
    TestTargetMetadataProvider testTargetMetadataProvider = new TestTargetMetadataProvider();
    testTargetMetadataProvider.setSyncedKeys(targetData, DocumentKey.emptyKeySet());
    WatchChangeAggregator aggregator = new WatchChangeAggregator(testTargetMetadataProvider);
    WatchChange.WatchTargetChange watchChange = new WatchChange.WatchTargetChange(WatchChange.WatchTargetChangeType.NoChange, asList(targetId), resumeToken);
    aggregator.handleTargetChange(watchChange);
    return aggregator.createRemoteEvent(version(version));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchChangeAggregator(com.google.firebase.firestore.remote.WatchChangeAggregator) WatchChange(com.google.firebase.firestore.remote.WatchChange)

Aggregations

WatchChange (com.google.firebase.firestore.remote.WatchChange)4 ExistenceFilterWatchChange (com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange)3 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)2 ByteString (com.google.protobuf.ByteString)2 TargetData (com.google.firebase.firestore.local.TargetData)1 MutableDocument (com.google.firebase.firestore.model.MutableDocument)1 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)1 WatchChangeAggregator (com.google.firebase.firestore.remote.WatchChangeAggregator)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1