use of com.hazelcast.cp.internal.session.operation.CloseSessionOp in project hazelcast by hazelcast.
the class AbstractFencedLockBasicTest method closeSession.
private void closeSession(HazelcastInstance instance, CPGroupId groupId, long sessionId) {
RaftService service = getNodeEngineImpl(instance).getService(RaftService.SERVICE_NAME);
service.getInvocationManager().invoke(groupId, new CloseSessionOp(sessionId)).joinInternal();
}
use of com.hazelcast.cp.internal.session.operation.CloseSessionOp in project hazelcast by hazelcast.
the class RaftSessionService method forceCloseSession.
@Override
public InternalCompletableFuture<Boolean> forceCloseSession(String groupName, final long sessionId) {
ManagedExecutorService executor = nodeEngine.getExecutionService().getExecutor(SYSTEM_EXECUTOR);
InternalCompletableFuture<Boolean> future = InternalCompletableFuture.withExecutor(executor);
raftService.getCPGroup(groupName).whenCompleteAsync((group, t) -> {
if (t == null) {
if (group != null) {
raftService.getInvocationManager().<Boolean>invoke(group.id(), new CloseSessionOp(sessionId)).whenCompleteAsync(completingCallback(future));
} else {
future.complete(false);
}
} else {
future.completeExceptionally(t);
}
});
return future;
}
use of com.hazelcast.cp.internal.session.operation.CloseSessionOp in project hazelcast by hazelcast.
the class RaftSessionServiceTest method testSessionClose.
@Test
public void testSessionClose() throws ExecutionException, InterruptedException, UnknownHostException {
SessionResponse response = invocationManager.<SessionResponse>invoke(groupId, newCreateSessionOp()).get();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService service = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
RaftSessionRegistry registry = service.getSessionRegistryOrNull(groupId);
assertNotNull(registry);
assertNotNull(registry.getSession(response.getSessionId()));
}
});
invocationManager.invoke(groupId, new CloseSessionOp(response.getSessionId())).get();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService service = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
RaftSessionRegistry registry = service.getSessionRegistryOrNull(groupId);
assertNotNull(registry);
assertNull(registry.getSession(response.getSessionId()));
assertThat(service.getAllSessions(groupId).get(), empty());
}
});
}
use of com.hazelcast.cp.internal.session.operation.CloseSessionOp in project hazelcast by hazelcast.
the class AbstractSessionAwareSemaphoreBasicTest method testNoDuplicateRelease_whenSessionExpires.
@Test
public void testNoDuplicateRelease_whenSessionExpires() throws InterruptedException, ExecutionException {
semaphore.init(5);
semaphore.acquire(3);
RaftGroupId groupId = getGroupId(semaphore);
long session = getSessionManager(proxyInstance).getSession(groupId);
assertNotEquals(NO_SESSION_ID, session);
boolean sessionClosed = this.<Boolean>invokeRaftOp(groupId, new CloseSessionOp(session)).get();
assertTrue(sessionClosed);
assertEquals(5, semaphore.availablePermits());
try {
semaphore.release(1);
fail();
} catch (IllegalStateException expected) {
if (expected.getCause() != null) {
assertInstanceOf(SessionExpiredException.class, expected.getCause());
}
}
}
use of com.hazelcast.cp.internal.session.operation.CloseSessionOp in project hazelcast by hazelcast.
the class RaftSessionServiceTest method testHeartbeatFailsAfterSessionClose.
@Test
public void testHeartbeatFailsAfterSessionClose() throws ExecutionException, InterruptedException, UnknownHostException {
SessionResponse response = invocationManager.<SessionResponse>invoke(groupId, newCreateSessionOp()).get();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
RaftSessionService service = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
RaftSessionRegistry registry = service.getSessionRegistryOrNull(groupId);
assertNotNull(registry);
assertNotNull(registry.getSession(response.getSessionId()));
}
});
invocationManager.invoke(groupId, new CloseSessionOp(response.getSessionId())).get();
exception.expectCause(isA(SessionExpiredException.class));
invocationManager.invoke(groupId, new HeartbeatSessionOp(response.getSessionId())).get();
}
Aggregations