Search in sources :

Example 1 with PingRequest

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());
}
Also used : PingRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest) RemotingException(org.apache.ignite.raft.jraft.error.RemotingException) ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 2 with PingRequest

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());
}
Also used : PingRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest) ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 3 with PingRequest

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());
}
Also used : PingRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest) InvokeTimeoutException(org.apache.ignite.raft.jraft.error.InvokeTimeoutException) ErrorResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 4 with PingRequest

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);
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) PingRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest) PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) Test(org.junit.jupiter.api.Test)

Example 5 with PingRequest

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);
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) PingRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest) PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Aggregations

PingRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest)5 Test (org.junit.jupiter.api.Test)5 ErrorResponse (org.apache.ignite.raft.jraft.rpc.RpcRequests.ErrorResponse)3 RpcContext (org.apache.ignite.raft.jraft.rpc.RpcContext)2 PeerPair (org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair)2 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)1 InvokeTimeoutException (org.apache.ignite.raft.jraft.error.InvokeTimeoutException)1 RemotingException (org.apache.ignite.raft.jraft.error.RemotingException)1 PeerRequestContext (org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext)1