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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations