Search in sources :

Example 26 with TxGrpcCommunicator

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

the class GrpcServerTest method whenCommittingATransactionRemotely_TheTransactionIsCommitted.

@Test
public void whenCommittingATransactionRemotely_TheTransactionIsCommitted() {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.send(commitRequest());
    }
    verify(tx).commitSubmitNoLogs();
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 27 with TxGrpcCommunicator

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

the class GrpcServerTest method whenClosingATransactionRemotely_TheTransactionIsClosedWithinTheThreadItWasCreated.

@Test
public void whenClosingATransactionRemotely_TheTransactionIsClosedWithinTheThreadItWasCreated() {
    final Thread[] threadOpenedWith = new Thread[1];
    final Thread[] threadClosedWith = new Thread[1];
    when(txFactory.tx(MYKS, GraknTxType.WRITE)).thenAnswer(invocation -> {
        threadOpenedWith[0] = Thread.currentThread();
        return tx;
    });
    doAnswer(invocation -> {
        threadClosedWith[0] = Thread.currentThread();
        return null;
    }).when(tx).close();
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
    }
    verify(tx).close();
    assertEquals(threadOpenedWith[0], threadClosedWith[0]);
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 28 with TxGrpcCommunicator

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

the class GrpcServerTest method whenParsingQueryFails_Throw.

@Test
public void whenParsingQueryFails_Throw() throws Throwable {
    String message = "you forgot a semicolon";
    GraknException error = GraqlSyntaxException.create(message);
    when(tx.graql().parse(QUERY)).thenThrow(error);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(execQueryRequest(QUERY, null));
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(message)));
        exception.expect(hasMetadata(ErrorType.KEY, ErrorType.GRAQL_SYNTAX_EXCEPTION));
        throw tx.receive().error();
    }
}
Also used : GraknException(ai.grakn.exception.GraknException) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 29 with TxGrpcCommunicator

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

the class GrpcServerTest method whenOpeningATransactionRemotely_ReceiveADoneMessage.

@Test
public void whenOpeningATransactionRemotely_ReceiveADoneMessage() throws InterruptedException {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        TxResponse response = tx.receive().ok();
        assertEquals(doneResponse(), response);
    }
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) Test(org.junit.Test)

Example 30 with TxGrpcCommunicator

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

the class GrpcServerTest method whenCommittingATransactionRemotely_ReceiveADoneMessage.

@Test
public void whenCommittingATransactionRemotely_ReceiveADoneMessage() throws InterruptedException {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(commitRequest());
        TxResponse response = tx.receive().ok();
        assertEquals(doneResponse(), response);
    }
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) 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