Search in sources :

Example 56 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.

the class RaftLogTest method getEntryAfterSnapshot.

@Test
public void getEntryAfterSnapshot() {
    LogEntry[] entries = new LogEntry[] { new LogEntry(1, 1, null), new LogEntry(1, 2, null), new LogEntry(1, 3, null) };
    log.appendEntries(entries);
    log.setSnapshot(new SnapshotEntry(1, 3, null, 0, Collections.<RaftEndpoint>emptySet()));
    log.appendEntries(new LogEntry(1, 4, null));
    log.appendEntries(new LogEntry(1, 5, null));
    for (int i = 1; i <= 3; i++) {
        assertNull(log.getLogEntry(i));
    }
    for (int i = 4; i <= log.lastLogOrSnapshotIndex(); i++) {
        LogEntry entry = log.getLogEntry(i);
        assertEquals(1, entry.term());
        assertEquals(i, entry.index());
    }
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with RaftEndpoint

use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.

the class LeaderStateTest method test_nextIndex.

@Test
public void test_nextIndex() {
    Map<RaftEndpoint, Integer> indices = new HashMap<RaftEndpoint, Integer>();
    for (RaftEndpoint endpoint : remoteEndpoints) {
        int index = 1 + RandomPicker.getInt(100);
        state.getFollowerState(endpoint).nextIndex(index);
        indices.put(endpoint, index);
    }
    for (RaftEndpoint endpoint : remoteEndpoints) {
        int index = indices.get(endpoint);
        assertEquals(index, state.getFollowerState(endpoint).nextIndex());
    }
}
Also used : HashMap(java.util.HashMap) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)8 RaftState (com.hazelcast.cp.internal.raft.impl.state.RaftState)7 ArrayList (java.util.ArrayList)7 CPMember (com.hazelcast.cp.CPMember)6 RaftLog (com.hazelcast.cp.internal.raft.impl.log.RaftLog)6 UUID (java.util.UUID)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 CPGroupId (com.hazelcast.cp.CPGroupId)5 TestRaftEndpoint (com.hazelcast.cp.internal.raft.impl.testing.TestRaftEndpoint)5 LinkedHashSet (java.util.LinkedHashSet)4 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)3 CPSubsystemException (com.hazelcast.cp.exception.CPSubsystemException)2 NotLeaderException (com.hazelcast.cp.exception.NotLeaderException)2 CannotCreateRaftGroupException (com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException)2 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)2 LeaderState (com.hazelcast.cp.internal.raft.impl.state.LeaderState)2