Search in sources :

Example 21 with ErrorResponse

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");
}
Also used : Status(org.apache.ignite.raft.jraft.Status) ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 22 with ErrorResponse

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());
}
Also used : ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 23 with ErrorResponse

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());
}
Also used : Node(org.apache.ignite.raft.jraft.Node) ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 24 with ErrorResponse

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());
}
Also used : ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ErrorResponse (org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse)24 Test (org.junit.jupiter.api.Test)20 Status (org.apache.ignite.raft.jraft.Status)5 Node (org.apache.ignite.raft.jraft.Node)4 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)4 Message (org.apache.ignite.raft.jraft.rpc.Message)4 PingRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest)3 NodeId (org.apache.ignite.raft.jraft.entity.NodeId)2 InvokeTimeoutException (org.apache.ignite.raft.jraft.error.InvokeTimeoutException)2 JRaftException (org.apache.ignite.raft.jraft.error.JRaftException)2 RemotingException (org.apache.ignite.raft.jraft.error.RemotingException)2 RpcClient (org.apache.ignite.raft.jraft.rpc.RpcClient)2 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)1 GetLeaderRequest (org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderRequest)1 GetLeaderResponse (org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderResponse)1 GetPeersRequest (org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersRequest)1 GetPeersResponse (org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersResponse)1