Search in sources :

Example 16 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testLockAcquireRetry.

@Test(timeout = 300_000)
public void testLockAcquireRetry() {
    lock.lock();
    lock.unlock();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid)).joinInternal();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid)).joinInternal();
    assertEquals(1, lock.getLockCount());
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) LockOp(com.hazelcast.cp.internal.datastructures.lock.operation.LockOp) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testLockReentrantAcquireRetry.

@Test(timeout = 300_000)
public void testLockReentrantAcquireRetry() {
    lock.lock();
    lock.unlock();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid1 = newUnsecureUUID();
    UUID invUid2 = newUnsecureUUID();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid1)).joinInternal();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid2)).joinInternal();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid2)).joinInternal();
    assertEquals(2, lock.getLockCount());
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) LockOp(com.hazelcast.cp.internal.datastructures.lock.operation.LockOp) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testRetriedLockDoesNotCancelPendingLockRequest.

@Test(timeout = 300_000)
public void testRetriedLockDoesNotCancelPendingLockRequest() {
    lockByOtherThread();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid));
    assertTrueAllTheTime(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertEquals(1, registry.getWaitTimeouts().size());
    }, 10);
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) LockOp(com.hazelcast.cp.internal.datastructures.lock.operation.LockOp) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testGetLockCountCallInitializesLockedSessionId.

@Test(timeout = 300_000)
public void testGetLockCountCallInitializesLockedSessionId() {
    lock.lock();
    lock.unlock();
    // there is a session id now
    long threadId = getThreadId();
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, threadId, newUnsecureUUID())).joinInternal();
    int getLockCount = lock.getLockCount();
    assertEquals(1, getLockCount);
    Long lockedSessionId = lock.getLockedSessionId(threadId);
    assertNotNull(lockedSessionId);
    assertEquals(sessionId, (long) lockedSessionId);
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) LockOp(com.hazelcast.cp.internal.datastructures.lock.operation.LockOp) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) Test(org.junit.Test)

Example 20 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testRetriedWaitKeysAreExpiredTogether.

@Test(timeout = 300_000)
public void testRetriedWaitKeysAreExpiredTogether() {
    CountDownLatch releaseLatch = new CountDownLatch(1);
    spawn(() -> {
        lock.lock();
        assertOpenEventually(releaseLatch);
        lock.unlock();
    });
    assertTrueEventually(() -> assertTrue(lock.isLocked()));
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    BiTuple[] lockWaitTimeoutKeyRef = new BiTuple[1];
    InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
    NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
    LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
    assertTrueEventually(() -> {
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
        assertEquals(1, waitTimeouts.size());
        lockWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
    });
    InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        RaftService raftService = nodeEngine.getService(RaftService.SERVICE_NAME);
        int partitionId = raftService.getCPGroupPartitionId(groupId);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        boolean[] verified = new boolean[1];
        CountDownLatch latch = new CountDownLatch(1);
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public int getPartitionId() {
                return partitionId;
            }

            @Override
            public void run() {
                Lock lock = registry.getResourceOrNull(objectName);
                Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
                verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
                latch.countDown();
            }
        });
        assertOpenEventually(latch);
        assertTrue(verified[0]);
    });
    RaftOp op = new ExpireWaitKeysOp(LockService.SERVICE_NAME, Collections.singletonList(lockWaitTimeoutKeyRef[0]));
    invocationManager.invoke(groupId, op).joinInternal();
    assertTrueEventually(() -> assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty()));
    releaseLatch.countDown();
    assertTrueEventually(() -> assertFalse(lock.isLocked()));
    long fence1 = f1.joinInternal();
    long fence2 = f2.joinInternal();
    assertInvalidFence(fence1);
    assertInvalidFence(fence2);
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RaftOp(com.hazelcast.cp.internal.RaftOp) CountDownLatch(java.util.concurrent.CountDownLatch) ExpireWaitKeysOp(com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) Map(java.util.Map) BiTuple(com.hazelcast.internal.util.BiTuple) Test(org.junit.Test)

Aggregations

RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)35 Test (org.junit.Test)32 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)30 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)25 UUID (java.util.UUID)25 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)16 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)12 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)12 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)9 CountDownLatch (java.util.concurrent.CountDownLatch)4 CPGroup (com.hazelcast.cp.CPGroup)2 CPGroupId (com.hazelcast.cp.CPGroupId)2 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)2 RaftService (com.hazelcast.cp.internal.RaftService)2 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)2 TriggerDestroyRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)2 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2