use of com.hazelcast.cp.internal.session.AbstractProxySessionManager in project hazelcast by hazelcast.
the class AbstractFencedLockBasicTest method testReentrantTryLockWithTimeoutFails_whenSessionClosed.
@Test
public void testReentrantTryLockWithTimeoutFails_whenSessionClosed() throws ExecutionException, InterruptedException {
long fence = lock.lockAndGetFence();
assertValidFence(fence);
AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
closeSession(instances[0], groupId, sessionId);
assertTrueEventually(() -> assertNotEquals(sessionId, sessionManager.getSession(groupId)));
try {
lock.tryLock(1, TimeUnit.SECONDS);
} catch (LockOwnershipLostException ignored) {
}
}
use of com.hazelcast.cp.internal.session.AbstractProxySessionManager in project hazelcast by hazelcast.
the class AbstractFencedLockBasicTest method testReentrantTryLockFails_whenSessionClosed.
@Test
public void testReentrantTryLockFails_whenSessionClosed() throws ExecutionException, InterruptedException {
long fence = lock.lockAndGetFence();
assertValidFence(fence);
AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
closeSession(instances[0], groupId, sessionId);
assertTrueEventually(() -> assertNotEquals(sessionId, sessionManager.getSession(groupId)));
try {
lock.tryLock();
} catch (LockOwnershipLostException ignored) {
}
}
use of com.hazelcast.cp.internal.session.AbstractProxySessionManager in project hazelcast by hazelcast.
the class AbstractFencedLockBasicTest method testUnlockFails_whenNewSessionCreated.
@Test
public void testUnlockFails_whenNewSessionCreated() throws ExecutionException, InterruptedException {
long fence = lock.lockAndGetFence();
assertValidFence(fence);
AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
closeSession(instances[0], groupId, sessionId);
assertTrueEventually(() -> assertNotEquals(sessionId, sessionManager.getSession(groupId)));
lockByOtherThread(lock);
try {
lock.unlock();
} catch (LockOwnershipLostException ignored) {
}
assertFalse(lock.isLockedByCurrentThread());
}
use of com.hazelcast.cp.internal.session.AbstractProxySessionManager in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testInactiveSessionsAreEventuallyClosed.
@Test
public void testInactiveSessionsAreEventuallyClosed() throws ExecutionException, InterruptedException {
semaphore.init(1);
semaphore.acquire();
RaftGroupId groupId = getGroupId();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
assertFalse(sessionService.getAllSessions(groupId).get().isEmpty());
}
});
AbstractProxySessionManager sessionManager = getSessionManager();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
// Not using semaphore.release(), because we want to keep sending session HBs.
RaftOp op = new ReleasePermitsOp(objectName, sessionId, getThreadId(), newUnsecureUUID(), 1);
invokeRaftOp(groupId, op).get();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService service1 = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
assertTrue(service1.getAllSessions(groupId).get().isEmpty());
}
assertEquals(NO_SESSION_ID, sessionManager.getSession(groupId));
});
}
use of com.hazelcast.cp.internal.session.AbstractProxySessionManager in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testRetriedWaitKeysAreExpiredTogether.
@Test
public void testRetriedWaitKeysAreExpiredTogether() {
semaphore.init(1);
CountDownLatch releaseLatch = new CountDownLatch(1);
spawn(() -> {
try {
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
assertOpenEventually(releaseLatch);
semaphore.release();
});
assertTrueEventually(() -> assertEquals(0, semaphore.availablePermits()));
// there is a session id now
RaftGroupId groupId = getGroupId();
AbstractProxySessionManager sessionManager = getSessionManager();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
UUID invUid = newUnsecureUUID();
BiTuple[] acquireWaitTimeoutKeyRef = new BiTuple[1];
InternalCompletableFuture<Boolean> f1 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
assertTrueEventually(() -> {
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
assertEquals(1, waitTimeouts.size());
acquireWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
});
InternalCompletableFuture<Boolean> f2 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
assertTrueEventually(() -> {
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
RaftService raftService = getNodeEngineImpl(primaryInstance).getService(RaftService.SERVICE_NAME);
int partitionId = raftService.getCPGroupPartitionId(groupId);
SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry 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() {
Semaphore semaphore = registry.getResourceOrNull(objectName);
Map<Object, WaitKeyContainer<AcquireInvocationKey>> waitKeys = semaphore.getInternalWaitKeysMap();
verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
latch.countDown();
}
});
assertOpenEventually(latch);
assertTrue(verified[0]);
});
RaftOp op = new ExpireWaitKeysOp(SemaphoreService.SERVICE_NAME, Collections.singletonList(acquireWaitTimeoutKeyRef[0]));
invokeRaftOp(groupId, op).joinInternal();
assertTrueEventually(() -> {
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty());
});
releaseLatch.countDown();
assertTrueEventually(() -> assertEquals(1, semaphore.availablePermits()));
assertFalse(f1.joinInternal());
assertFalse(f2.joinInternal());
}
Aggregations