use of org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest in project ignite-3 by apache.
the class AbstractClientServiceTest method testInvokeWithDoneException.
@Test
public void testInvokeWithDoneException() throws Exception {
InvokeContext invokeCtx = new InvokeContext();
ArgumentCaptor<InvokeCallback> callbackArg = ArgumentCaptor.forClass(InvokeCallback.class);
PingRequest request = TestUtils.createPingRequest();
Mockito.doThrow(new RemotingException()).when(this.rpcClient).invokeAsync(eq(this.endpoint), eq(request), eq(invokeCtx), callbackArg.capture(), eq((long) this.rpcOptions.getRpcDefaultTimeout()));
MockRpcResponseClosure<ErrorResponse> done = new MockRpcResponseClosure<>();
Future<Message> future = this.clientService.invokeWithDone(this.endpoint, request, invokeCtx, done, -1);
InvokeCallback cb = callbackArg.getValue();
assertNotNull(cb);
assertNotNull(future);
assertTrue(future.isDone());
done.latch.await();
assertNotNull(done.status);
assertEquals(RaftError.EINTERNAL.getNumber(), done.status.getCode());
}
use of org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest in project ignite-3 by apache.
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(rpcOptions.getRaftMessagesFactory(), Status.OK());
cb.complete(response, null);
done.latch.await();
assertNotNull(done.status);
assertEquals(0, done.status.getCode());
}
use of org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest in project ignite-3 by apache.
the class AbstractClientServiceTest method testInvokeWithDoneOnException.
@Test
public void testInvokeWithDoneOnException() throws Exception {
InvokeContext invokeCtx = new InvokeContext();
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, 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());
cb.complete(null, new InvokeTimeoutException());
done.latch.await();
assertNotNull(done.status);
assertEquals(RaftError.ETIMEDOUT.getNumber(), done.status.getCode());
}
use of org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest in project ignite-3 by apache.
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, nodeManager);
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 org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest in project ignite-3 by apache.
the class AppendEntriesRequestProcessorTest method testTooManyPendingResponses.
@Test
public void testTooManyPendingResponses() {
final PeerId peer = mockNode();
nodeManager.get(this.groupId, peer).getRaftOptions().setMaxReplicatorInflightMsgs(2);
final RpcContext asyncContext = Mockito.mock(RpcContext.class);
final AppendEntriesRequestProcessor processor = (AppendEntriesRequestProcessor) newProcessor();
final PeerPair pair = processor.pairOf(this.peerIdStr, this.serverId);
final PingRequest msg = TestUtils.createPingRequest();
final PeerRequestContext ctx = processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
assertNotNull(ctx);
processor.sendSequenceResponse(this.groupId, pair, 1, asyncContext, msg);
processor.sendSequenceResponse(this.groupId, pair, 2, asyncContext, msg);
processor.sendSequenceResponse(this.groupId, pair, 3, asyncContext, msg);
Mockito.verify(asyncContext, Mockito.never()).sendResponse(msg);
final PeerRequestContext newCtx = processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
assertNotNull(newCtx);
assertNotSame(ctx, newCtx);
}
Aggregations