Search in sources :

Example 1 with TxGrpcCommunicator

use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.

the class GrpcServerTest method whenExecutingAQueryRemotely_TheQueryIsParsedAndExecuted.

@Test
public void whenExecutingAQueryRemotely_TheQueryIsParsedAndExecuted() {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.send(execQueryRequest(QUERY, null));
    }
    ai.grakn.graql.Query<?> query = tx.graql().parse(QUERY);
    verify(query).results(any());
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 2 with TxGrpcCommunicator

use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.

the class GrpcServerTest method whenExecutingQueryWithInferenceOn_InferenceIsTurnedOn.

@Test
public void whenExecutingQueryWithInferenceOn_InferenceIsTurnedOn() throws InterruptedException {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.send(execQueryRequest(QUERY, true));
        IteratorId iterator = tx.receive().ok().getIteratorId();
        tx.send(nextRequest(iterator));
        tx.send(stopRequest(iterator));
    }
    verify(tx.graql()).infer(true);
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 3 with TxGrpcCommunicator

use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.

the class GrpcServerTest method whenExecutingAQueryBeforeOpeningTx_Throw.

@Test
public void whenExecutingAQueryBeforeOpeningTx_Throw() throws Throwable {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(execQueryRequest(QUERY, null));
        exception.expect(hasStatus(Status.FAILED_PRECONDITION));
        throw tx.receive().error();
    }
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 4 with TxGrpcCommunicator

use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.

the class GrpcServerTest method whenSendingAnotherQueryDuringQueryExecution_ReturnResultsForBothQueries.

@Test
public void whenSendingAnotherQueryDuringQueryExecution_ReturnResultsForBothQueries() throws Throwable {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(execQueryRequest(QUERY, null));
        IteratorId iterator1 = tx.receive().ok().getIteratorId();
        tx.send(execQueryRequest(QUERY, null));
        IteratorId iterator2 = tx.receive().ok().getIteratorId();
        tx.send(nextRequest(iterator1));
        tx.receive().ok();
        tx.send(nextRequest(iterator2));
        tx.receive().ok();
        tx.send(stopRequest(iterator1));
        tx.receive().ok();
        tx.send(stopRequest(iterator2));
        tx.receive().ok();
    }
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 5 with TxGrpcCommunicator

use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.

the class GrpcServerTest method whenGettingALabel_TheLabelIsReturned.

@Test
public void whenGettingALabel_TheLabelIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Label label = Label.of("Dunstan");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isSchemaConcept()).thenReturn(true);
    when(concept.asSchemaConcept().getLabel()).thenReturn(label);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.GET_LABEL));
        assertEquals(label, ConceptMethods.GET_LABEL.get(conceptConverter, client, tx.receive().ok()));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Aggregations

TxGrpcCommunicator (ai.grakn.grpc.TxGrpcCommunicator)31 Test (org.junit.Test)31 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)9 Concept (ai.grakn.concept.Concept)8 ConceptId (ai.grakn.concept.ConceptId)8 IteratorId (ai.grakn.rpc.generated.GrpcIterator.IteratorId)7 TxResponse (ai.grakn.rpc.generated.GrpcGrakn.TxResponse)4 GraknException (ai.grakn.exception.GraknException)3 Answer (ai.grakn.graql.admin.Answer)2 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 Entity (ai.grakn.concept.Entity)1 Label (ai.grakn.concept.Label)1 Role (ai.grakn.concept.Role)1 GrpcGrakn (ai.grakn.rpc.generated.GrpcGrakn)1 Open (ai.grakn.rpc.generated.GrpcGrakn.Open)1 QueryResult (ai.grakn.rpc.generated.GrpcGrakn.QueryResult)1 ArrayList (java.util.ArrayList)1