Search in sources :

Example 21 with Query

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

the class SQLiteIndexManagerTest method testArrayContainsFilter.

@Test
public void testArrayContainsFilter() {
    setUpArrayValueFilter();
    Query query = query("coll").filter(filter("values", "array-contains", 1));
    verifyResults(query, "coll/arr1");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 22 with Query

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

the class SQLiteIndexManagerTest method testGreaterThanOrEqualsFilter.

@Test
public void testGreaterThanOrEqualsFilter() {
    setUpSingleValueFilter();
    Query query = query("coll").filter(filter("count", ">=", 2));
    verifyResults(query, "coll/val2", "coll/val3");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 23 with Query

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

the class SQLiteIndexManagerTest method testNoMatchingFilter.

@Test
public void testNoMatchingFilter() {
    setUpSingleValueFilter();
    Query query = query("coll").filter(filter("unknown", "==", true));
    assertNull(indexManager.getFieldIndex(query.toTarget()));
    assertNull(indexManager.getDocumentsMatchingTarget(query.toTarget()));
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 24 with Query

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

the class SQLiteIndexManagerTest method testLessThanOrEqualsFilter.

@Test
public void testLessThanOrEqualsFilter() {
    setUpSingleValueFilter();
    Query query = query("coll").filter(filter("count", "<=", 2));
    verifyResults(query, "coll/val1", "coll/val2");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 25 with Query

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

Aggregations

Query (com.google.firebase.firestore.core.Query)189 Test (org.junit.Test)179 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)40 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)39 StructuredQuery (com.google.firestore.v1.StructuredQuery)16 Target (com.google.firestore.v1.Target)13 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)13 QueryTarget (com.google.firestore.v1.Target.QueryTarget)13 DocumentSet (com.google.firebase.firestore.model.DocumentSet)12 MutableDocument (com.google.firebase.firestore.model.MutableDocument)8 ArrayList (java.util.ArrayList)8 TargetData (com.google.firebase.firestore.local.TargetData)7 FieldIndex (com.google.firebase.firestore.model.FieldIndex)7 DocumentKey (com.google.firebase.firestore.model.DocumentKey)6 ByteString (com.google.protobuf.ByteString)5 Document (com.google.firebase.firestore.model.Document)4 HashMap (java.util.HashMap)4 Target (com.google.firebase.firestore.core.Target)3 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)3 Map (java.util.Map)3