Search in sources :

Example 1 with AbstractProxySessionManager

use of com.hazelcast.cp.internal.session.AbstractProxySessionManager 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 2 with AbstractProxySessionManager

use of com.hazelcast.cp.internal.session.AbstractProxySessionManager 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 3 with AbstractProxySessionManager

use of com.hazelcast.cp.internal.session.AbstractProxySessionManager 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 4 with AbstractProxySessionManager

use of com.hazelcast.cp.internal.session.AbstractProxySessionManager 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 5 with AbstractProxySessionManager

use of com.hazelcast.cp.internal.session.AbstractProxySessionManager in project hazelcast by hazelcast.

the class ClientSessionManagerTest method testClientSessionManagerShutdown.

@Test
public void testClientSessionManagerShutdown() throws ExecutionException, InterruptedException {
    AbstractProxySessionManager sessionManager = getSessionManager();
    SessionProxyImpl proxy = new SessionProxyImpl(sessionManager, groupId);
    proxy.createSession();
    Map<RaftGroupId, InternalCompletableFuture<Object>> futures = sessionManager.shutdown();
    assertEquals(1, futures.size());
    Entry<RaftGroupId, InternalCompletableFuture<Object>> e = futures.entrySet().iterator().next();
    assertEquals(groupId, e.getKey());
    e.getValue().get();
    exception.expect(IllegalStateException.class);
    proxy.createSession();
}
Also used : AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) AbstractProxySessionManagerTest(com.hazelcast.cp.internal.session.AbstractProxySessionManagerTest)

Aggregations

RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)10 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)10 Test (org.junit.Test)10 LockOwnershipLostException (com.hazelcast.cp.lock.exception.LockOwnershipLostException)6 RaftOp (com.hazelcast.cp.internal.RaftOp)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ISemaphore (com.hazelcast.cp.ISemaphore)1 RaftService (com.hazelcast.cp.internal.RaftService)1 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)1 ReleasePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp)1 ExpireWaitKeysOp (com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp)1 AbstractProxySessionManagerTest (com.hazelcast.cp.internal.session.AbstractProxySessionManagerTest)1 RaftSessionService (com.hazelcast.cp.internal.session.RaftSessionService)1 BiTuple (com.hazelcast.internal.util.BiTuple)1 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)1