FilterAction extends Action<Query> { @Override public ActionResponse execute(Query parameter) { SearchRequestBuilder search = getRequestBuilder(parameter); try { logger.info("Search: {}", search); SearchResponse response = search.execute() .actionGet(getGetQueryTimeout()); return getResponse(response, parameter); } catch (ElasticsearchException e) { throw FoxtrotExceptions.createQueryExecutionException(parameter, e); } } FilterAction(Query parameter, AnalyticsLoader analyticsLoader); @Override void preprocess(); @Override String getMetricKey(); @Override String getRequestCacheKey(); @Override void validateImpl(Query parameter); @Override ActionResponse execute(Query parameter); @Override SearchRequestBuilder getRequestBuilder(Query parameter); @Override ActionResponse getResponse(org.elasticsearch.action.ActionResponse response, Query parameter);  }
@SuppressWarnings("deprecation") @Test public void testMissingIndicesQuery() throws FoxtrotException { final ObjectMapper mapper = getMapper(); List<Document> documents = TestUtils.getQueryDocumentsDifferentDate(mapper, new Date(2014 - 1900, 4, 1).getTime()); documents.addAll(TestUtils.getQueryDocumentsDifferentDate(mapper, new Date(2014 - 1900, 4, 5).getTime())); getQueryStore().save(TestUtils.TEST_TABLE_NAME, documents); for(Document document : documents) { getElasticsearchConnection().getClient() .admin() .indices() .prepareRefresh(ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, document.getTimestamp())) .execute() .actionGet(); } GetIndexResponse response = getElasticsearchConnection().getClient() .admin() .indices() .getIndex(new GetIndexRequest()) .actionGet(); assertEquals(3, Arrays.stream(response.getIndices()) .filter(index -> index.matches(".*-" + TestUtils.TEST_TABLE_NAME + "-.*")) .count()); Query query = new Query(); query.setLimit(documents.size()); query.setTable(TestUtils.TEST_TABLE_NAME); BetweenFilter betweenFilter = new BetweenFilter(); betweenFilter.setField("_timestamp"); betweenFilter.setFrom(documents.get(0) .getTimestamp()); betweenFilter.setTo(documents.get(documents.size() - 1) .getTimestamp()); betweenFilter.setTemporal(true); query.setFilters(Lists.<Filter>newArrayList(betweenFilter)); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); assertEquals(documents.size(), actualResponse.getDocuments() .size()); }
@Test public void testQueryNoFilterAscending() throws FoxtrotException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.asc); resultSort.setField("_timestamp"); query.setSort(resultSort); List<Document> documents = new ArrayList<>(); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper() )); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper() )); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper() )); documents.add( TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper() )); documents.add( TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper() )); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNoFilterDescending() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper() )); documents.add( TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper() )); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper() )); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper() )); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNoFilterWithLimit() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(2); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper())); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryTotalHitsWithLimit() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(2); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper())); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); assertEquals(9, actualResponse.getTotalHits()); }
@Test public void testQueryAnyFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); AnyFilter filter = new AnyFilter(); query.setFilters(Lists.<Filter>newArrayList(filter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper() )); documents.add( TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper() )); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper() )); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper() )); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryEqualsFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("ios"); query.setFilters(Lists.<Filter>newArrayList(equalsFilter)); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper())); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNotEqualsFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(3); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); NotEqualsFilter notEqualsFilter = new NotEqualsFilter(); notEqualsFilter.setField("os"); notEqualsFilter.setValue("ios"); query.setFilters(Lists.<Filter>newArrayList(notEqualsFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper())); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNotInFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(100); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); NotInFilter notInFilter = new NotInFilter(); notInFilter.setValues(Lists.newArrayList("nexus", "galaxy")); notInFilter.setField("device"); query.setFilters(Lists.<Filter>newArrayList(notInFilter)); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper())); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNotInFilterMissingField() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(100); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); NotInFilter notInFilter = new NotInFilter(); notInFilter.setValues(Lists.newArrayList("nexus", "galaxy", "ipad", "iphone")); notInFilter.setField("dummy"); query.setFilters(Lists.<Filter>newArrayList(notInFilter)); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); assertEquals(9, actualResponse.getDocuments() .size()); }
@Test public void testQueryGreaterThanFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(3); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); GreaterThanFilter greaterThanFilter = new GreaterThanFilter(); greaterThanFilter.setField("battery"); greaterThanFilter.setValue(48); query.setFilters(Lists.<Filter>newArrayList(greaterThanFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryGreaterEqualFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(3); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); GreaterEqualFilter greaterEqualFilter = new GreaterEqualFilter(); greaterEqualFilter.setField("battery"); greaterEqualFilter.setValue(48); query.setFilters(Lists.<Filter>newArrayList(greaterEqualFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryLessThanFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(3); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setField("battery"); lessThanFilter.setValue(48); query.setFilters(Lists.<Filter>newArrayList(lessThanFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryLessEqualFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(3); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); LessEqualFilter lessEqualFilter = new LessEqualFilter(); lessEqualFilter.setField("battery"); lessEqualFilter.setValue(48); query.setFilters(Lists.<Filter>newArrayList(lessEqualFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryBetweenFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setLimit(3); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); BetweenFilter betweenFilter = new BetweenFilter(); betweenFilter.setField("battery"); betweenFilter.setFrom(47); betweenFilter.setTo(75); query.setFilters(Lists.<Filter>newArrayList(betweenFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryContainsFilter() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); ContainsFilter containsFilter = new ContainsFilter(); containsFilter.setField("os"); containsFilter.setValue("*droid*"); query.setFilters(Lists.<Filter>newArrayList(containsFilter)); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper())); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryEmptyResult() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("wp8"); query.setFilters(Lists.<Filter>newArrayList(equalsFilter)); List<Document> documents = new ArrayList<Document>(); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryMultipleFiltersEmptyResult() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("android"); GreaterEqualFilter greaterEqualFilter = new GreaterEqualFilter(); greaterEqualFilter.setField("battery"); greaterEqualFilter.setValue(100); List<Filter> filters = new Vector<Filter>(); filters.add(equalsFilter); filters.add(greaterEqualFilter); query.setFilters(filters); List<Document> documents = new ArrayList<Document>(); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryMultipleFiltersAndCombiner() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("android"); GreaterEqualFilter greaterEqualFilter = new GreaterEqualFilter(); greaterEqualFilter.setField("battery"); greaterEqualFilter.setValue(98); List<Filter> filters = new Vector<Filter>(); filters.add(equalsFilter); filters.add(greaterEqualFilter); query.setFilters(filters); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryMultipleFiltersOrCombiner() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("android"); EqualsFilter equalsFilter2 = new EqualsFilter(); equalsFilter2.setField("device"); equalsFilter2.setValue("nexus"); List<Filter> filters = new Vector<Filter>(); filters.add(equalsFilter); filters.add(equalsFilter2); query.setFilters(filters); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryPagination() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("ios"); query.setFilters(Lists.<Filter>newArrayList(equalsFilter)); query.setFrom(1); query.setLimit(1); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNullFilters() throws FoxtrotException, JsonProcessingException, InterruptedException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setFilters(null); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper() )); documents.add( TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper() )); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper() )); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper() )); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper() )); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper() )); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper() )); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNullCombiner() throws FoxtrotException, JsonProcessingException, InterruptedException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setFilters(new ArrayList<>()); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); List<Document> documents = new ArrayList<Document>(); documents.add( TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper() )); documents.add( TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper() )); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper() )); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper() )); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryCaching() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.desc); resultSort.setField("_timestamp"); query.setSort(resultSort); EqualsFilter equalsFilter = new EqualsFilter(); equalsFilter.setField("os"); equalsFilter.setValue("ios"); query.setFilters(Lists.<Filter>newArrayList(equalsFilter)); query.setFrom(1); query.setLimit(1); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query)); compare(documents, actualResponse.getDocuments()); }