use of org.apache.ignite.raft.jraft.entity.LogEntry 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);
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class IteratorImplTest method testNext.
@Test
public void testNext() {
int i = 1;
while (iter.isGood()) {
assertEquals(i, iter.getIndex());
assertNotNull(iter.done());
final LogEntry log = iter.entry();
assertEquals(i, log.getId().getIndex());
assertEquals(1, log.getId().getTerm());
iter.next();
i++;
}
assertEquals(i, 11);
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class IteratorTest method setup.
@BeforeEach
public void setup() {
this.applyingIndex = new AtomicLong(0);
this.closures = new ArrayList<>();
for (int i = 0; i < 11; i++) {
this.closures.add(new MockClosure());
final LogEntry log = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_DATA);
log.getId().setIndex(i);
log.getId().setTerm(1);
log.setData(ByteBuffer.allocate(i));
Mockito.when(this.logManager.getEntry(i)).thenReturn(log);
}
this.iterImpl = new IteratorImpl(fsm, logManager, closures, 0L, 0L, 10L, applyingIndex, new NodeOptions());
this.iter = new IteratorWrapper(iterImpl);
}
Aggregations