use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testSuccessfulTryAcquireClearsWaitTimeouts.
@Test
public void testSuccessfulTryAcquireClearsWaitTimeouts() {
semaphore.init(1);
CPGroupId groupId = getGroupId();
HazelcastInstance leader = leaderInstanceOf(groupId);
SemaphoreService service = getNodeEngineImpl(leader).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
CountDownLatch latch = new CountDownLatch(1);
spawn(() -> {
try {
semaphore.tryAcquire(2, 10, MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
latch.countDown();
});
assertTrueEventually(() -> {
assertFalse(registry.getWaitTimeouts().isEmpty());
assertFalse(registry.getLiveOperations().isEmpty());
});
semaphore.increasePermits(1);
assertOpenEventually(latch);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId 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.CPGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockAdvancedTest method testFailedTryLockClearsWaitTimeouts.
@Test
public void testFailedTryLockClearsWaitTimeouts() {
lockByOtherThread(lock);
CPGroupId groupId = lock.getGroupId();
HazelcastInstance leader = leaderInstanceOf(groupId);
LockService service = getNodeEngineImpl(leader).getService(LockService.SERVICE_NAME);
LockRegistry registry = service.getRegistryOrNull(groupId);
long fence = lock.tryLockAndGetFence(1, TimeUnit.SECONDS);
assertEquals(FencedLock.INVALID_FENCE, fence);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockAdvancedTest method testDestroyClearsWaitTimeouts.
@Test
public void testDestroyClearsWaitTimeouts() {
lockByOtherThread(lock);
CPGroupId groupId = lock.getGroupId();
HazelcastInstance leader = leaderInstanceOf(groupId);
LockService service = getNodeEngineImpl(leader).getService(LockService.SERVICE_NAME);
LockRegistry registry = service.getRegistryOrNull(groupId);
spawn(() -> {
lock.tryLock(10, MINUTES);
});
assertTrueEventually(() -> {
assertFalse(registry.getWaitTimeouts().isEmpty());
assertFalse(registry.getLiveOperations().isEmpty());
});
lock.destroy();
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockAdvancedTest method testSuccessfulLockClearsWaitTimeouts.
@Test
public void testSuccessfulLockClearsWaitTimeouts() {
lock.lock();
CPGroupId groupId = lock.getGroupId();
HazelcastInstance leader = leaderInstanceOf(groupId);
LockService service = getNodeEngineImpl(leader).getService(LockService.SERVICE_NAME);
LockRegistry registry = service.getRegistryOrNull(groupId);
CountDownLatch latch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
latch.countDown();
});
assertTrueEventually(() -> assertFalse(registry.getLiveOperations().isEmpty()));
lock.unlock();
assertOpenEventually(latch);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
Aggregations