use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp 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.datastructures.lock.operation.TryLockOp 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.datastructures.lock.operation.TryLockOp 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.TryLockOp in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testNewUnlockCancelsPendingLockRequest.
@Test(timeout = 300_000)
public void testNewUnlockCancelsPendingLockRequest() {
lockByOtherThread();
// there is a session id now
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid = newUnsecureUUID();
InternalCompletableFuture<Object> f = 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());
});
try {
lock.unlock();
fail();
} catch (IllegalMonitorStateException ignored) {
}
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.
the class TryLockMessageTask method processMessage.
@Override
protected void processMessage() {
RaftOp op = new TryLockOp(parameters.name, parameters.sessionId, parameters.threadId, parameters.invocationUid, parameters.timeoutMs);
invoke(parameters.groupId, op);
}
Aggregations