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);
}
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);
}
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) {
}
}
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());
}
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());
}
Aggregations