Search in sources :

Example 1 with ErrorResponse

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

the class ProtobufSerializerTest method testEncodeDecodeResponseContent.

@Test
public void testEncodeDecodeResponseContent() throws Exception {
    final PingRequest reqObject = TestUtils.createPingRequest();
    final RpcRequestCommand request = cmdFactory.createRequestCommand(reqObject);
    final ErrorResponse respObject = (ErrorResponse) RpcFactoryHelper.responseFactory().newResponse(null, new Status(-1, "test"));
    final RpcResponseCommand response = cmdFactory.createResponse(respObject, request);
    response.setResponseClass(ErrorResponse.class.getName());
    assertTrue(serializer.serializeContent(response));
    response.setResponseObject(null);
    assertTrue(serializer.deserializeContent(response, null));
    assertNotNull(response.getResponseObject());
    assertEquals(respObject, response.getResponseObject());
    assertNotSame(respObject, response.getResponseObject());
}
Also used : Status(com.alipay.sofa.jraft.Status) PingRequest(com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest) RpcResponseCommand(com.alipay.remoting.rpc.protocol.RpcResponseCommand) RpcRequestCommand(com.alipay.remoting.rpc.protocol.RpcRequestCommand) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 2 with ErrorResponse

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

the class RpcResponseFactoryTest method testNewResponseWithVaridicArgs.

@Test
public void testNewResponseWithVaridicArgs() {
    ErrorResponse response = (ErrorResponse) RpcFactoryHelper.responseFactory().newResponse(null, 300, "hello %s %d", "world", 99);
    assertEquals(response.getErrorCode(), 300);
    assertEquals(response.getErrorMsg(), "hello world 99");
}
Also used : ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 3 with ErrorResponse

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

the class RpcResponseFactoryTest method testNewResponseWithErrorStatus.

@Test
public void testNewResponseWithErrorStatus() {
    ErrorResponse response = (ErrorResponse) RpcFactoryHelper.responseFactory().newResponse(null, new Status(300, "test"));
    assertEquals(response.getErrorCode(), 300);
    assertEquals(response.getErrorMsg(), "test");
}
Also used : Status(com.alipay.sofa.jraft.Status) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 4 with ErrorResponse

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

the class RpcResponseFactoryTest method testNewResponseWithRaftError.

@Test
public void testNewResponseWithRaftError() {
    ErrorResponse response = (ErrorResponse) RpcFactoryHelper.responseFactory().newResponse(null, RaftError.EAGAIN, "hello world");
    assertEquals(response.getErrorCode(), RaftError.EAGAIN.getNumber());
    assertEquals(response.getErrorMsg(), "hello world");
}
Also used : ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 5 with ErrorResponse

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

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.getErrorCode());
}
Also used : Node(com.alipay.sofa.jraft.Node) 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