Search in sources :

Example 11 with SnapshotVersion

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);
}
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 12 with SnapshotVersion

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);
}
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 13 with SnapshotVersion

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);
}
Also used : Target(com.google.firebase.firestore.core.Target) JSONObject(org.json.JSONObject) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) Timestamp(com.google.protobuf.Timestamp)

Example 14 with SnapshotVersion

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();
}
Also used : Query(com.google.firebase.firestore.core.Query) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) Timestamp(com.google.firebase.Timestamp) Test(org.junit.Test)

Example 15 with SnapshotVersion

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);
}
Also used : SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

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