Search in sources :

Example 1 with WatchChangeAggregator

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

the class TestUtil method existenceFilterEvent.

public static RemoteEvent existenceFilterEvent(int targetId, ImmutableSortedSet<DocumentKey> syncedKeys, int remoteCount, int version) {
    TargetData targetData = TestUtil.targetData(targetId, QueryPurpose.LISTEN, "foo");
    TestTargetMetadataProvider testTargetMetadataProvider = new TestTargetMetadataProvider();
    testTargetMetadataProvider.setSyncedKeys(targetData, syncedKeys);
    ExistenceFilter existenceFilter = new ExistenceFilter(remoteCount);
    WatchChangeAggregator aggregator = new WatchChangeAggregator(testTargetMetadataProvider);
    WatchChange.ExistenceFilterWatchChange existenceFilterWatchChange = new WatchChange.ExistenceFilterWatchChange(targetId, existenceFilter);
    aggregator.handleExistenceFilter(existenceFilterWatchChange);
    return aggregator.createRemoteEvent(version(version));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchChangeAggregator(com.google.firebase.firestore.remote.WatchChangeAggregator) ExistenceFilter(com.google.firebase.firestore.remote.ExistenceFilter) WatchChange(com.google.firebase.firestore.remote.WatchChange)

Example 2 with WatchChangeAggregator

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

the class TestUtil method addedRemoteEvent.

public static RemoteEvent addedRemoteEvent(List<MutableDocument> docs, List<Integer> updatedInTargets, List<Integer> removedFromTargets) {
    Preconditions.checkArgument(!docs.isEmpty(), "Cannot pass empty docs array");
    WatchChangeAggregator aggregator = new WatchChangeAggregator(new WatchChangeAggregator.TargetMetadataProvider() {

        @Override
        public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
            return DocumentKey.emptyKeySet();
        }

        @Override
        public TargetData getTargetDataForTarget(int targetId) {
            ResourcePath collectionPath = docs.get(0).getKey().getCollectionPath();
            return targetData(targetId, QueryPurpose.LISTEN, collectionPath.toString());
        }
    });
    SnapshotVersion version = SnapshotVersion.NONE;
    for (MutableDocument doc : docs) {
        DocumentChange change = new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
        aggregator.handleDocumentChange(change);
        version = doc.getVersion().compareTo(version) > 0 ? doc.getVersion() : version;
    }
    return aggregator.createRemoteEvent(version);
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchChangeAggregator(com.google.firebase.firestore.remote.WatchChangeAggregator) ResourcePath(com.google.firebase.firestore.model.ResourcePath) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) ImmutableSortedSet(com.google.firebase.database.collection.ImmutableSortedSet) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange)

Example 3 with WatchChangeAggregator

use of com.google.firebase.firestore.remote.WatchChangeAggregator 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)

Example 4 with WatchChangeAggregator

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

the class TestUtil method updateRemoteEvent.

public static RemoteEvent updateRemoteEvent(MutableDocument doc, List<Integer> updatedInTargets, List<Integer> removedFromTargets, List<Integer> activeTargets) {
    DocumentChange change = new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
    WatchChangeAggregator aggregator = new WatchChangeAggregator(new WatchChangeAggregator.TargetMetadataProvider() {

        @Override
        public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
            return DocumentKey.emptyKeySet().insert(doc.getKey());
        }

        @Override
        public TargetData getTargetDataForTarget(int targetId) {
            return activeTargets.contains(targetId) ? targetData(targetId, QueryPurpose.LISTEN, doc.getKey().toString()) : null;
        }
    });
    aggregator.handleDocumentChange(change);
    return aggregator.createRemoteEvent(doc.getVersion());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchChangeAggregator(com.google.firebase.firestore.remote.WatchChangeAggregator) ImmutableSortedSet(com.google.firebase.database.collection.ImmutableSortedSet) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange)

Aggregations

TargetData (com.google.firebase.firestore.local.TargetData)4 WatchChangeAggregator (com.google.firebase.firestore.remote.WatchChangeAggregator)4 ImmutableSortedSet (com.google.firebase.database.collection.ImmutableSortedSet)2 WatchChange (com.google.firebase.firestore.remote.WatchChange)2 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)2 MutableDocument (com.google.firebase.firestore.model.MutableDocument)1 ResourcePath (com.google.firebase.firestore.model.ResourcePath)1 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)1 ExistenceFilter (com.google.firebase.firestore.remote.ExistenceFilter)1