use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class SemaphoreAdvancedTest method testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot.
@Test
public void testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot() throws ExecutionException, InterruptedException {
semaphore.init(1);
spawn(() -> {
try {
semaphore.tryAcquire(2, 10, MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
CPGroupId groupId = getGroupId();
assertTrueEventually(() -> {
HazelcastInstance leader = leaderInstanceOf(groupId);
SemaphoreService service = getNodeEngineImpl(leader).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertFalse(registry.getWaitTimeouts().isEmpty());
});
for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
semaphore.acquire();
semaphore.release();
}
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftNodeImpl raftNode = getRaftNode(instance, groupId);
assertNotNull(raftNode);
LogEntry snapshotEntry = getSnapshotEntry(raftNode);
assertTrue(snapshotEntry.index() > 0);
List<RestoreSnapshotOp> ops = (List<RestoreSnapshotOp>) snapshotEntry.operation();
for (RestoreSnapshotOp op : ops) {
if (op.getServiceName().equals(SemaphoreService.SERVICE_NAME)) {
ResourceRegistry registry = (ResourceRegistry) op.getSnapshot();
assertFalse(registry.getWaitTimeouts().isEmpty());
return;
}
}
fail();
}
});
instances[1].shutdown();
HazelcastInstance newInstance = factory.newHazelcastInstance(createConfig(groupSize, groupSize));
newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(newInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertFalse(registry.getWaitTimeouts().isEmpty());
assertEquals(1, registry.availablePermits(objectName));
});
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class HazelcastRaftTestSupport method getLeaderInstance.
protected static HazelcastInstance getLeaderInstance(HazelcastInstance[] instances, CPGroupId groupId) {
RaftNodeImpl[] raftNodeRef = new RaftNodeImpl[1];
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftNodeImpl raftNode = getRaftNode(instance, groupId);
if (raftNode != null) {
raftNodeRef[0] = raftNode;
return;
}
}
fail();
});
RaftNodeImpl raftNode = raftNodeRef[0];
waitUntilLeaderElected(raftNode);
RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
assertNotNull(leaderEndpoint);
for (HazelcastInstance instance : instances) {
CPMember cpMember = instance.getCPSubsystem().getLocalCPMember();
if (cpMember != null && leaderEndpoint.getUuid().equals(cpMember.getUuid())) {
return instance;
}
}
throw new AssertionError();
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class HazelcastRaftTestSupport method waitAllForLeaderElection.
protected static RaftNodeImpl waitAllForLeaderElection(HazelcastInstance[] instances, CPGroupId groupId) {
assertTrueEventually(() -> {
RaftNodeImpl leaderNode = getLeaderNode(instances, groupId);
int leaderTerm = getTerm(leaderNode);
for (HazelcastInstance instance : instances) {
RaftNodeImpl raftNode = getRaftNode(instance, groupId);
assertNotNull(raftNode);
assertEquals(leaderNode.getLocalMember(), getLeaderMember(raftNode));
assertEquals(leaderTerm, getTerm(raftNode));
}
});
return getLeaderNode(instances, groupId);
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class LocalRaftGroup method getNodesExcept.
public RaftNodeImpl[] getNodesExcept(RaftEndpoint endpoint) {
RaftNodeImpl[] n = new RaftNodeImpl[nodes.length - 1];
int i = 0;
for (RaftNodeImpl node : nodes) {
if (!node.getLocalMember().equals(endpoint)) {
n[i++] = node;
}
}
if (i != n.length) {
throw new IllegalArgumentException();
}
return n;
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class LocalRaftGroup method createNewRaftNode.
public RaftNodeImpl createNewRaftNode(RestoredRaftState restoredRaftState, RaftStateStore stateStore) {
checkNotNull(restoredRaftState);
int oldSize = this.integrations.length;
int newSize = oldSize + 1;
RaftEndpoint[] endpoints = new RaftEndpoint[newSize];
LocalRaftIntegration[] integrations = new LocalRaftIntegration[newSize];
RaftNodeImpl[] nodes = new RaftNodeImpl[newSize];
System.arraycopy(this.members, 0, endpoints, 0, oldSize);
System.arraycopy(this.integrations, 0, integrations, 0, oldSize);
System.arraycopy(this.nodes, 0, nodes, 0, oldSize);
LocalRaftIntegration integration = createNewLocalRaftIntegration((TestRaftEndpoint) restoredRaftState.localEndpoint());
createdNodeCount++;
integrations[oldSize] = integration;
RaftEndpoint endpoint = integration.getLocalEndpoint();
endpoints[oldSize] = endpoint;
RaftNodeImpl node = restoreRaftNode(groupId, restoredRaftState, raftAlgorithmConfig, integration, stateStore);
nodes[oldSize] = node;
this.members = endpoints;
this.integrations = integrations;
this.nodes = nodes;
node.start();
initDiscovery();
return node;
}
Aggregations