Search in sources :

Example 61 with CPGroupId

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());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 62 with CPGroupId

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());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 63 with CPGroupId

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());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Test(org.junit.Test)

Example 64 with CPGroupId

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());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 65 with CPGroupId

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());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Test(org.junit.Test)

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5