Search in sources :

Example 1 with PingRequest

use of com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest 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 PingRequest

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

the class ProtobufSerializerTest method testEncodeDecodeRequestContent.

@Test
public void testEncodeDecodeRequestContent() throws Exception {
    final PingRequest reqObject = TestUtils.createPingRequest();
    final RpcRequestCommand request = cmdFactory.createRequestCommand(reqObject);
    request.setRequestClass(PingRequest.class.getName());
    assertTrue(serializer.serializeContent(request, null));
    request.setRequestObject(null);
    assertTrue(serializer.deserializeContent(request));
    assertNotNull(request.getRequestObject());
    assertEquals(reqObject, request.getRequestObject());
    assertNotSame(reqObject, request.getRequestObject());
}
Also used : PingRequest(com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest) RpcRequestCommand(com.alipay.remoting.rpc.protocol.RpcRequestCommand) Test(org.junit.Test)

Example 3 with PingRequest

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

the class AppendEntriesRequestProcessorTest method testSendSequenceResponse.

@Test
public void testSendSequenceResponse() {
    mockNode();
    final AppendEntriesRequestProcessor processor = (AppendEntriesRequestProcessor) newProcessor();
    final PeerPair pair = processor.pairOf(this.peerIdStr, this.serverId);
    processor.getOrCreatePeerRequestContext(this.groupId, pair, this.conn);
    final PingRequest msg = TestUtils.createPingRequest();
    final RpcContext asyncContext = Mockito.mock(RpcContext.class);
    processor.sendSequenceResponse(this.groupId, pair, 1, asyncContext, msg);
    Mockito.verify(asyncContext, Mockito.never()).sendResponse(msg);
    processor.sendSequenceResponse(this.groupId, pair, 0, asyncContext, msg);
    Mockito.verify(asyncContext, Mockito.times(2)).sendResponse(msg);
}
Also used : RpcContext(com.alipay.sofa.jraft.rpc.RpcContext) PingRequest(com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest) PeerPair(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) Test(org.junit.Test)

Example 4 with PingRequest

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

the class AbstractClientServiceTest method testInvokeWithDoneOK.

@Test
public void testInvokeWithDoneOK() throws Exception {
    ArgumentCaptor<InvokeCallback> callbackArg = ArgumentCaptor.forClass(InvokeCallback.class);
    PingRequest request = TestUtils.createPingRequest();
    MockRpcResponseClosure<ErrorResponse> done = new MockRpcResponseClosure<>();
    Future<Message> future = this.clientService.invokeWithDone(this.endpoint, request, done, -1);
    Mockito.verify(this.rpcClient).invokeAsync(eq(this.endpoint), eq(request), Mockito.any(), callbackArg.capture(), eq((long) this.rpcOptions.getRpcDefaultTimeout()));
    InvokeCallback cb = callbackArg.getValue();
    assertNotNull(cb);
    assertNotNull(future);
    assertNull(done.getResponse());
    assertNull(done.status);
    assertFalse(future.isDone());
    ErrorResponse response = (ErrorResponse) this.rpcResponseFactory.newResponse(null, Status.OK());
    cb.complete(response, null);
    Message msg = future.get();
    assertNotNull(msg);
    assertTrue(msg instanceof ErrorResponse);
    assertSame(msg, response);
    done.latch.await();
    assertNotNull(done.status);
    assertEquals(0, done.status.getCode());
}
Also used : PingRequest(com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest) Message(com.google.protobuf.Message) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 5 with PingRequest

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

the class AbstractClientServiceTest method testCancel.

@Test
public void testCancel() throws Exception {
    ArgumentCaptor<InvokeCallback> callbackArg = ArgumentCaptor.forClass(InvokeCallback.class);
    PingRequest request = TestUtils.createPingRequest();
    MockRpcResponseClosure<ErrorResponse> done = new MockRpcResponseClosure<>();
    Future<Message> future = this.clientService.invokeWithDone(this.endpoint, request, done, -1);
    Mockito.verify(this.rpcClient).invokeAsync(eq(this.endpoint), eq(request), Mockito.any(), callbackArg.capture(), eq((long) this.rpcOptions.getRpcDefaultTimeout()));
    InvokeCallback cb = callbackArg.getValue();
    assertNotNull(cb);
    assertNotNull(future);
    assertNull(done.getResponse());
    assertNull(done.status);
    assertFalse(future.isDone());
    future.cancel(true);
    ErrorResponse response = (ErrorResponse) this.rpcResponseFactory.newResponse(null, Status.OK());
    cb.complete(response, null);
    // The closure should be notified with ECANCELED error code.
    done.latch.await();
    assertNotNull(done.status);
    assertEquals(RaftError.ECANCELED.getNumber(), done.status.getCode());
}
Also used : PingRequest(com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest) Message(com.google.protobuf.Message) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Aggregations

PingRequest (com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest)9 Test (org.junit.Test)8 ErrorResponse (com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse)6 Message (com.google.protobuf.Message)4 RpcRequestCommand (com.alipay.remoting.rpc.protocol.RpcRequestCommand)2 RemotingException (com.alipay.sofa.jraft.error.RemotingException)2 RpcContext (com.alipay.sofa.jraft.rpc.RpcContext)2 PeerPair (com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair)2 ExecutionException (java.util.concurrent.ExecutionException)2 RpcResponseCommand (com.alipay.remoting.rpc.protocol.RpcResponseCommand)1 Status (com.alipay.sofa.jraft.Status)1 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 InvokeTimeoutException (com.alipay.sofa.jraft.error.InvokeTimeoutException)1 Connection (com.alipay.sofa.jraft.rpc.Connection)1 RpcClient (com.alipay.sofa.jraft.rpc.RpcClient)1 PeerRequestContext (com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext)1