use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testExpiredAndRetriedTryLockRequestReceivesFailureResponse.
@Test(timeout = 300_000)
public void testExpiredAndRetriedTryLockRequestReceivesFailureResponse() {
final CountDownLatch unlockLatch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
assertOpenEventually(unlockLatch);
lock.unlock();
});
assertTrueEventually(() -> assertTrue(lock.isLocked()));
final RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
UUID invUid = newUnsecureUUID();
InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(5)));
long fence1 = f1.joinInternal();
assertEquals(INVALID_FENCE, fence1);
unlockLatch.countDown();
assertTrueEventually(() -> assertFalse(lock.isLocked()));
InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(5)));
long fence2 = f2.joinInternal();
assertEquals(INVALID_FENCE, fence2);
}
use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedTryLockWithTimeoutDoesNotCancelPendingLockRequest.
@Test(timeout = 300_000)
public void testRetriedTryLockWithTimeoutDoesNotCancelPendingLockRequest() {
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)));
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
assertTrueEventually(() -> {
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertNotNull(registry.getResourceOrNull(objectName));
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
RaftService raftService = getNodeEngineImpl(primaryInstance).getService(RaftService.SERVICE_NAME);
int partitionId = raftService.getCPGroupPartitionId(groupId);
LockRegistry registry = service.getRegistryOrNull(groupId);
boolean[] verified = new boolean[1];
CountDownLatch latch = new CountDownLatch(1);
OperationServiceImpl operationService = nodeEngine.getOperationService();
operationService.execute(new PartitionSpecificRunnable() {
@Override
public int getPartitionId() {
return partitionId;
}
@Override
public void run() {
Lock lock = registry.getResourceOrNull(objectName);
Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
latch.countDown();
}
});
latch.await(60, SECONDS);
assertTrue(verified[0]);
});
}
use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp 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);
}
use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedWaitKeysAreExpiredTogether.
@Test(timeout = 300_000)
public void testRetriedWaitKeysAreExpiredTogether() {
CountDownLatch releaseLatch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
assertOpenEventually(releaseLatch);
lock.unlock();
});
assertTrueEventually(() -> assertTrue(lock.isLocked()));
// 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();
BiTuple[] lockWaitTimeoutKeyRef = new BiTuple[1];
InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
assertTrueEventually(() -> {
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
assertEquals(1, waitTimeouts.size());
lockWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
});
InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
assertTrueEventually(() -> {
RaftService raftService = nodeEngine.getService(RaftService.SERVICE_NAME);
int partitionId = raftService.getCPGroupPartitionId(groupId);
LockRegistry registry = service.getRegistryOrNull(groupId);
boolean[] verified = new boolean[1];
CountDownLatch latch = new CountDownLatch(1);
OperationServiceImpl operationService = nodeEngine.getOperationService();
operationService.execute(new PartitionSpecificRunnable() {
@Override
public int getPartitionId() {
return partitionId;
}
@Override
public void run() {
Lock lock = registry.getResourceOrNull(objectName);
Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
latch.countDown();
}
});
assertOpenEventually(latch);
assertTrue(verified[0]);
});
RaftOp op = new ExpireWaitKeysOp(LockService.SERVICE_NAME, Collections.singletonList(lockWaitTimeoutKeyRef[0]));
invocationManager.invoke(groupId, op).joinInternal();
assertTrueEventually(() -> assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty()));
releaseLatch.countDown();
assertTrueEventually(() -> assertFalse(lock.isLocked()));
long fence1 = f1.joinInternal();
long fence2 = f2.joinInternal();
assertInvalidFence(fence1);
assertInvalidFence(fence2);
}
use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testNewTryLockWithTimeoutCancelsPendingLockRequest.
@Test(timeout = 300_000)
public void testNewTryLockWithTimeoutCancelsPendingLockRequest() {
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 TryLockOp(objectName, sessionId, getThreadId(), invUid2, MINUTES.toMillis(5)));
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
Aggregations