diff --git a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/nxql/TestCompareQueryAndFetch.java b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/nxql/TestCompareQueryAndFetch.java index 7b6f071..172583e 100644 --- a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/nxql/TestCompareQueryAndFetch.java +++ b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/nxql/TestCompareQueryAndFetch.java @@ -33,6 +33,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.nuxeo.ecm.core.api.Blobs; import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.IterableQueryResult; @@ -57,6 +58,8 @@ import org.nuxeo.runtime.transaction.TransactionHelper; import com.google.inject.Inject; +import static junit.framework.TestCase.assertEquals; + @RunWith(FeaturesRunner.class) @Features({ RepositoryElasticSearchFeature.class }) @LocalDeploy("org.nuxeo.elasticsearch.core:elasticsearch-test-contrib.xml") @@ -92,6 +95,7 @@ public class TestCompareQueryAndFetch { String name = "file" + i; DocumentModel doc = session.createDocumentModel("/", name, "File"); doc.setPropertyValue("dc:title", "File" + i); + doc.setPropertyValue("file:content", (Serializable) Blobs.createBlob("Content" + i)); doc.setPropertyValue("dc:nature", "Nature" + i); doc.setPropertyValue("dc:rights", "Rights" + i % 2); doc.setPropertyValue("dc:issued", cal); @@ -189,8 +193,30 @@ public class TestCompareQueryAndFetch { compareESAndCore("select ecm:uuid, dc:title, dc:nature from Document order by ecm:uuid"); compareESAndCore("select ecm:uuid, dc:title from Document where ecm:currentLifeCycleState != 'deleted' order by ecm:uuid"); compareESAndCore("select ecm:uuid, dc:nature from File order by dc:nature, ecm:uuid"); + compareESAndCore("select ecm:uuid, file:content/data, file:content/name, file:content/length from File order by ecm:uuid"); // TODO some timezone issues here... // compareESAndCore("select ecm:uuid, dc:issued from File order by ecm:uuid"); } + @Test + public void testPagingOffsetsAndLimits() throws Exception { + String nxql = "select ecm:uuid from File order by ecm:uuid"; + IterableQueryResult coreResult = session.queryAndFetch(nxql, NXQL.NXQL); + long size = coreResult.size(); + EsResult esRes = ess.queryAndAggregate(new NxQueryBuilder(session).nxql(nxql).limit(20)); + IterableQueryResult esResult = esRes.getRows(); + assertEquals(size, esResult.size()); + esResult.close(); + esRes = ess.queryAndAggregate(new NxQueryBuilder(session).nxql(nxql).offset( + Math.toIntExact((int) (size - 2))).limit(2)); + esResult = esRes.getRows(); + // Following assertion currently fails because EsResultSetImpl.getSize() should return either + // EsResultSetImpl.size or EsResultSetImpl.response.getHits().getHits().length + assertEquals(2, esResult.size()); + coreResult.skipTo(size - 2); + assertSameDocumentLists(coreResult, esResult); + coreResult.close(); + esResult.close(); + } + }