Search in sources :

Example 46 with LogEntry

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

Example 47 with LogEntry

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);
}
Also used : LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) Test(org.junit.jupiter.api.Test)

Example 48 with LogEntry

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LogEntry (org.apache.ignite.raft.jraft.entity.LogEntry)48 LogId (org.apache.ignite.raft.jraft.entity.LogId)26 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)12 Status (org.apache.ignite.raft.jraft.Status)11 BaseStorageTest (org.apache.ignite.raft.jraft.storage.BaseStorageTest)11 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 LogManager (org.apache.ignite.raft.jraft.storage.LogManager)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 ConfigurationEntry (org.apache.ignite.raft.jraft.conf.ConfigurationEntry)6 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)6 ByteBuffer (java.nio.ByteBuffer)5 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)5 ConfigurationManager (org.apache.ignite.raft.jraft.conf.ConfigurationManager)4 RaftOptions (org.apache.ignite.raft.jraft.option.RaftOptions)4 EventHandler (com.lmax.disruptor.EventHandler)3 EventTranslator (com.lmax.disruptor.EventTranslator)3 RingBuffer (com.lmax.disruptor.RingBuffer)3 List (java.util.List)3