Search in sources :

Example 11 with ByteString

use of org.apache.ignite.raft.jraft.util.ByteString in project ignite-3 by apache.

the class ReplicatorTest method testContinueSendingEntries.

@Test
public void testContinueSendingEntries() throws Exception {
    testOnRpcReturnedWaitMoreEntries();
    final Replicator r = getReplicator();
    this.id.unlock();
    mockSendEmptyEntries();
    final Future<Message> rpcInFly = r.getRpcInFly();
    assertNotNull(rpcInFly);
    final AppendEntriesRequestBuilder rb = raftOptions.getRaftMessagesFactory().appendEntriesRequest().groupId("test").serverId(new PeerId("localhost", 8082).toString()).peerId(this.peerId.toString()).term(1).prevLogIndex(10).prevLogTerm(1).committedIndex(0);
    int totalDataLen = 0;
    List<RaftOutter.EntryMeta> entries = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        totalDataLen += i;
        final LogEntry value = new LogEntry();
        value.setData(ByteBuffer.allocate(i));
        value.setType(EnumOutter.EntryType.ENTRY_TYPE_DATA);
        value.setId(new LogId(11 + i, 1));
        Mockito.when(this.logManager.getEntry(11 + i)).thenReturn(value);
        entries.add(raftOptions.getRaftMessagesFactory().entryMeta().term(1).type(EnumOutter.EntryType.ENTRY_TYPE_DATA).dataLen(i).build());
    }
    rb.entriesList(entries);
    rb.data(new ByteString(new byte[totalDataLen]));
    final RpcRequests.AppendEntriesRequest request = rb.build();
    Mockito.when(this.rpcService.appendEntries(eq(this.peerId.getEndpoint()), eq(request), eq(-1), Mockito.any())).thenAnswer(new Answer<Future>() {

        @Override
        public Future answer(InvocationOnMock invocation) throws Throwable {
            return new CompletableFuture<>();
        }
    });
    assertEquals(11, r.statInfo.firstLogIndex);
    assertEquals(10, r.statInfo.lastLogIndex);
    Mockito.when(this.logManager.getTerm(20)).thenReturn(1L);
    assertTrue(Replicator.continueSending(this.id, 0));
    assertNotNull(r.getRpcInFly());
    assertNotSame(rpcInFly, r.getRpcInFly());
    assertEquals(11, r.statInfo.firstLogIndex);
    assertEquals(20, r.statInfo.lastLogIndex);
    assertEquals(0, r.getWaitId());
    assertEquals(Replicator.RunningState.IDLE, r.statInfo.runningState);
}
Also used : Message(org.apache.ignite.raft.jraft.rpc.Message) ByteString(org.apache.ignite.raft.jraft.util.ByteString) ArrayList(java.util.ArrayList) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) AppendEntriesRequestBuilder(org.apache.ignite.raft.jraft.rpc.AppendEntriesRequestBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) LogId(org.apache.ignite.raft.jraft.entity.LogId) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Aggregations

ByteString (org.apache.ignite.raft.jraft.util.ByteString)11 ByteBuffer (java.nio.ByteBuffer)7 ByteBufferCollector (org.apache.ignite.raft.jraft.util.ByteBufferCollector)7 Message (org.apache.ignite.raft.jraft.rpc.Message)5 Test (org.junit.jupiter.api.Test)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 RpcRequests (org.apache.ignite.raft.jraft.rpc.RpcRequests)4 ArrayList (java.util.ArrayList)3 AppendEntriesRequestBuilder (org.apache.ignite.raft.jraft.rpc.AppendEntriesRequestBuilder)2 GetFileRequestBuilder (org.apache.ignite.raft.jraft.rpc.GetFileRequestBuilder)2 RpcResponseClosure (org.apache.ignite.raft.jraft.rpc.RpcResponseClosure)2 SnapshotReader (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader)2 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Future (java.util.concurrent.Future)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)1 Status (org.apache.ignite.raft.jraft.Status)1 LoadSnapshotClosure (org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure)1