.addOption(QueryOption.EXPAND_CONTENT) .setQuery(qs) .orderAscending(ServiceDocument.FIELD_NAME_VERSION, TypeName.LONG) .build();
.addOption(QueryOption.EXPAND_CONTENT) .setQuery(qs) .orderAscending(ServiceDocument.FIELD_NAME_VERSION, TypeName.LONG) .build();
.addOption(QueryOption.EXPAND_CONTENT) .setQuery(qs) .orderAscending(ServiceDocument.FIELD_NAME_VERSION, TypeName.LONG) .build();
.addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build();
.orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .setQuery(query).build(); post = Operation.createPost(queryFactoryURI) .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.COUNT) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.CONTINUOUS) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build();
.orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .setQuery(query).build(); post = Operation.createPost(queryFactoryURI) .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.COUNT) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.CONTINUOUS) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build();
@Test public void testServiceWithMappedFieldName() throws Throwable { setUpHost(); // Issue a query for documents which don't exist. Query query = Query.Builder.create() .addFieldClause(ServiceWithMappedFieldName.FIELD_NAME_DEFAULT, "a special string value") .addKindFieldClause(ServiceWithMappedFieldName.State.class) .build(); QueryTask queryTask = QueryTask.Builder.createDirectTask() .orderAscending(ServiceWithMappedFieldName.FIELD_NAME_DEFAULT, TypeName.STRING) .setQuery(query).build(); this.host.createQueryTaskService(queryTask, false, true, queryTask, null); assertEquals(0, (long) queryTask.results.documentCount); // Now create some documents of the expected type, re-issue the same query once again, and // verify that the newly-created documents are sorted correctly in the results ServiceWithMappedFieldName.State initialState1 = new ServiceWithMappedFieldName.State(); initialState1._default = "a special string value"; this.host.doThroughputServiceStart(this.serviceCount, ServiceWithMappedFieldName.class, initialState1, null, null); queryTask = QueryTask.Builder.createDirectTask() .orderAscending(ServiceWithMappedFieldName.FIELD_NAME_DEFAULT, TypeName.STRING) .setQuery(query).build(); this.host.createQueryTaskService(queryTask, false, true, queryTask, null); assertEquals(this.serviceCount, (long) queryTask.results.documentCount); }
@Test public void testServiceWithMappedFieldName() throws Throwable { setUpHost(); // Issue a query for documents which don't exist. Query query = Query.Builder.create() .addFieldClause(ServiceWithMappedFieldName.FIELD_NAME_DEFAULT, "a special string value") .addKindFieldClause(ServiceWithMappedFieldName.State.class) .build(); QueryTask queryTask = QueryTask.Builder.createDirectTask() .orderAscending(ServiceWithMappedFieldName.FIELD_NAME_DEFAULT, TypeName.STRING) .setQuery(query).build(); this.host.createQueryTaskService(queryTask, false, true, queryTask, null); assertEquals(0, (long) queryTask.results.documentCount); // Now create some documents of the expected type, re-issue the same query once again, and // verify that the newly-created documents are sorted correctly in the results ServiceWithMappedFieldName.State initialState1 = new ServiceWithMappedFieldName.State(); initialState1._default = "a special string value"; this.host.doThroughputServiceStart(this.serviceCount, ServiceWithMappedFieldName.class, initialState1, null, null); queryTask = QueryTask.Builder.createDirectTask() .orderAscending(ServiceWithMappedFieldName.FIELD_NAME_DEFAULT, TypeName.STRING) .setQuery(query).build(); this.host.createQueryTaskService(queryTask, false, true, queryTask, null); assertEquals(this.serviceCount, (long) queryTask.results.documentCount); }
private void verifyGroupQueryAfterDeletion(VerificationHost targetHost, List<String> groups, Map<String, ServiceDocumentQueryResult> resultsPerGroup) throws Throwable { String groupToDelete = groups.get(0); ServiceDocumentQueryResult resultsToDelete = resultsPerGroup.get(groupToDelete); TestContext ctx = this.host.testCreate(resultsToDelete.documentLinks.size()); for (String link : resultsToDelete.documentLinks) { Operation delete = Operation.createDelete(targetHost, link) .setCompletion(ctx.getCompletion()); this.host.send(delete); } this.host.testWait(ctx); Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); validateGroupByResults(targetHost, groups, groupToDelete, finalState, null, this.serviceCount); }
private void verifyGroupQueryAfterDeletion(VerificationHost targetHost, List<String> groups, Map<String, ServiceDocumentQueryResult> resultsPerGroup) throws Throwable { String groupToDelete = groups.get(0); ServiceDocumentQueryResult resultsToDelete = resultsPerGroup.get(groupToDelete); TestContext ctx = this.host.testCreate(resultsToDelete.documentLinks.size()); for (String link : resultsToDelete.documentLinks) { Operation delete = Operation.createDelete(targetHost, link) .setCompletion(ctx.getCompletion()); this.host.send(delete); } this.host.testWait(ctx); Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); validateGroupByResults(targetHost, groups, groupToDelete, finalState, null, this.serviceCount); }
private void verifyGroupQueryPaginatedAcrossGroups(VerificationHost targetHost, List<String> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); // two pagination across two dimensions: number of groups, and documents per group QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .setGroupResultLimit(2) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
private static void handlePostCompletion(ServiceHost host, Map<Long, Throwable> exs) { if (exs != null && !exs.isEmpty()) { host.log(Level.SEVERE, "Failed to start services: %s", Utils.toString(exs)); return; } QueryTask.Query query = QueryTask.Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .addFieldClause(ExampleServiceState.FIELD_NAME_NAME, "Bernard", QueryTask.Query.Occurance.MUST_NOT_OCCUR) .build(); QueryTask queryTask = QueryTask.Builder.createDirectTask() .setQuery(query) .addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT) .orderAscending(ExampleServiceState.FIELD_NAME_SORTED_COUNTER, ServiceDocumentDescription.TypeName.LONG) .build(); Operation post = Operation.createPost(host, ServiceUriPaths.CORE_QUERY_TASKS) .setBody(queryTask) .setReferer(host.getUri()) .setCompletion((o, e) -> handleQueryCompletion(host, o, e)); host.sendRequest(post); }
private void verifyNumericGroupQueryPaginatedAcrossGroups(VerificationHost targetHost, List<Long> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); // two pagination across two dimensions: number of groups, and documents per group QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .setGroupResultLimit(2) .orderAscending(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_SORTED_COUNTER, TypeName.LONG, SortOrder.DESC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateNumericGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
private void verifyGroupQueryPaginatedAcrossGroups(VerificationHost targetHost, List<String> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); // two pagination across two dimensions: number of groups, and documents per group QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .setGroupResultLimit(2) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
@Test public void maxExpirationTimeForGroupByQuery() throws Throwable { setUpHost(false); Query query = Query.Builder.create() .addFieldClause(ServiceDocument.FIELD_NAME_KIND, Utils.buildKind(ExampleServiceState.class)) .build(); // create a group by paginated query with MAX expiration time QueryTask queryTask = QueryTask.Builder.createDirectTask() .addOption(QueryOption.GROUP_BY) .setGroupResultLimit(10) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); queryTask.documentExpirationTimeMicros = Long.MAX_VALUE; this.host.createQueryTaskService(queryTask, false, true, queryTask, null); assertThat(this.indexService.getPaginatedSearchersByExpirationTime()) .hasSize(1) .containsOnlyKeys(Long.MAX_VALUE); }
private void verifyNumericGroupQueryPaginatedAcrossGroups(VerificationHost targetHost, List<Long> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); // two pagination across two dimensions: number of groups, and documents per group QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .setGroupResultLimit(2) .orderAscending(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_SORTED_COUNTER, TypeName.LONG, SortOrder.DESC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateNumericGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
private void verifyNumericGroupQueryPaginatedPerGroup(VerificationHost targetHost, List<Long> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .orderAscending(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_SORTED_COUNTER, TypeName.LONG, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateNumericGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
private void verifyGroupQueryPaginatedPerGroup(VerificationHost targetHost, List<String> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
private void verifyNumericGroupQueryPaginatedPerGroup(VerificationHost targetHost, List<Long> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .orderAscending(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_SORTED_COUNTER, TypeName.LONG, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateNumericGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }
private void verifyGroupQueryPaginatedPerGroup(VerificationHost targetHost, List<String> groups) throws Throwable { Query query = Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .build(); QueryTask queryTask = QueryTask.Builder.create() .addOption(QueryOption.GROUP_BY) .addOption(QueryOption.EXPAND_CONTENT) .setResultLimit(this.serviceCount / 5) .orderAscending(ExampleServiceState.FIELD_NAME_ID, TypeName.STRING) .groupOrder(ExampleServiceState.FIELD_NAME_NAME, TypeName.STRING, SortOrder.ASC) .setQuery(query).build(); URI queryTaskURI = this.host.createQueryTaskService(queryTask); QueryTask finalState = this.host.waitForQueryTask(queryTaskURI, TaskStage.FINISHED); int expectedCountPerPage = queryTask.querySpec.resultLimit; validateGroupByResults(targetHost, groups, null, finalState, null, expectedCountPerPage); }