FilterAction extends Action<Query> { @Override public QueryResponse execute(Query parameter) throws QueryStoreException { parameter.setTable(ElasticsearchUtils.getValidTableName(parameter.getTable())); if (null == parameter.getFilters() || parameter.getFilters().isEmpty()) { parameter.setFilters(Lists.<Filter>newArrayList(new AnyFilter(parameter.getTable()))); } if (null == parameter.getSort()) { ResultSort resultSort = new ResultSort(); resultSort.setField("_timestamp"); resultSort.setOrder(ResultSort.Order.desc); parameter.setSort(resultSort); } SearchRequestBuilder search = null; SearchResponse response; try { search = getConnection().getClient().prepareSearch(ElasticsearchUtils.getIndices(parameter.getTable(), parameter)) .setTypes(ElasticsearchUtils.TYPE_NAME) .setQuery(new ElasticSearchQueryGenerator(FilterCombinerType.and).genFilter(parameter.getFilters())) .setSearchType(SearchType.QUERY_THEN_FETCH) .setFrom(parameter.getFrom()) .setSize(parameter.getLimit()); search.addSort(parameter.getSort().getField(), ResultSort.Order.desc == parameter.getSort().getOrder() ? SortOrder.DESC : SortOrder.ASC); response = search.execute().actionGet(); Vector<String> ids = new Vector<String>(); for (SearchHit searchHit : response.getHits()) { ids.add(searchHit.getId()); } if (ids.isEmpty()) { return new QueryResponse(Collections.<Document>emptyList()); } return new QueryResponse(getQueryStore().get(parameter.getTable(), ids)); } catch (Exception e) { if (null != search) { logger.error("Error running generated query: " + search, e); } else { logger.error("Query generation error: ", e); } throw new QueryStoreException(QueryStoreException.ErrorCode.QUERY_EXECUTION_ERROR, "Error running query: " + parameter.toString()); } } FilterAction(Query parameter,
                        TableMetadataManager tableMetadataManager,
                        DataStore dataStore,
                        QueryStore queryStore,
                        ElasticsearchConnection connection,
                        String cacheToken); @Override QueryResponse execute(Query parameter);  }
@Test(expected = QueryStoreException.class) public void testQueryException() throws QueryStoreException, JsonProcessingException { 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); when(elasticsearchServer.getClient()).thenReturn(null); queryExecutor.execute(query); }
@Test public void testQueryNoFilterAscending() throws QueryStoreException, JsonProcessingException { 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<Document>(); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNoFilterDescending() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNoFilterWithLimit() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryAnyFilter() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryEqualsFilter() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNotEqualsFilter() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryGreaterThanFilter() throws QueryStoreException, 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}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryGreaterEqualFilter() throws QueryStoreException, 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}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryLessThanFilter() throws QueryStoreException, 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}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryLessEqualFilter() throws QueryStoreException, 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}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryBetweenFilter() throws QueryStoreException, 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}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryContainsFilter() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryEmptyResult() throws QueryStoreException, 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(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryMultipleFiltersEmptyResult() throws QueryStoreException, 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(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryMultipleFiltersAndCombiner() throws QueryStoreException, 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}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Ignore @Test public void testQueryMultipleFiltersOrCombiner() throws QueryStoreException, 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"); 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("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); }
@Test public void testQueryPagination() throws QueryStoreException, 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"}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNullFilters() throws QueryStoreException, 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"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Ignore @Test public void testQueryNullCombiner() throws QueryStoreException, JsonProcessingException, InterruptedException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setFilters(new ArrayList<Filter>()); 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"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryNullSort() throws QueryStoreException, JsonProcessingException, InterruptedException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); query.setFilters(new ArrayList<Filter>()); query.setSort(null); List<Document> documents = new ArrayList<Document>(); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, mapper)); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, mapper)); documents.add(TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, mapper)); documents.add(TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, mapper)); documents.add(TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, mapper)); documents.add(TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, mapper)); documents.add(TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, mapper)); documents.add(TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }
@Test public void testQueryCaching() throws QueryStoreException, 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"}, mapper)); QueryResponse actualResponse = QueryResponse.class.cast(queryExecutor.execute(query)); compare(documents, actualResponse.getDocuments()); }