Search in sources :

Example 1 with PeerPair

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair 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 PeerPair

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair 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);
}
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) Test(org.junit.Test)

Example 3 with PeerPair

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

the class AppendEntriesRequestProcessorTest method setup.

@Override
public void setup() {
    super.setup();
    this.asyncContext = new MockAsyncContext() {

        @Override
        public Connection getConnection() {
            return AppendEntriesRequestProcessorTest.this.conn;
        }
    };
    Set<PeerPair> pairs = new ConcurrentHashSet<>();
    pairs.add(new PeerPair(this.peerIdStr, this.serverId));
    Mockito.when(this.conn.getAttribute(AppendEntriesRequestProcessor.PAIR_ATTR)).thenReturn(pairs);
}
Also used : PeerPair(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) ConcurrentHashSet(com.alipay.sofa.jraft.util.concurrent.ConcurrentHashSet) MockAsyncContext(com.alipay.sofa.jraft.test.MockAsyncContext) Connection(com.alipay.sofa.jraft.rpc.Connection)

Example 4 with PeerPair

use of com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair 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 5 with PeerPair

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

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));
}
Also used : PeerPair(com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) Test(org.junit.Test)

Aggregations

PeerPair (com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair)7 Test (org.junit.Test)5 PeerRequestContext (com.alipay.sofa.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext)4 Connection (com.alipay.sofa.jraft.rpc.Connection)2 RpcContext (com.alipay.sofa.jraft.rpc.RpcContext)2 PingRequest (com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest)2 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 AppendEntriesRequest (com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequest)1 MockAsyncContext (com.alipay.sofa.jraft.test.MockAsyncContext)1 ConcurrentHashSet (com.alipay.sofa.jraft.util.concurrent.ConcurrentHashSet)1