Search in sources :

Example 1 with DeleteResponse

use of ai.grakn.rpc.generated.GrpcGrakn.DeleteResponse in project grakn by graknlabs.

the class GrpcServerMock method before.

@Override
protected void before() throws Throwable {
    when(service.tx(any())).thenAnswer(args -> {
        serverResponses = args.getArgument(0);
        return serverRequests;
    });
    doAnswer(args -> {
        StreamObserver<DeleteResponse> deleteResponses = args.getArgument(1);
        deleteResponses.onNext(GrpcUtil.deleteResponse());
        deleteResponses.onCompleted();
        return null;
    }).when(service).delete(any(), any());
    // Return a default "done" response to every message from the client
    doAnswer(args -> {
        if (serverResponses == null) {
            throw new IllegalArgumentException("Set-up of rule not called");
        }
        TxRequest request = args.getArgument(0);
        Optional<TxResponse> next = grpcIterators.next(request.getNext().getIteratorId());
        serverResponses.onNext(next.orElse(GrpcUtil.doneResponse()));
        return null;
    }).when(serverRequests).onNext(any());
    // Return a default "complete" response to every "complete" message from the client
    doAnswer(args -> {
        if (serverResponses == null) {
            throw new IllegalArgumentException("Set-up of rule not called");
        }
        serverResponses.onCompleted();
        return null;
    }).when(serverRequests).onCompleted();
    serverRule.getServiceRegistry().addService(service);
}
Also used : DeleteResponse(ai.grakn.rpc.generated.GrpcGrakn.DeleteResponse) TxRequest(ai.grakn.rpc.generated.GrpcGrakn.TxRequest) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Aggregations

DeleteResponse (ai.grakn.rpc.generated.GrpcGrakn.DeleteResponse)1 TxRequest (ai.grakn.rpc.generated.GrpcGrakn.TxRequest)1 TxResponse (ai.grakn.rpc.generated.GrpcGrakn.TxResponse)1