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);
}
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);
}
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);
}
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);
}
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;
}
};
}
Aggregations