Search in sources :

Example 1 with RaftGroupId

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

the class AbstractSemaphoreAdvancedTest method testRetriedReleaseIsSuccessfulAfterAcquiredByAnotherEndpoint.

@Test
public void testRetriedReleaseIsSuccessfulAfterAcquiredByAnotherEndpoint() throws InterruptedException {
    semaphore.init(1);
    semaphore.acquire();
    RaftGroupId groupId = getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    UUID invUid = newUnsecureUUID();
    invokeRaftOp(groupId, new ReleasePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
    spawn(() -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    invokeRaftOp(groupId, new ReleasePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
}
Also used : ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with RaftGroupId

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

the class AbstractFencedLockBasicTest method testFailedTryLock_doesNotAcquireSession.

@Test
public void testFailedTryLock_doesNotAcquireSession() {
    lockByOtherThread(lock);
    AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
    RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
    long sessionId = sessionManager.getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    assertEquals(1, sessionManager.getSessionAcquireCount(groupId, sessionId));
    long fence = lock.tryLockAndGetFence();
    assertInvalidFence(fence);
    assertEquals(1, sessionManager.getSessionAcquireCount(groupId, sessionId));
}
Also used : AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) Test(org.junit.Test)

Example 3 with RaftGroupId

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

the class AbstractFencedLockBasicTest method testGetFenceFails_whenNewSessionCreated.

@Test
public void testGetFenceFails_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.getFence();
    } 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 4 with RaftGroupId

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

the class AbstractFencedLockBasicTest method testUnlockFails_whenSessionClosed.

@Test
public void testUnlockFails_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.unlock();
    } catch (LockOwnershipLostException ignored) {
    }
    assertFalse(lock.isLockedByCurrentThread());
    assertFalse(lock.isLocked());
    assertNoLockedSessionId();
}
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 5 with RaftGroupId

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

the class AbstractFencedLockBasicTest method testReentrantLockFails_whenSessionClosed.

@Test
public void testReentrantLockFails_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.lock();
    } 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)

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