use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class LeaderStateTest method test_matchIndex.
@Test
public void test_matchIndex() {
Map<RaftEndpoint, Long> indices = new HashMap<RaftEndpoint, Long>();
for (RaftEndpoint endpoint : remoteEndpoints) {
long index = 1 + RandomPicker.getInt(100);
state.getFollowerState(endpoint).matchIndex(index);
indices.put(endpoint, index);
}
for (RaftEndpoint endpoint : remoteEndpoints) {
long index = indices.get(endpoint);
assertEquals(index, state.getFollowerState(endpoint).matchIndex());
}
long[] matchIndices = state.matchIndices();
assertEquals(indices.size() + 1, matchIndices.length);
for (int i = 0; i < matchIndices.length - 1; i++) {
long index = matchIndices[i];
assertTrue(indices.containsValue(index));
}
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class LeaderStateTest method test_initialState.
@Test
public void test_initialState() {
for (RaftEndpoint endpoint : remoteEndpoints) {
FollowerState followerState = state.getFollowerState(endpoint);
assertEquals(0, followerState.matchIndex());
assertEquals(lastLogIndex + 1, followerState.nextIndex());
}
long[] matchIndices = state.matchIndices();
assertEquals(remoteEndpoints.size() + 1, matchIndices.length);
for (long index : matchIndices) {
assertEquals(0, index);
}
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class RaftSessionServiceTest method testLeaderFailureShiftsSessionExpirationTimes.
@Test
public void testLeaderFailureShiftsSessionExpirationTimes() throws ExecutionException, InterruptedException, UnknownHostException {
SessionResponse response = invocationManager.<SessionResponse>invoke(groupId, newCreateSessionOp()).get();
CPSessionInfo[] sessions = new CPSessionInfo[instances.length];
assertTrueEventually(() -> {
for (int i = 0; i < instances.length; i++) {
RaftSessionService service = getNodeEngineImpl(instances[i]).getService(RaftSessionService.SERVICE_NAME);
RaftSessionRegistry registry = service.getSessionRegistryOrNull(groupId);
assertNotNull(registry);
CPSessionInfo session = registry.getSession(response.getSessionId());
assertNotNull(session);
sessions[i] = session;
}
});
RaftEndpoint leaderEndpoint = getLeaderMember(getRaftNode(instances[0], groupId));
HazelcastInstance leader = getInstance(leaderEndpoint);
leader.getLifecycleService().terminate();
assertTrueEventually(() -> {
for (int i = 0; i < instances.length; i++) {
Node node;
try {
node = getNode(instances[i]);
} catch (IllegalArgumentException ignored) {
continue;
}
RaftSessionService service = node.nodeEngine.getService(RaftSessionService.SERVICE_NAME);
RaftSessionRegistry registry = service.getSessionRegistryOrNull(groupId);
assertNotNull(registry);
CPSessionInfo session = registry.getSession(response.getSessionId());
assertNotNull(session);
assertTrue(session.version() > sessions[i].version());
}
});
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class RaftStateTest method test_majority.
private void test_majority(int count) {
members = new HashSet<RaftEndpoint>();
members.add(localMember);
for (int i = 1; i < count; i++) {
members.add(newRaftMember(1000 + i));
}
state = newRaftState(groupId, localMember, members, 100);
assertEquals(majority(count), state.majority());
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class RaftStateTest method toLeader_fromCandidate.
@Test
public void toLeader_fromCandidate() {
state.toCandidate(false);
int term = state.term();
RaftLog log = state.log();
log.appendEntries(new LogEntry(term, 1, null), new LogEntry(term, 2, null), new LogEntry(term, 3, null));
long lastLogIndex = log.lastLogOrSnapshotIndex();
state.toLeader();
assertEquals(RaftRole.LEADER, state.role());
assertEquals(localMember, state.leader());
assertNull(state.candidateState());
LeaderState leaderState = state.leaderState();
assertNotNull(leaderState);
for (RaftEndpoint endpoint : state.remoteMembers()) {
FollowerState followerState = leaderState.getFollowerState(endpoint);
assertEquals(0, followerState.matchIndex());
assertEquals(lastLogIndex + 1, followerState.nextIndex());
}
long[] matchIndices = leaderState.matchIndices();
assertEquals(state.remoteMembers().size() + 1, matchIndices.length);
for (long index : matchIndices) {
assertEquals(0, index);
}
}
Aggregations