use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class BundleCacheTestCase method testReturnsSavedLimitToLastQueries.
@Test
public void testReturnsSavedLimitToLastQueries() {
Target target = new Target(path("room"), /* collectionGroup= */
null, Collections.emptyList(), Collections.emptyList(), /* limit= */
1, /* startAt= */
null, /* endAt= */
null);
BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST);
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 testReturnsSavedLimitToFirstQueries.
@Test
public void testReturnsSavedLimitToFirstQueries() {
Target target = new Target(path("room"), /* collectionGroup= */
null, 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 BundleSerializerTest method assertDecodesNamedQuery.
private void assertDecodesNamedQuery(String json, Query query) throws JSONException {
String queryJson = "{\n" + " name: 'query-1',\n" + " bundledQuery: {\n" + " parent: '" + TEST_PROJECT + "',\n" + " structuredQuery:\n" + json + ",\n" + " limitType: '" + (query.getLimitType().equals(Query.LimitType.LIMIT_TO_LAST) ? "LAST" : "FIRST") + "'\n" + " },\n" + " readTime: '2020-01-01T00:00:01.000000001Z'\n" + "}";
NamedQuery actualNamedQuery = serializer.decodeNamedQuery(new JSONObject(queryJson));
Target target = new Target(query.getPath(), query.getCollectionGroup(), query.getFilters(), query.getExplicitOrderBy(), query.getLimit(), query.getStartAt(), query.getEndAt());
BundledQuery bundledQuery = new BundledQuery(target, query.getLimitType().equals(Query.LimitType.LIMIT_TO_LAST) ? Query.LimitType.LIMIT_TO_LAST : Query.LimitType.LIMIT_TO_FIRST);
NamedQuery expectedNamedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(new com.google.firebase.Timestamp(1577836801, 1)));
assertEquals(expectedNamedQuery, actualNamedQuery);
}
use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class SQLiteTargetCacheTest method testMetadataPersistedAcrossRestarts.
@Test
public void testMetadataPersistedAcrossRestarts() {
String name = "test-targetCache-restarts";
SQLitePersistence db1 = PersistenceTestHelpers.createSQLitePersistence(name);
TargetCache targetCache1 = db1.getTargetCache();
assertEquals(0, targetCache1.getHighestListenSequenceNumber());
long originalSequenceNumber = 1234;
int targetId = 5;
SnapshotVersion snapshotVersion = new SnapshotVersion(new Timestamp(1, 2));
Query query = query("rooms");
TargetData targetData = new TargetData(query.toTarget(), targetId, originalSequenceNumber, QueryPurpose.LISTEN);
db1.runTransaction("add query data", () -> {
targetCache1.addTargetData(targetData);
targetCache1.setLastRemoteSnapshotVersion(snapshotVersion);
});
db1.shutdown();
SQLitePersistence db2 = PersistenceTestHelpers.createSQLitePersistence(name);
db2.runTransaction("verify sequence number", () -> {
long newSequenceNumber = db2.getReferenceDelegate().getCurrentSequenceNumber();
assertTrue(newSequenceNumber > originalSequenceNumber);
});
TargetCache targetCache2 = db2.getTargetCache();
assertEquals(targetId, targetCache2.getHighestTargetId());
assertEquals(snapshotVersion, targetCache2.getLastRemoteSnapshotVersion());
assertEquals(1, targetCache2.getTargetCount());
db2.shutdown();
}
use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeMissingDocument.
private MutableDocument decodeMissingDocument(BatchGetDocumentsResponse response) {
Assert.hardAssert(response.getResultCase().equals(ResultCase.MISSING), "Tried to deserialize a missing document from a found document.");
DocumentKey key = decodeKey(response.getMissing());
SnapshotVersion version = decodeVersion(response.getReadTime());
hardAssert(!version.equals(SnapshotVersion.NONE), "Got a no document response with no snapshot version");
return MutableDocument.newNoDocument(key, version);
}
Aggregations