use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class FencedLockAdvancedTest method testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot.
@Test
public void testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot() throws ExecutionException, InterruptedException {
long fence = this.lock.lockAndGetFence();
assertTrue(fence > 0);
spawn(() -> {
lock.tryLock(10, MINUTES);
});
CPGroupId groupId = this.lock.getGroupId();
assertTrueEventually(() -> {
HazelcastInstance leader = getLeaderInstance(instances, groupId);
LockService service = getNodeEngineImpl(leader).getService(LockService.SERVICE_NAME);
ResourceRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertFalse(registry.getWaitTimeouts().isEmpty());
});
spawn(() -> {
for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
lock.isLocked();
}
});
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(LockService.SERVICE_NAME)) {
ResourceRegistry registry = (ResourceRegistry) op.getSnapshot();
assertFalse(registry.getWaitTimeouts().isEmpty());
return;
}
}
fail();
}
});
HazelcastInstance instanceToShutdown = (instances[0] == proxyInstance) ? instances[1] : instances[0];
instanceToShutdown.shutdown();
HazelcastInstance newInstance = factory.newHazelcastInstance(createConfig(groupSize, groupSize));
newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
assertTrueEventually(() -> {
RaftNodeImpl raftNode = getRaftNode(newInstance, groupId);
assertNotNull(raftNode);
assertTrue(getSnapshotEntry(raftNode).index() > 0);
LockService service = getNodeEngineImpl(newInstance).getService(LockService.SERVICE_NAME);
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertFalse(registry.getWaitTimeouts().isEmpty());
LockOwnershipState ownership = registry.getLockOwnershipState(objectName);
assertTrue(ownership.isLocked());
assertTrue(ownership.getLockCount() > 0);
assertEquals(fence, ownership.getFence());
});
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method testExpandMultipleRaftGroupsMultipleTimes.
@Test
public void testExpandMultipleRaftGroupsMultipleTimes() throws ExecutionException, InterruptedException, TimeoutException {
HazelcastInstance[] instances = newInstances(5, 5, 2);
CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
CPSubsystemManagementService managementService = instances[6].getCPSubsystem().getCPSubsystemManagementService();
String groupName = "group1";
instances[0].getCPSubsystem().getAtomicLong("long1@" + groupName).set(5);
CPGroup otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
CPGroupId groupId = otherGroup.id();
waitAllForLeaderElection(Arrays.copyOf(instances, 5), groupId);
CPMember[] otherGroupMembers = otherGroup.members().toArray(new CPMember[0]);
List<Address> shutdownAddresses = asList(otherGroupMembers[0].getAddress(), otherGroupMembers[1].getAddress());
instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
HazelcastInstance[] runningInstances = new HazelcastInstance[instances.length - shutdownAddresses.size()];
for (int i = 0, j = 0; i < instances.length; i++) {
HazelcastInstance instance = instances[i];
if (shutdownAddresses.contains(getAddress(instance))) {
instance.shutdown();
} else {
runningInstances[j++] = instance;
}
}
CPGroup metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
assertEquals(4, metadataGroup.members().size());
assertEquals(4, otherGroup.members().size());
assertTrueEventually(() -> {
assertNotNull(getRaftNode(instances[5], metadataGroupId));
assertNotNull(getRaftNode(instances[5], groupId));
});
instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
assertEquals(5, metadataGroup.members().size());
assertEquals(5, otherGroup.members().size());
CPGroup metadataGroupRef = metadataGroup;
CPGroup otherGroupRef = otherGroup;
assertTrueEventually(() -> {
long commitIndex = getCommitIndex(getLeaderNode(runningInstances, metadataGroupId));
assertNotNull(getRaftNode(instances[6], groupId));
for (HazelcastInstance instance : asList(instances[5], instances[6])) {
RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
assertNotNull(raftNode);
assertEquals(commitIndex, getCommitIndex(raftNode));
CPGroup g1 = queryRaftGroupLocally(instance, metadataGroupId);
CPGroup g2 = queryRaftGroupLocally(instance, otherGroupRef.id());
assertNotNull(g1);
assertNotNull(g2);
assertArrayEquals(metadataGroupRef.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
assertArrayEquals(otherGroupRef.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
}
});
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractCountDownLatchAdvancedTest method testDestroyClearsWaitTimeouts.
@Test
public void testDestroyClearsWaitTimeouts() {
latch.trySetCount(1);
CPGroupId groupId = getGroupId(latch);
HazelcastInstance leader = leaderInstanceOf(groupId);
CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
spawn(() -> {
try {
latch.await(10, MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
assertTrueEventually(() -> assertFalse(registry.getWaitTimeouts().isEmpty()));
latch.destroy();
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class CountDownLatchAdvancedTest method testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot.
@Test
public void testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot() throws ExecutionException, InterruptedException {
latch.trySetCount(1);
spawn(() -> {
try {
latch.await(10, MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
CPGroupId groupId = getGroupId(latch);
assertTrueEventually(() -> {
HazelcastInstance leader = getLeaderInstance(instances, groupId);
CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
ResourceRegistry registry = service.getRegistryOrNull(groupId);
assertFalse(registry.getWaitTimeouts().isEmpty());
});
for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
latch.trySetCount(1);
}
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(CountDownLatchService.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(() -> {
CountDownLatchService service = getNodeEngineImpl(newInstance).getService(CountDownLatchService.SERVICE_NAME);
CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertFalse(registry.getWaitTimeouts().isEmpty());
Assert.assertEquals(1, registry.getRemainingCount(objectName));
});
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AtomicRefBasicTest method testRecreate_afterGroupDestroy.
@Test
public void testRecreate_afterGroupDestroy() throws Exception {
atomicRef.destroy();
CPGroupId groupId = getGroupId(atomicRef);
RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
assertTrueEventually(() -> {
CPGroup group = invocationManager.<CPGroup>invoke(getMetadataGroupId(instances[0]), new GetRaftGroupOp(groupId)).join();
assertEquals(CPGroupStatus.DESTROYED, group.status());
});
try {
atomicRef.get();
fail();
} catch (CPGroupDestroyedException ignored) {
}
atomicRef = createAtomicRef(name);
assertNotEquals(groupId, getGroupId(atomicRef));
atomicRef.set("str1");
}
Aggregations