Search in sources :

Example 1 with PeerRequestContext

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext in project sofa-jraft by sofastack.

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, this.conn);
    assertNotNull(ctx);
}
Also used : PeerPair(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) AppendEntriesRequest(com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequest)

Example 2 with PeerRequestContext

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext in project sofa-jraft by sofastack.

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, this.conn);
    assertNotNull(ctx);
    assertSame(ctx, processor.getPeerRequestContext(this.groupId, pair));
    assertSame(ctx, processor.getOrCreatePeerRequestContext(this.groupId, pair, this.conn));
    processor.onClosed(null, this.conn);
    assertNull(processor.getPeerRequestContext(this.groupId, pair));
    assertNotSame(ctx, processor.getOrCreatePeerRequestContext(this.groupId, pair, this.conn));
}
Also used : PeerPair(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) Test(org.junit.Test)

Example 3 with PeerRequestContext

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext in project sofa-jraft by sofastack.

the class AppendEntriesRequestProcessorTest method testTooManyPendingResponses.

@Test
public void testTooManyPendingResponses() {
    final PeerId peer = mockNode();
    NodeManager.getInstance().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 Connection conn = Mockito.mock(Connection.class);
    Mockito.when(asyncContext.getConnection()).thenReturn(conn);
    final PeerRequestContext ctx = processor.getOrCreatePeerRequestContext(this.groupId, pair, conn);
    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);
    Mockito.verify(conn).close();
    final PeerRequestContext newCtx = processor.getOrCreatePeerRequestContext(this.groupId, pair, conn);
    assertNotNull(newCtx);
    assertNotSame(ctx, newCtx);
}
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) Connection(com.alipay.sofa.jraft.rpc.Connection) PeerRequestContext(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) PeerId(com.alipay.sofa.jraft.entity.PeerId) Test(org.junit.Test)

Example 4 with PeerRequestContext

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext in project sofa-jraft by sofastack.

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, this.conn);
    assertNotNull(ctx);
    assertSame(ctx, processor.getOrCreatePeerRequestContext(this.groupId, pair, this.conn));
    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, this.conn);
    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(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) PeerRequestContext(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext) Test(org.junit.Test)

Aggregations

PeerPair (com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair)4 PeerRequestContext (com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext)4 Test (org.junit.Test)3 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 Connection (com.alipay.sofa.jraft.rpc.Connection)1 RpcContext (com.alipay.sofa.jraft.rpc.RpcContext)1 AppendEntriesRequest (com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequest)1 PingRequest (com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest)1