use of ai.grakn.graql.Query in project grakn by graknlabs.
the class QueryParserTest method testParseList.
@Test
public void testParseList() {
String insertString = "insert $x isa movie;";
String getString = "match $y isa movie; limit 1; get;";
List<Query<?>> queries = Graql.parser().parseList(insertString + getString).collect(toList());
assertEquals(ImmutableList.of(insert(var("x").isa("movie")), match(var("y").isa("movie")).limit(1).get()), queries);
}
use of ai.grakn.graql.Query in project grakn by graknlabs.
the class QueryParserTest method testParseListOneInsert.
@Test
public void testParseListOneInsert() {
String insertString = "insert $x isa movie;";
List<Query<?>> queries = Graql.parser().parseList(insertString).collect(toList());
assertEquals(ImmutableList.of(insert(var("x").isa("movie"))), queries);
}
use of ai.grakn.graql.Query in project grakn by graknlabs.
the class SampleKBLoader method loadFromFile.
public static void loadFromFile(GraknTx graph, String file) {
File graql = new File(GraknSystemProperty.PROJECT_RELATIVE_DIR.value() + "/grakn-test-tools/src/main/graql/" + file);
List<String> queries;
try {
queries = Files.readLines(graql, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
graph.graql().parser().parseList(queries.stream().collect(Collectors.joining("\n"))).forEach(Query::execute);
}
use of ai.grakn.graql.Query 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()));
}
use of ai.grakn.graql.Query in project grakn by graknlabs.
the class RemoteGraknTxTest method whenExecutingAQueryWithABooleanResult_GetABoolBack.
@Test
public void whenExecutingAQueryWithABooleanResult_GetABoolBack() {
Query<?> query = match(var("x").isa("person")).aggregate(ask());
String queryString = query.toString();
TxResponse response = TxResponse.newBuilder().setQueryResult(QueryResult.newBuilder().setOtherResult("true")).build();
server.setResponseSequence(GrpcUtil.execQueryRequest(query), response);
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
// The open request
verify(server.requests()).onNext(any());
assertTrue(tx.graql().<Query<Boolean>>parse(queryString).execute());
}
}
Aggregations