use of com.hazelcast.cp.internal.RaftGroupId 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.RaftGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testPendingLockAcquireRetry.
@Test(timeout = 300_000)
public void testPendingLockAcquireRetry() {
CountDownLatch unlockLatch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
assertOpenEventually(unlockLatch);
lock.unlock();
});
assertTrueEventually(() -> assertTrue(lock.isLocked()));
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid = newUnsecureUUID();
InternalCompletableFuture<Long> f1 = 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);
assertFalse(registry.getWaitTimeouts().isEmpty());
});
unlockLatch.countDown();
assertTrueEventually(() -> {
LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty());
assertTrue(lock.isLocked());
});
InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
long fence1 = f1.joinInternal();
long fence2 = f2.joinInternal();
assertEquals(fence1, lock.getFence());
assertEquals(fence1, fence2);
assertEquals(1, lock.getLockCount());
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedTryLockWithoutTimeoutDoesNotCancelPendingLockRequest.
@Test(timeout = 300_000)
public void testRetriedTryLockWithoutTimeoutDoesNotCancelPendingLockRequest() {
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 TryLockOp(objectName, sessionId, getThreadId(), invUid, 0));
assertTrueAllTheTime(() -> {
LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
LockRegistry registry = service.getRegistryOrNull(groupId);
assertEquals(1, registry.getWaitTimeouts().size());
}, 10);
}
use of com.hazelcast.cp.internal.RaftGroupId 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.RaftGroupId 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) {
}
}
Aggregations