use of ai.grakn.Keyspace 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.Keyspace in project grakn by graknlabs.
the class PostProcessingTest method whenUpdatingInstanceCounts_EnsureRedisIsUpdated.
@Test
public void whenUpdatingInstanceCounts_EnsureRedisIsUpdated() throws InterruptedException {
RedisCountStorage redis = engine.redis();
Keyspace keyspace = SampleKBLoader.randomKeyspace();
String entityType1 = "e1";
String entityType2 = "e2";
// Create Artificial configuration
createAndUploadCountCommitLog(keyspace, ConceptId.of(entityType1), 6L);
createAndUploadCountCommitLog(keyspace, ConceptId.of(entityType2), 3L);
// Check cache in redis has been updated
assertEquals(6L, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace, ConceptId.of(entityType1))));
assertEquals(3L, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace, ConceptId.of(entityType2))));
// Create Artificial configuration
createAndUploadCountCommitLog(keyspace, ConceptId.of(entityType1), 1L);
createAndUploadCountCommitLog(keyspace, ConceptId.of(entityType2), -1L);
// Check cache in redis has been updated
assertEquals(7L, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace, ConceptId.of(entityType1))));
assertEquals(2L, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace, ConceptId.of(entityType2))));
}
use of ai.grakn.Keyspace in project grakn by graknlabs.
the class PostProcessingTest method whenShardingThresholdIsBreached_ShardTypes.
@Test
public void whenShardingThresholdIsBreached_ShardTypes() {
Keyspace keyspace = SampleKBLoader.randomKeyspace();
EntityType et1;
EntityType et2;
// Create Simple GraknTx
try (EmbeddedGraknTx<?> graknTx = EmbeddedGraknSession.create(keyspace, engine.uri().toString()).open(GraknTxType.WRITE)) {
et1 = graknTx.putEntityType("et1");
et2 = graknTx.putEntityType("et2");
graknTx.commitSubmitNoLogs();
}
checkShardCount(keyspace, et1, 1);
checkShardCount(keyspace, et2, 1);
// Add new counts
createAndUploadCountCommitLog(keyspace, et1.getId(), 99_999L);
createAndUploadCountCommitLog(keyspace, et2.getId(), 99_999L);
checkShardCount(keyspace, et1, 1);
checkShardCount(keyspace, et2, 1);
// Add new counts
createAndUploadCountCommitLog(keyspace, et1.getId(), 2L);
createAndUploadCountCommitLog(keyspace, et2.getId(), 1L);
checkShardCount(keyspace, et1, 2);
checkShardCount(keyspace, et2, 1);
}
use of ai.grakn.Keyspace in project grakn by graknlabs.
the class EngineContext method clearGraphs.
private static void clearGraphs(EngineGraknTxFactory factory) {
// Drop all keyspaces
final Set<String> keyspaceNames = new HashSet<String>();
try (GraknTx systemGraph = factory.tx(GraknKeyspaceStore.SYSTEM_KB_KEYSPACE, GraknTxType.WRITE)) {
systemGraph.graql().match(var("x").isa("keyspace-name")).forEach(x -> x.concepts().forEach(y -> {
keyspaceNames.add(y.asAttribute().getValue().toString());
}));
}
keyspaceNames.forEach(name -> {
GraknTx graph = factory.tx(Keyspace.of(name), GraknTxType.WRITE);
graph.admin().delete();
});
factory.refreshConnections();
}
use of ai.grakn.Keyspace in project grakn by graknlabs.
the class ConceptController method getConceptById.
private String getConceptById(Request request, Response response) throws JsonProcessingException {
Requests.validateRequest(request, APPLICATION_ALL, APPLICATION_JSON);
Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
ConceptId conceptId = ConceptId.of(mandatoryPathParameter(request, ID_PARAMETER));
return getConcept(response, keyspace, (tx) -> tx.getConcept(conceptId));
}
Aggregations