Search in sources :

Example 21 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class TxFactoryJanusTest method getGraph.

private static JanusGraph getGraph() {
    Keyspace name = Keyspace.of("hehe" + UUID.randomUUID().toString().replaceAll("-", ""));
    when(session.keyspace()).thenReturn(name);
    janusGraphFactory = new TxFactoryJanus(session);
    Graph graph = janusGraphFactory.open(GraknTxType.WRITE).getTinkerPopGraph();
    assertThat(graph, instanceOf(JanusGraph.class));
    return (JanusGraph) graph;
}
Also used : Graph(org.apache.tinkerpop.gremlin.structure.Graph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) Keyspace(ai.grakn.Keyspace) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph)

Example 22 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class GraknSessionProvider method getSession.

@Override
public GraknSession getSession(GraqlShellOptions options, ConsoleReader console) {
    int defaultGrpcPort = config.getProperty(GraknConfigKey.GRPC_PORT);
    SimpleURI defaultGrpcUri = new SimpleURI(Grakn.DEFAULT_URI.getHost(), defaultGrpcPort);
    SimpleURI location = options.getUri();
    SimpleURI uri = location != null ? location : defaultGrpcUri;
    Keyspace keyspace = options.getKeyspace();
    return RemoteGrakn.session(uri, keyspace);
}
Also used : Keyspace(ai.grakn.Keyspace) SimpleURI(ai.grakn.util.SimpleURI)

Example 23 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class GraknClientFake method whenBatchExecutorClientCloses_AllTasksHaveCompleted.

@Test
public void whenBatchExecutorClientCloses_AllTasksHaveCompleted() throws GraknClientException {
    Keyspace keyspace = Keyspace.of("yes");
    GraknClientFake graknClient = new GraknClientFake();
    // 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) Test(org.junit.Test)

Example 24 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class DocTestUtil method getTestGraph.

public static GraknSession getTestGraph(SimpleURI uri, String knowledgeBaseName) {
    Keyspace keyspace = SampleKBLoader.randomKeyspace();
    GraknSession session = Grakn.session(uri, keyspace);
    try (GraknTx tx = session.open(GraknTxType.WRITE)) {
        Consumer<GraknTx> loader = loaders.get(knowledgeBaseName);
        if (loader == null) {
            throw new IllegalArgumentException("Unknown knowledge base '" + knowledgeBaseName + "'");
        }
        loader.accept(tx);
        tx.commit();
    }
    return session;
}
Also used : GraknTx(ai.grakn.GraknTx) Keyspace(ai.grakn.Keyspace) GraknSession(ai.grakn.GraknSession)

Example 25 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class BenchmarkIT method loadRandomisedRelationInstances.

private void loadRandomisedRelationInstances(String entityLabel, String fromRoleLabel, String toRoleLabel, String relationLabel, int N, GraknSession session, GraknClient graknClient, Keyspace keyspace) {
    try (BatchExecutorClient loader = BatchExecutorClient.newBuilder().taskClient(graknClient).build()) {
        GraknTx tx = session.open(GraknTxType.READ);
        Var entityVar = var().asUserDefined();
        ConceptId[] instances = tx.graql().match(entityVar.isa(entityLabel)).get().execute().stream().map(ans -> ans.get(entityVar).getId()).toArray(ConceptId[]::new);
        assertEquals(instances.length, N);
        Role fromRole = tx.getRole(fromRoleLabel);
        Role toRole = tx.getRole(toRoleLabel);
        RelationshipType relationType = tx.getRelationshipType(relationLabel);
        Random rand = new Random();
        Multimap<Integer, Integer> assignmentMap = HashMultimap.create();
        for (int i = 0; i < N; i++) {
            int from = rand.nextInt(N - 1);
            int to = rand.nextInt(N - 1);
            while (to == from && assignmentMap.get(from).contains(to)) to = rand.nextInt(N - 1);
            Var fromRolePlayer = Graql.var();
            Var toRolePlayer = Graql.var();
            Pattern relationInsert = Graql.var().rel(Graql.label(fromRole.getLabel()), fromRolePlayer).rel(Graql.label(toRole.getLabel()), toRolePlayer).isa(Graql.label(relationType.getLabel())).and(fromRolePlayer.asUserDefined().id(instances[from])).and(toRolePlayer.asUserDefined().id(instances[to]));
            loader.add(Graql.insert(relationInsert.admin().varPatterns()), keyspace).subscribe();
        }
        tx.close();
    }
}
Also used : Iterables(com.google.common.collect.Iterables) VarPattern(ai.grakn.graql.VarPattern) Keyspace(ai.grakn.Keyspace) Role(ai.grakn.concept.Role) Assume.assumeFalse(org.junit.Assume.assumeFalse) InsertQuery(ai.grakn.graql.InsertQuery) LoggerFactory(org.slf4j.LoggerFactory) Graql(ai.grakn.graql.Graql) Random(java.util.Random) Answer(ai.grakn.graql.admin.Answer) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) Charset(java.nio.charset.Charset) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) Files(com.google.common.io.Files) GraknTx(ai.grakn.GraknTx) GraknClient(ai.grakn.client.GraknClient) ConceptId(ai.grakn.concept.ConceptId) ClassRule(org.junit.ClassRule) Grakn(ai.grakn.Grakn) GraknSystemProperty(ai.grakn.GraknSystemProperty) EngineContext(ai.grakn.test.rule.EngineContext) Before(org.junit.Before) GraknTxType(ai.grakn.GraknTxType) Graql.var(ai.grakn.graql.Graql.var) BatchExecutorClient(ai.grakn.client.BatchExecutorClient) Logger(org.slf4j.Logger) GraknSession(ai.grakn.GraknSession) Test(org.junit.Test) GetQuery(ai.grakn.graql.GetQuery) File(java.io.File) GraknTestUtil.usingTinker(ai.grakn.util.GraknTestUtil.usingTinker) List(java.util.List) SampleKBLoader.randomKeyspace(ai.grakn.util.SampleKBLoader.randomKeyspace) Var(ai.grakn.graql.Var) Pattern(ai.grakn.graql.Pattern) Assert.assertEquals(org.junit.Assert.assertEquals) VarPattern(ai.grakn.graql.VarPattern) Pattern(ai.grakn.graql.Pattern) Var(ai.grakn.graql.Var) RelationshipType(ai.grakn.concept.RelationshipType) ConceptId(ai.grakn.concept.ConceptId) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) Random(java.util.Random) BatchExecutorClient(ai.grakn.client.BatchExecutorClient)

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