Search in sources :

Example 26 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleSerializer method decodeBundleMetadata.

public BundleMetadata decodeBundleMetadata(JSONObject bundleMetadata) throws JSONException {
    String bundleId = bundleMetadata.getString("id");
    int version = bundleMetadata.getInt("version");
    SnapshotVersion createTime = decodeSnapshotVersion(bundleMetadata.get("createTime"));
    int totalDocuments = bundleMetadata.getInt("totalDocuments");
    long totalBytes = bundleMetadata.getLong("totalBytes");
    return new BundleMetadata(bundleId, version, createTime, totalDocuments, totalBytes);
}
Also used : SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) ByteString(com.google.protobuf.ByteString)

Example 27 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedBundle.

@Test
public void testReturnsSavedBundle() {
    BundleMetadata expectedBundleMetadata = new BundleMetadata("bundle-1", 1, new SnapshotVersion(Timestamp.now()), /* totalDocuments= */
    1, /* totalBytes= */
    10);
    bundleCache.saveBundleMetadata(expectedBundleMetadata);
    BundleMetadata actualBundleMetadata = bundleCache.getBundleMetadata("bundle-1");
    assertEquals(expectedBundleMetadata, actualBundleMetadata);
    // Overwrite
    expectedBundleMetadata = new BundleMetadata("bundle-1", 2, new SnapshotVersion(Timestamp.now()), /* totalDocuments= */
    1, /* totalBytes= */
    10);
    bundleCache.saveBundleMetadata(expectedBundleMetadata);
    actualBundleMetadata = bundleCache.getBundleMetadata("bundle-1");
    assertEquals(expectedBundleMetadata, actualBundleMetadata);
}
Also used : SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundleMetadata(com.google.firebase.firestore.bundle.BundleMetadata) Test(org.junit.Test)

Example 28 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedCollectionQueries.

@Test
public void testReturnsSavedCollectionQueries() {
    Target target = new Target(path("room"), /* collectionGroup= */
    null, Collections.emptyList(), Collections.emptyList(), Target.NO_LIMIT, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 29 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleCacheTestCase method testReturnsSavedCollectionGroupQueries.

@Test
public void testReturnsSavedCollectionGroupQueries() {
    Target target = new Target(ResourcePath.EMPTY, /* collectionGroup= */
    "collectionGroup", Collections.emptyList(), Collections.emptyList(), /* limit= */
    1, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 30 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class CountingQueryEngine method wrapRemoteDocumentCache.

private RemoteDocumentCache wrapRemoteDocumentCache(RemoteDocumentCache subject) {
    return new RemoteDocumentCache() {

        @Override
        public void setIndexManager(IndexManager indexManager) {
        // Not implemented.
        }

        @Override
        public void add(MutableDocument document, SnapshotVersion readTime) {
            subject.add(document, readTime);
        }

        @Override
        public void removeAll(Collection<DocumentKey> keys) {
            subject.removeAll(keys);
        }

        @Override
        public MutableDocument get(DocumentKey documentKey) {
            MutableDocument result = subject.get(documentKey);
            documentsReadByKey[0] += result.isValidDocument() ? 1 : 0;
            return result;
        }

        @Override
        public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKeys) {
            Map<DocumentKey, MutableDocument> result = subject.getAll(documentKeys);
            for (MutableDocument document : result.values()) {
                documentsReadByKey[0] += document.isValidDocument() ? 1 : 0;
            }
            return result;
        }

        @Override
        public Map<DocumentKey, MutableDocument> getAll(String collectionGroup, IndexOffset offset, int limit) {
            Map<DocumentKey, MutableDocument> result = subject.getAll(collectionGroup, offset, limit);
            documentsReadByCollection[0] += result.size();
            return result;
        }

        @Override
        public Map<DocumentKey, MutableDocument> getAll(ResourcePath collection, IndexOffset offset) {
            Map<DocumentKey, MutableDocument> result = subject.getAll(collection, offset);
            documentsReadByCollection[0] += result.size();
            return result;
        }
    };
}
Also used : ResourcePath(com.google.firebase.firestore.model.ResourcePath) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Collection(java.util.Collection) IndexOffset(com.google.firebase.firestore.model.FieldIndex.IndexOffset)

Aggregations

SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)43 DocumentKey (com.google.firebase.firestore.model.DocumentKey)16 Test (org.junit.Test)13 MutableDocument (com.google.firebase.firestore.model.MutableDocument)9 Target (com.google.firebase.firestore.core.Target)8 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)7 ByteString (com.google.protobuf.ByteString)7 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)6 ArrayList (java.util.ArrayList)6 Timestamp (com.google.firebase.Timestamp)5 ObjectValue (com.google.firebase.firestore.model.ObjectValue)5 MutationResult (com.google.firebase.firestore.model.mutation.MutationResult)4 JSONObject (org.json.JSONObject)4 Query (com.google.firebase.firestore.core.Query)3 Timestamp (com.google.protobuf.Timestamp)3 ResourcePath (com.google.firebase.firestore.model.ResourcePath)2 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)2 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)2 ExistenceFilterWatchChange (com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange)2 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)2