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();
}
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]);
}
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();
}
}
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);
}
}
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);
}
}
Aggregations