use of org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse in project ignite-3 by apache.
the class AbstractClientServiceTest method testInvokeWithDoneOnErrorResponse.
@Test
public void testInvokeWithDoneOnErrorResponse() throws Exception {
final InvokeContext invokeCtx = new InvokeContext();
final ArgumentCaptor<InvokeCallback> callbackArg = ArgumentCaptor.forClass(InvokeCallback.class);
final CliRequests.GetPeersRequest request = rpcOptions.getRaftMessagesFactory().getPeersRequest().groupId("id").leaderId("127.0.0.1:8001").build();
MockRpcResponseClosure<ErrorResponse> done = new MockRpcResponseClosure<>();
Future<Message> future = this.clientService.invokeWithDone(this.endpoint, request, invokeCtx, done, -1);
Mockito.verify(this.rpcClient).invokeAsync(eq(this.endpoint), eq(request), eq(invokeCtx), callbackArg.capture(), eq((long) this.rpcOptions.getRpcDefaultTimeout()));
InvokeCallback cb = callbackArg.getValue();
assertNotNull(cb);
assertNotNull(future);
assertNull(done.getResponse());
assertNull(done.status);
assertFalse(future.isDone());
final Message resp = this.rpcResponseFactory.newResponse(rpcOptions.getRaftMessagesFactory(), new Status(-1, "failed"));
cb.complete(resp, null);
done.latch.await();
assertNotNull(done.status);
assertTrue(!done.status.isOk());
assertEquals(done.status.getErrorMsg(), "failed");
}
use of org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse in project ignite-3 by apache.
the class RpcResponseFactoryTest method testNewResponseFromStatus.
@Test
public void testNewResponseFromStatus() {
ErrorResponse response = (ErrorResponse) RaftRpcFactory.DEFAULT.newResponse(msgFactory, Status.OK());
assertEquals(0, response.errorCode());
assertNull(response.errorMsg());
}
use of org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse in project ignite-3 by apache.
the class BaseCliRequestProcessorTest method testSingleNode.
@Test
public void testSingleNode() {
Node node = this.mockNode(false);
this.processor = new MockCliRequestProcessor(null, "test");
this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
assertNotNull(resp);
assertSame(this.processor.ctx.node, node);
assertNotNull(resp);
assertEquals(0, resp.errorCode());
}
use of org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse in project ignite-3 by apache.
the class BaseCliRequestProcessorTest method testDisableCli.
@Test
public void testDisableCli() {
mockNode(true);
this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
assertNotNull(resp);
assertEquals(RaftError.EACCES.getNumber(), resp.errorCode());
assertEquals("Cli service is not allowed to access node <test/localhost:8081>", resp.errorMsg());
}
Aggregations