use of ai.grakn.client.BatchExecutorClient in project grakn by graknlabs.
the class GraknClientFake method whenQueriesFail_TheBatchExecutorClientStillCompletes.
@Test
public void whenQueriesFail_TheBatchExecutorClientStillCompletes() throws GraknClientException {
Keyspace keyspace = Keyspace.of("yes");
GraknClientFake graknClient = new GraknClientFake();
graknClient.shouldThrow(new GraknClientException("UH OH"));
// Make sure there are more queries to execute than are allowed to run at once
int maxQueries = 10;
int numQueries = 100;
BatchExecutorClient.Builder clientBuilder = BatchExecutorClient.newBuilder().taskClient(graknClient).maxQueries(maxQueries);
Set<Query<?>> queriesToExecute = IntStream.range(0, numQueries).mapToObj(this::createInsertQuery).collect(toImmutableSet());
try (BatchExecutorClient client = clientBuilder.build()) {
for (Query<?> query : queriesToExecute) {
// If we don't subscribe, the query won't execute
client.add(query, keyspace).subscribe(a -> {
});
}
}
assertThat(graknClient.queriesExecuted(), containsInAnyOrder(queriesToExecute.toArray()));
}
use of ai.grakn.client.BatchExecutorClient in project grakn by graknlabs.
the class BatchExecutorClientIT method whenSending100Queries_TheyAreSentInBatch.
@Ignore("This test interferes with other tests using the BEC (they probably use the same HystrixRequestLog)")
@Test
public void whenSending100Queries_TheyAreSentInBatch() {
List<Observable<QueryResponse>> all = new ArrayList<>();
// Increasing the max delay so eveyrthing goes in a single batch
try (BatchExecutorClient loader = loader(MAX_DELAY * 100)) {
int n = 100;
generate(this::query).limit(n).forEach(q -> all.add(loader.add(q, keyspace, true)));
int completed = allObservable(all).toBlocking().first().size();
assertEquals(n, completed);
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixCommand<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixCommand<?>[1])[0];
// assert the command is the one we're expecting
assertEquals("CommandQueries", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
// and that it was successful
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
}
use of ai.grakn.client.BatchExecutorClient in project grakn by graknlabs.
the class BatchExecutorClientIT method whenSingleQueryLoadedAndServerDown_RequestIsRetried.
@Ignore("This test stops and restart server - this is not supported yet by gRPC [https://github.com/grpc/grpc/issues/7031] - fix when gRPC 1.1 is released")
@Test
public void whenSingleQueryLoadedAndServerDown_RequestIsRetried() throws InterruptedException, IOException {
List<Observable<QueryResponse>> all = new ArrayList<>();
// Create a BatchExecutorClient with a callback that will fail
try (BatchExecutorClient loader = loader(MAX_DELAY)) {
// Engine goes down
engine.server().getHttpHandler().stopHTTP();
// Most likely the first call doesn't find the server but it's retried
generate(this::query).limit(1).forEach(q -> all.add(loader.add(q, keyspace, true)));
engine.server().getHttpHandler().startHTTP();
int completed = allObservable(all).toBlocking().first().size();
// Verify that the logger received the failed log message
assertEquals(1, completed);
}
}
use of ai.grakn.client.BatchExecutorClient in project grakn by graknlabs.
the class BatchExecutorClientIT method whenSingleQueryLoaded_TaskCompletionExecutesExactlyOnce.
@Test
public void whenSingleQueryLoaded_TaskCompletionExecutesExactlyOnce() {
List<Observable<QueryResponse>> all = new ArrayList<>();
// Create a BatchExecutorClient with a callback that will fail
try (BatchExecutorClient loader = loader(MAX_DELAY)) {
// Load some queries
generate(this::query).limit(1).forEach(q -> all.add(loader.add(q, keyspace, true)));
int completed = allObservable(all).toBlocking().first().size();
// Verify that the logger received the failed log message
assertEquals(1, completed);
}
}
use of ai.grakn.client.BatchExecutorClient in project grakn by graknlabs.
the class BatchExecutorClientIT method whenSending100InsertQueries_100EntitiesAreLoadedIntoGraph.
@Test
public void whenSending100InsertQueries_100EntitiesAreLoadedIntoGraph() {
int n = 100;
List<Observable<QueryResponse>> all = new ArrayList<>();
try (BatchExecutorClient loader = loader(MAX_DELAY)) {
generate(this::query).limit(n).forEach(q -> all.add(loader.add(q, keyspace, true)));
int completed = allObservable(all).toBlocking().first().size();
assertEquals(n, completed);
}
try (GraknTx graph = session.open(GraknTxType.READ)) {
assertEquals(n, graph.getEntityType("name_tag").instances().count());
}
}
Aggregations