@Test
public void testCountQuery() throws Throwable {

    int numberOfServices = 20;
    this.services = this.host.doThroughputServiceStart(numberOfServices,
            MinimalTestService.class,
            this.host.buildMinimalTestState(), EnumSet.of(ServiceOption.PERSISTENCE), null);
    Query query = Builder.create().addKindFieldClause(MinimalTestServiceState.class).build();
    QueryTask q = QueryTask.Builder.createDirectTask()
            .addOption(QueryOption.COUNT)
            .setQuery(query).build();
    List<Long> results = new ArrayList<>();
    query(q, (r, e) -> {
        if (e != null) {
            this.host.failIteration(e);
        } else if (!r.hasResult()) {
            this.host.completeIteration();
        } else {
            results.add(r.getCount());
        }
    });
    assertEquals(1, results.size());
    assertEquals(20, results.get(0).intValue());
}