Search in sources :

Example 1 with Target

use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.

the class LocalSerializer method encodeTargetData.

com.google.firebase.firestore.proto.Target encodeTargetData(TargetData targetData) {
    hardAssert(QueryPurpose.LISTEN.equals(targetData.getPurpose()), "Only queries with purpose %s may be stored, got %s", QueryPurpose.LISTEN, targetData.getPurpose());
    com.google.firebase.firestore.proto.Target.Builder result = com.google.firebase.firestore.proto.Target.newBuilder();
    result.setTargetId(targetData.getTargetId()).setLastListenSequenceNumber(targetData.getSequenceNumber()).setLastLimboFreeSnapshotVersion(rpcSerializer.encodeVersion(targetData.getLastLimboFreeSnapshotVersion())).setSnapshotVersion(rpcSerializer.encodeVersion(targetData.getSnapshotVersion())).setResumeToken(targetData.getResumeToken());
    Target target = targetData.getTarget();
    if (target.isDocumentQuery()) {
        result.setDocuments(rpcSerializer.encodeDocumentsTarget(target));
    } else {
        result.setQuery(rpcSerializer.encodeQueryTarget(target));
    }
    return result.build();
}
Also used : Target(com.google.firebase.firestore.core.Target)

Example 2 with Target

use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.

the class LocalSerializer method decodeTargetData.

TargetData decodeTargetData(com.google.firebase.firestore.proto.Target targetProto) {
    int targetId = targetProto.getTargetId();
    SnapshotVersion version = rpcSerializer.decodeVersion(targetProto.getSnapshotVersion());
    SnapshotVersion lastLimboFreeSnapshotVersion = rpcSerializer.decodeVersion(targetProto.getLastLimboFreeSnapshotVersion());
    ByteString resumeToken = targetProto.getResumeToken();
    long sequenceNumber = targetProto.getLastListenSequenceNumber();
    Target target;
    switch(targetProto.getTargetTypeCase()) {
        case DOCUMENTS:
            target = rpcSerializer.decodeDocumentsTarget(targetProto.getDocuments());
            break;
        case QUERY:
            target = rpcSerializer.decodeQueryTarget(targetProto.getQuery());
            break;
        default:
            throw fail("Unknown targetType %d", targetProto.getTargetTypeCase());
    }
    return new TargetData(target, targetId, sequenceNumber, QueryPurpose.LISTEN, version, lastLimboFreeSnapshotVersion, resumeToken);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) ByteString(com.google.protobuf.ByteString)

Example 3 with Target

use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.

the class SQLiteIndexManagerTest method verifyResults.

private void verifyResults(Query query, String... documents) {
    Target target = query.toTarget();
    Iterable<DocumentKey> results = indexManager.getDocumentsMatchingTarget(target);
    assertNotNull("Target cannot be served from index.", results);
    List<DocumentKey> keys = Arrays.stream(documents).map(s -> key(s)).collect(Collectors.toList());
    assertWithMessage("Result for %s", query).that(results).containsExactlyElementsIn(keys);
}
Also used : IndexOffset(com.google.firebase.firestore.model.FieldIndex.IndexOffset) Arrays(java.util.Arrays) TestUtil.fieldIndex(com.google.firebase.firestore.testutil.TestUtil.fieldIndex) IndexState(com.google.firebase.firestore.model.FieldIndex.IndexState) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Kind(com.google.firebase.firestore.model.FieldIndex.Segment.Kind) TestUtil.filter(com.google.firebase.firestore.testutil.TestUtil.filter) TestUtil.bound(com.google.firebase.firestore.testutil.TestUtil.bound) TestUtil.query(com.google.firebase.firestore.testutil.TestUtil.query) ArrayList(java.util.ArrayList) TestUtil.wrap(com.google.firebase.firestore.testutil.TestUtil.wrap) Values(com.google.firebase.firestore.model.Values) TestUtil.doc(com.google.firebase.firestore.testutil.TestUtil.doc) Map(java.util.Map) TestUtil.docMap(com.google.firebase.firestore.testutil.TestUtil.docMap) Document(com.google.firebase.firestore.model.Document) Iterator(java.util.Iterator) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Assert.assertNotNull(org.junit.Assert.assertNotNull) User(com.google.firebase.firestore.auth.User) Collection(java.util.Collection) TestUtil.deletedDoc(com.google.firebase.firestore.testutil.TestUtil.deletedDoc) Target(com.google.firebase.firestore.core.Target) Test(org.junit.Test) Collectors(java.util.stream.Collectors) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) TestUtil.path(com.google.firebase.firestore.testutil.TestUtil.path) List(java.util.List) TestUtil.version(com.google.firebase.firestore.testutil.TestUtil.version) Assert.assertNull(org.junit.Assert.assertNull) FieldIndex(com.google.firebase.firestore.model.FieldIndex) Filter(com.google.firebase.firestore.core.Filter) TestUtil.map(com.google.firebase.firestore.testutil.TestUtil.map) TestUtil.key(com.google.firebase.firestore.testutil.TestUtil.key) Collections(java.util.Collections) TestUtil.orderBy(com.google.firebase.firestore.testutil.TestUtil.orderBy) Assert.assertEquals(org.junit.Assert.assertEquals) DocumentKey(com.google.firebase.firestore.model.DocumentKey) Query(com.google.firebase.firestore.core.Query) Target(com.google.firebase.firestore.core.Target) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Example 4 with Target

use of com.google.firebase.firestore.core.Target 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 5 with Target

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

Aggregations

Target (com.google.firebase.firestore.core.Target)23 Test (org.junit.Test)14 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)11 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)8 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)7 DocumentKey (com.google.firebase.firestore.model.DocumentKey)5 Filter (com.google.firebase.firestore.core.Filter)3 Query (com.google.firebase.firestore.core.Query)3 ArrayList (java.util.ArrayList)3 Nullable (androidx.annotation.Nullable)2 Bound (com.google.firebase.firestore.core.Bound)2 FieldFilter (com.google.firebase.firestore.core.FieldFilter)2 FieldIndex (com.google.firebase.firestore.model.FieldIndex)2 ByteString (com.google.protobuf.ByteString)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 User (com.google.firebase.firestore.auth.User)1 CompositeFilter (com.google.firebase.firestore.core.CompositeFilter)1 OrderBy (com.google.firebase.firestore.core.OrderBy)1 LimitType (com.google.firebase.firestore.core.Query.LimitType)1 TargetData (com.google.firebase.firestore.local.TargetData)1