Search in sources :

Example 31 with RaftGroupId

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

the class AbstractFencedLockBasicTest method testReentrantTryLockFails_whenSessionClosed.

@Test
public void testReentrantTryLockFails_whenSessionClosed() throws ExecutionException, InterruptedException {
    long fence = lock.lockAndGetFence();
    assertValidFence(fence);
    AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
    RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
    long sessionId = sessionManager.getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    closeSession(instances[0], groupId, sessionId);
    assertTrueEventually(() -> assertNotEquals(sessionId, sessionManager.getSession(groupId)));
    try {
        lock.tryLock();
    } catch (LockOwnershipLostException ignored) {
    }
}
Also used : AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) LockOwnershipLostException(com.hazelcast.cp.lock.exception.LockOwnershipLostException) Test(org.junit.Test)

Example 32 with RaftGroupId

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

the class AbstractFencedLockBasicTest method testUnlockFails_whenNewSessionCreated.

@Test
public void testUnlockFails_whenNewSessionCreated() throws ExecutionException, InterruptedException {
    long fence = lock.lockAndGetFence();
    assertValidFence(fence);
    AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
    RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
    long sessionId = sessionManager.getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    closeSession(instances[0], groupId, sessionId);
    assertTrueEventually(() -> assertNotEquals(sessionId, sessionManager.getSession(groupId)));
    lockByOtherThread(lock);
    try {
        lock.unlock();
    } catch (LockOwnershipLostException ignored) {
    }
    assertFalse(lock.isLockedByCurrentThread());
}
Also used : AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) LockOwnershipLostException(com.hazelcast.cp.lock.exception.LockOwnershipLostException) Test(org.junit.Test)

Example 33 with RaftGroupId

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

the class AbstractFencedLockAdvancedTest method testInactiveSessionsAreEventuallyClosed.

@Test
public void testInactiveSessionsAreEventuallyClosed() throws ExecutionException, InterruptedException {
    lock.lock();
    RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertFalse(sessionService.getAllSessions(groupId).get().isEmpty());
        }
    });
    RaftSessionService sessionService = getNodeEngineImpl(primaryInstance).getService(RaftSessionService.SERVICE_NAME);
    long sessionId = sessionService.getAllSessions(groupId).get().iterator().next().id();
    getRaftInvocationManager(proxyInstance).invoke(groupId, new UnlockOp(objectName, sessionId, getThreadId(), newUnsecureUUID())).joinInternal();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService service = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertTrue(service.getAllSessions(groupId).get().isEmpty());
        }
        ProxySessionManagerService service = getNodeEngineImpl(proxyInstance).getService(ProxySessionManagerService.SERVICE_NAME);
        assertEquals(NO_SESSION_ID, service.getSession(groupId));
    });
}
Also used : RaftSessionService(com.hazelcast.cp.internal.session.RaftSessionService) UnlockOp(com.hazelcast.cp.internal.datastructures.lock.operation.UnlockOp) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ProxySessionManagerService(com.hazelcast.cp.internal.session.ProxySessionManagerService) Test(org.junit.Test)

Example 34 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId 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 35 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId 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)

Aggregations

RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)59 Test (org.junit.Test)51 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)30 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)30 UUID (java.util.UUID)30 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)16 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)13 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)13 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)10 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)9 LockOwnershipLostException (com.hazelcast.cp.lock.exception.LockOwnershipLostException)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 RaftOp (com.hazelcast.cp.internal.RaftOp)4 RaftService (com.hazelcast.cp.internal.RaftService)4 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)4 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)3