Search in sources :

Example 1 with Keyspace

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()));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Query(ai.grakn.graql.Query) Keyspace(ai.grakn.Keyspace) BatchExecutorClient(ai.grakn.client.BatchExecutorClient) GraknClientException(ai.grakn.client.GraknClientException) Test(org.junit.Test)

Example 2 with Keyspace

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))));
}
Also used : RedisCountStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage) Keyspace(ai.grakn.Keyspace) Test(org.junit.Test)

Example 3 with Keyspace

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);
}
Also used : EntityType(ai.grakn.concept.EntityType) Keyspace(ai.grakn.Keyspace) Test(org.junit.Test)

Example 4 with Keyspace

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();
}
Also used : Keyspace(ai.grakn.Keyspace) LoggerFactory(org.slf4j.LoggerFactory) RedisSanityCheck(ai.grakn.engine.data.RedisSanityCheck) EngineGraknTxFactory(ai.grakn.engine.factory.EngineGraknTxFactory) GraknConfig(ai.grakn.engine.GraknConfig) CountStorage(ai.grakn.engine.task.postprocessing.CountStorage) GraknTx(ai.grakn.GraknTx) RedisWrapper(ai.grakn.engine.data.RedisWrapper) JedisLockProvider(ai.grakn.engine.lock.JedisLockProvider) JedisPool(redis.clients.jedis.JedisPool) RedisCountStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage) GraknTxType(ai.grakn.GraknTxType) Graql.var(ai.grakn.graql.Graql.var) GraknKeyspaceStoreImpl(ai.grakn.engine.GraknKeyspaceStoreImpl) GraknKeyspaceStore(ai.grakn.engine.GraknKeyspaceStore) Set(java.util.Set) GrpcOpenRequestExecutorImpl(ai.grakn.engine.rpc.GrpcOpenRequestExecutorImpl) GraknConfigKey(ai.grakn.GraknConfigKey) IndexPostProcessor(ai.grakn.engine.task.postprocessing.IndexPostProcessor) IndexStorage(ai.grakn.engine.task.postprocessing.IndexStorage) List(java.util.List) ExceptionUtils.getFullStackTrace(org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace) GraknEngineServer(ai.grakn.engine.GraknEngineServer) RedisIndexStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisIndexStorage) RestAssured(com.jayway.restassured.RestAssured) GraknEngineStatus(ai.grakn.engine.GraknEngineStatus) SimpleURI(ai.grakn.util.SimpleURI) Iterables(com.google.common.collect.Iterables) GraknTestUtil(ai.grakn.util.GraknTestUtil) TestRule(org.junit.rules.TestRule) CountPostProcessor(ai.grakn.engine.task.postprocessing.CountPostProcessor) GrpcOpenRequestExecutor(ai.grakn.grpc.GrpcOpenRequestExecutor) LockProvider(ai.grakn.engine.lock.LockProvider) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) ServerBuilder(io.grpc.ServerBuilder) Server(io.grpc.Server) GrpcServer(ai.grakn.engine.rpc.GrpcServer) MetricRegistry(com.codahale.metrics.MetricRegistry) GraknEngineServerFactory(ai.grakn.engine.GraknEngineServerFactory) IOException(java.io.IOException) PostProcessor(ai.grakn.engine.task.postprocessing.PostProcessor) GraknSystemKeyspaceSession(ai.grakn.engine.GraknSystemKeyspaceSession) QueueSanityCheck(ai.grakn.engine.data.QueueSanityCheck) EmbeddedGraknSession(ai.grakn.factory.EmbeddedGraknSession) SampleKBLoader.randomKeyspace(ai.grakn.util.SampleKBLoader.randomKeyspace) GrpcGraknService(ai.grakn.engine.rpc.GrpcGraknService) Service(spark.Service) EngineID(ai.grakn.engine.util.EngineID) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Collections(java.util.Collections) GraknTx(ai.grakn.GraknTx) HashSet(java.util.HashSet)

Example 5 with Keyspace

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));
}
Also used : Keyspace(ai.grakn.Keyspace) ConceptId(ai.grakn.concept.ConceptId)

Aggregations

Keyspace (ai.grakn.Keyspace)30 Test (org.junit.Test)14 GraknTx (ai.grakn.GraknTx)9 GraknTxType (ai.grakn.GraknTxType)7 ConceptId (ai.grakn.concept.ConceptId)7 List (java.util.List)6 BatchExecutorClient (ai.grakn.client.BatchExecutorClient)5 Timer (com.codahale.metrics.Timer)5 LoggerFactory (org.slf4j.LoggerFactory)5 GraknSession (ai.grakn.GraknSession)4 Role (ai.grakn.concept.Role)4 InsertQuery (ai.grakn.graql.InsertQuery)4 SimpleURI (ai.grakn.util.SimpleURI)4 Before (org.junit.Before)4 Logger (org.slf4j.Logger)4 GraknClient (ai.grakn.client.GraknClient)3 AttributeType (ai.grakn.concept.AttributeType)3 EntityType (ai.grakn.concept.EntityType)3 RelationshipType (ai.grakn.concept.RelationshipType)3 Graql (ai.grakn.graql.Graql)3