Search in sources :

Example 6 with CPGroupId

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

Example 7 with CPGroupId

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));
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RestoreSnapshotOp(com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp) List(java.util.List) ResourceRegistry(com.hazelcast.cp.internal.datastructures.spi.blocking.ResourceRegistry) LogEntry(com.hazelcast.cp.internal.raft.impl.log.LogEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with CPGroupId

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

Example 9 with CPGroupId

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

Example 10 with CPGroupId

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