Search in sources :

Example 6 with ErrorResponse

use of com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse in project sofa-jraft by sofastack.

the class BaseCliRequestProcessorTest method testEmptyNodes.

@Test
public void testEmptyNodes() {
    this.processor = new MockCliRequestProcessor(null, "test");
    this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
    ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
    assertNotNull(resp);
    assertEquals(RaftError.ENOENT.getNumber(), resp.getErrorCode());
    assertEquals("Empty nodes in group test", resp.getErrorMsg());
}
Also used : ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 7 with ErrorResponse

use of com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse in project sofa-jraft by sofastack.

the class BaseCliRequestProcessorTest method testPeerIdNotFound.

@Test
public void testPeerIdNotFound() {
    this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
    ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
    assertNotNull(resp);
    assertEquals(RaftError.ENOENT.getNumber(), resp.getErrorCode());
    assertEquals("Fail to find node localhost:8081 in group test", resp.getErrorMsg());
}
Also used : ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 8 with ErrorResponse

use of com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse in project sofa-jraft by sofastack.

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.getErrorCode());
    assertEquals("Cli service is not allowed to access node <test/localhost:8081>", resp.getErrorMsg());
}
Also used : ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 9 with ErrorResponse

use of com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse in project sofa-jraft by sofastack.

the class NodeRequestProcessorTest method testOK.

@Test
public void testOK() {
    Node node = Mockito.mock(Node.class, withSettings().extraInterfaces(RaftServerService.class));
    Mockito.when(node.getGroupId()).thenReturn("test");
    PeerId peerId = new PeerId("localhost", 8081);
    Mockito.when(node.getNodeId()).thenReturn(new NodeId("test", peerId));
    NodeManager.getInstance().addAddress(peerId.getEndpoint());
    NodeManager.getInstance().add(node);
    this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
    ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
    assertNotNull(resp);
    assertEquals(0, resp.getErrorCode());
}
Also used : Node(com.alipay.sofa.jraft.Node) NodeId(com.alipay.sofa.jraft.entity.NodeId) RaftServerService(com.alipay.sofa.jraft.rpc.RaftServerService) PeerId(com.alipay.sofa.jraft.entity.PeerId) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 10 with ErrorResponse

use of com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse in project sofa-jraft by sofastack.

the class PingRequestProcessorTest method testHandlePing.

@Test
public void testHandlePing() throws Exception {
    PingRequestProcessor processor = new PingRequestProcessor();
    MockAsyncContext ctx = new MockAsyncContext();
    processor.handleRequest(ctx, TestUtils.createPingRequest());
    ErrorResponse response = (ErrorResponse) ctx.getResponseObject();
    assertEquals(0, response.getErrorCode());
}
Also used : MockAsyncContext(com.alipay.sofa.jraft.test.MockAsyncContext) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Aggregations

ErrorResponse (com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse)26 Test (org.junit.Test)22 Message (com.google.protobuf.Message)8 Status (com.alipay.sofa.jraft.Status)6 PingRequest (com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest)6 Node (com.alipay.sofa.jraft.Node)4 PeerId (com.alipay.sofa.jraft.entity.PeerId)4 RemotingException (com.alipay.sofa.jraft.error.RemotingException)3 NodeId (com.alipay.sofa.jraft.entity.NodeId)2 InvokeTimeoutException (com.alipay.sofa.jraft.error.InvokeTimeoutException)2 JRaftException (com.alipay.sofa.jraft.error.JRaftException)2 RpcClient (com.alipay.sofa.jraft.rpc.RpcClient)2 ExecutionException (java.util.concurrent.ExecutionException)2 RpcRequestCommand (com.alipay.remoting.rpc.protocol.RpcRequestCommand)1 RpcResponseCommand (com.alipay.remoting.rpc.protocol.RpcResponseCommand)1 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)1 GetLeaderRequest (com.alipay.sofa.jraft.rpc.CliRequests.GetLeaderRequest)1 GetLeaderResponse (com.alipay.sofa.jraft.rpc.CliRequests.GetLeaderResponse)1 GetPeersRequest (com.alipay.sofa.jraft.rpc.CliRequests.GetPeersRequest)1 GetPeersResponse (com.alipay.sofa.jraft.rpc.CliRequests.GetPeersResponse)1