use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockAdvancedTest method testSuccessfulTryLockClearsWaitTimeouts.
@Test
public void testSuccessfulTryLockClearsWaitTimeouts() {
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.tryLock(10, MINUTES);
latch.countDown();
});
assertTrueEventually(() -> {
assertFalse(registry.getWaitTimeouts().isEmpty());
assertFalse(registry.getLiveOperations().isEmpty());
});
lock.unlock();
assertOpenEventually(latch);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testSuccessfulAcquireClearsWaitTimeouts.
@Test
public void testSuccessfulAcquireClearsWaitTimeouts() {
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.acquire(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
latch.countDown();
});
assertTrueEventually(() -> 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 AbstractSemaphoreAdvancedTest method testFailedTryAcquireClearsWaitTimeouts.
@Test
public void testFailedTryAcquireClearsWaitTimeouts() throws InterruptedException {
semaphore.init(1);
CPGroupId groupId = getGroupId();
HazelcastInstance leader = leaderInstanceOf(groupId);
SemaphoreService service = getNodeEngineImpl(leader).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
boolean success = semaphore.tryAcquire(2, 1, TimeUnit.SECONDS);
assertFalse(success);
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testPermitIncreaseClearsWaitTimeouts.
@Test
public void testPermitIncreaseClearsWaitTimeouts() {
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 AbstractSemaphoreAdvancedTest method testDestroyClearsWaitTimeouts.
@Test
public void testDestroyClearsWaitTimeouts() {
semaphore.init(1);
CPGroupId groupId = getGroupId();
HazelcastInstance leader = leaderInstanceOf(groupId);
SemaphoreService service = getNodeEngineImpl(leader).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
spawn(() -> {
try {
semaphore.tryAcquire(2, 10, MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
assertTrueEventually(() -> {
assertFalse(registry.getWaitTimeouts().isEmpty());
assertFalse(registry.getLiveOperations().isEmpty());
});
semaphore.destroy();
assertTrue(registry.getWaitTimeouts().isEmpty());
assertTrue(registry.getLiveOperations().isEmpty());
}
Aggregations