Search in sources :

Example 6 with LockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.LockOp 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 7 with LockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.LockOp 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 8 with LockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.LockOp in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testUnlockCallInitializesLockedSessionId.

@Test(timeout = 300_000)
public void testUnlockCallInitializesLockedSessionId() {
    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();
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, threadId, newUnsecureUUID())).joinInternal();
    lock.unlock();
    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 9 with LockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.LockOp in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testIsLockedCallInitializesLockedSessionId.

@Test(timeout = 300_000)
public void testIsLockedCallInitializesLockedSessionId() {
    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();
    boolean locked = lock.isLocked();
    assertTrue(locked);
    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)

Aggregations

RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)9 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)9 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)9 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)9 Test (org.junit.Test)9 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)4 UUID (java.util.UUID)4 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)1