Search in sources :

Example 1 with LockOp

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

the class AbstractFencedLockFailureTest method testLockCallInitializesLockedSessionId.

@Test(timeout = 300_000)
public void testLockCallInitializesLockedSessionId() {
    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();
    lock.lock();
    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 2 with LockOp

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

the class AbstractFencedLockFailureTest method testIsLockedByCurrentThreadCallInitializesLockedSessionId.

@Test(timeout = 300_000)
public void testIsLockedByCurrentThreadCallInitializesLockedSessionId() {
    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();
    // the current thread acquired the lock once and we pretend that there was a operation timeout in lock.lock() call
    assertTrue(lock.isLockedByCurrentThread());
    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 3 with LockOp

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

the class AbstractFencedLockFailureTest method testNewLockCancelsPendingLockRequest.

@Test(timeout = 300_000)
public void testNewLockCancelsPendingLockRequest() {
    lockByOtherThread();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid1 = newUnsecureUUID();
    UUID invUid2 = newUnsecureUUID();
    InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid1, 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(), invUid2));
    try {
        f.joinInternal();
        fail();
    } catch (WaitKeyCancelledException ignored) {
    }
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) 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 4 with LockOp

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

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