Search in sources :

Example 21 with TxGrpcCommunicator

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

the class GrpcServerTest method whenExecutingQueryWithoutInferenceSet_InferenceIsNotSet.

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

Example 22 with TxGrpcCommunicator

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

the class GrpcServerTest method whenOpeningATransactionRemotelyWithAnInvalidKeyspace_Throw.

@Test
public void whenOpeningATransactionRemotelyWithAnInvalidKeyspace_Throw() throws Throwable {
    GrpcGrakn.Keyspace keyspace = GrpcGrakn.Keyspace.newBuilder().setValue("not!@akeyspace").build();
    Open open = Open.newBuilder().setKeyspace(keyspace).setTxType(TxType.Write).build();
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(TxRequest.newBuilder().setOpen(open).build());
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(GraknTxOperationException.invalidKeyspace("not!@akeyspace").getMessage())));
        exception.expect(hasMetadata(ErrorType.KEY, ErrorType.GRAKN_TX_OPERATION_EXCEPTION));
        throw tx.receive().error();
    }
}
Also used : GrpcGrakn(ai.grakn.rpc.generated.GrpcGrakn) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Open(ai.grakn.rpc.generated.GrpcGrakn.Open) Test(org.junit.Test)

Example 23 with TxGrpcCommunicator

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

the class GrpcServerTest method whenGettingAConcept_ReturnTheConcept.

@Test
public void whenGettingAConcept_ReturnTheConcept() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(concept.getId()).thenReturn(id);
    when(concept.isRelationship()).thenReturn(true);
    when(tx.getConcept(id)).thenReturn(concept);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.getConceptRequest(id));
        GrpcConcept.OptionalConcept response = tx.receive().ok().getOptionalConcept();
        assertEquals(id.getValue(), response.getPresent().getId().getValue());
        assertEquals(BaseType.Relationship, response.getPresent().getBaseType());
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 24 with TxGrpcCommunicator

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

the class GrpcServerTest method whenGettingIsInferredProperty_IsInferredIsReturned.

@Test
public void whenGettingIsInferredProperty_IsInferredIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isThing()).thenReturn(true);
    when(concept.asThing().isInferred()).thenReturn(false);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_INFERRED));
        assertFalse(ConceptMethods.IS_INFERRED.get(conceptConverter, client, tx.receive().ok()));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 25 with TxGrpcCommunicator

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

the class GrpcServerTest method whenCommittingFails_Throw.

@Test
public void whenCommittingFails_Throw() throws Throwable {
    doThrow(EXCEPTION).when(tx).commitSubmitNoLogs();
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(commitRequest());
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(EXCEPTION_MESSAGE)));
        throw tx.receive().error();
    }
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) 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