Search in sources :

Example 1 with LockOwnershipLostException

use of com.hazelcast.cp.lock.exception.LockOwnershipLostException 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 2 with LockOwnershipLostException

use of com.hazelcast.cp.lock.exception.LockOwnershipLostException 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 3 with LockOwnershipLostException

use of com.hazelcast.cp.lock.exception.LockOwnershipLostException 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)

Example 4 with LockOwnershipLostException

use of com.hazelcast.cp.lock.exception.LockOwnershipLostException in project hazelcast by hazelcast.

the class AbstractFencedLockBasicTest method testReentrantTryLockWithTimeoutFails_whenSessionClosed.

@Test
public void testReentrantTryLockWithTimeoutFails_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(1, TimeUnit.SECONDS);
    } 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 5 with LockOwnershipLostException

use of com.hazelcast.cp.lock.exception.LockOwnershipLostException 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)

Aggregations

RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)6 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)6 LockOwnershipLostException (com.hazelcast.cp.lock.exception.LockOwnershipLostException)6 Test (org.junit.Test)6