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);
}
Aggregations