use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testRetriedReleaseIsSuccessfulAfterAcquiredByAnotherEndpoint.
@Test
public void testRetriedReleaseIsSuccessfulAfterAcquiredByAnotherEndpoint() throws InterruptedException {
semaphore.init(1);
semaphore.acquire();
RaftGroupId groupId = getGroupId();
long sessionId = getSessionManager().getSession(groupId);
UUID invUid = newUnsecureUUID();
invokeRaftOp(groupId, new ReleasePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
spawn(() -> {
try {
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
invokeRaftOp(groupId, new ReleasePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.
the class SessionAwareSemaphoreProxy method release.
@Override
public void release(int permits) {
checkPositive(permits, "Permits must be positive!");
long sessionId = getSession();
if (sessionId == NO_SESSION_ID) {
throw newIllegalStateException(null);
}
long threadId = getThreadId();
UUID invocationUid = newUnsecureUUID();
RaftOp op = new ReleasePermitsOp(objectName, sessionId, threadId, invocationUid, permits);
try {
invocationManager.invoke(groupId, op).joinInternal();
} catch (SessionExpiredException e) {
invalidateSession(sessionId);
throw newIllegalStateException(e);
} finally {
releaseSession(sessionId, permits);
}
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.
the class ReleasePermitsMessageTask method processMessage.
@Override
protected void processMessage() {
RaftOp op = new ReleasePermitsOp(parameters.name, parameters.sessionId, parameters.threadId, parameters.invocationUid, parameters.permits);
invoke(parameters.groupId, op);
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method release.
@Override
public void release(int permits) {
checkPositive(permits, "Permits must be positive!");
long clusterWideThreadId = getOrCreateUniqueThreadId();
RaftOp op = new ReleasePermitsOp(objectName, NO_SESSION_ID, clusterWideThreadId, newUnsecureUUID(), permits);
invocationManager.invoke(groupId, op).joinInternal();
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp 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));
});
}
Aggregations