Search in sources :

Example 1 with PeerPair

use of org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair 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 2 with PeerPair

use of org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair in project ignite-3 by apache.

the class AppendEntriesRequestProcessorTest method testGetPeerRequestContextRemovePeerRequestContext.

@Test
public void testGetPeerRequestContextRemovePeerRequestContext() {
    mockNode();
    final AppendEntriesRequestProcessor processor = (AppendEntriesRequestProcessor) newProcessor();
    final PeerPair pair = processor.pairOf(this.peerIdStr, this.serverId);
    final PeerRequestContext ctx = processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
    assertNotNull(ctx);
    assertSame(ctx, processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager));
    assertEquals(0, ctx.getNextRequiredSequence());
    assertEquals(0, ctx.getAndIncrementSequence());
    assertEquals(1, ctx.getAndIncrementSequence());
    assertEquals(0, ctx.getAndIncrementNextRequiredSequence());
    assertEquals(1, ctx.getAndIncrementNextRequiredSequence());
    assertFalse(ctx.hasTooManyPendingResponses());
    processor.removePeerRequestContext(this.groupId, pair);
    final PeerRequestContext newCtx = processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
    assertNotNull(newCtx);
    assertNotSame(ctx, newCtx);
    assertEquals(0, newCtx.getNextRequiredSequence());
    assertEquals(0, newCtx.getAndIncrementSequence());
    assertEquals(1, newCtx.getAndIncrementSequence());
    assertEquals(0, newCtx.getAndIncrementNextRequiredSequence());
    assertEquals(1, newCtx.getAndIncrementNextRequiredSequence());
    assertFalse(newCtx.hasTooManyPendingResponses());
}
Also used : PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) Test(org.junit.jupiter.api.Test)

Example 3 with PeerPair

use of org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair in project ignite-3 by apache.

the class AppendEntriesRequestProcessorTest method testOnClosed.

@Test
public void testOnClosed() {
    mockNode();
    final AppendEntriesRequestProcessor processor = (AppendEntriesRequestProcessor) newProcessor();
    PeerPair pair = processor.pairOf(this.peerIdStr, this.serverId);
    final PeerRequestContext ctx = processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
    assertNotNull(ctx);
    assertSame(ctx, processor.getPeerRequestContext(this.groupId, pair));
    assertSame(ctx, processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager));
    processor.onClosed(peerIdStr, this.serverId);
    assertNull(processor.getPeerRequestContext(this.groupId, pair));
    assertNotSame(ctx, processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager));
}
Also used : PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) Test(org.junit.jupiter.api.Test)

Example 4 with PeerPair

use of org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair in project ignite-3 by apache.

the class AppendEntriesRequestProcessorTest method verify.

@Override
public void verify(final String interest, final RaftServerService service, final NodeRequestProcessor<AppendEntriesRequest> processor) {
    assertEquals(interest, AppendEntriesRequest.class.getName());
    Mockito.verify(service).handleAppendEntriesRequest(eq(this.request), Mockito.any());
    final PeerPair pair = ((AppendEntriesRequestProcessor) processor).pairOf(this.peerIdStr, this.serverId);
    final PeerRequestContext ctx = ((AppendEntriesRequestProcessor) processor).getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
    assertNotNull(ctx);
}
Also used : PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) AppendEntriesRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesRequest)

Example 5 with PeerPair

use of org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair in project ignite-3 by apache.

the class AppendEntriesRequestProcessorTest method testPairOf.

@Test
public void testPairOf() {
    final AppendEntriesRequestProcessor processor = (AppendEntriesRequestProcessor) newProcessor();
    PeerPair pair = processor.pairOf(this.peerIdStr, this.serverId);
    assertEquals(pair.remote, this.serverId);
    assertEquals(pair.local, this.peerIdStr);
    // test constant pool
    assertSame(pair, processor.pairOf(this.peerIdStr, this.serverId));
    assertSame(pair, processor.pairOf(this.peerIdStr, this.serverId));
    assertEquals("PeerPair[localhost:8081 -> localhost:8082]", pair.toString());
}
Also used : PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) Test(org.junit.jupiter.api.Test)

Aggregations

PeerPair (org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair)6 Test (org.junit.jupiter.api.Test)5 PeerRequestContext (org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext)4 RpcContext (org.apache.ignite.raft.jraft.rpc.RpcContext)2 PingRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest)2 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)1 AppendEntriesRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesRequest)1