Search in sources :

Example 1 with CloseSessionOp

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();
}
Also used : CloseSessionOp(com.hazelcast.cp.internal.session.operation.CloseSessionOp) RaftService(com.hazelcast.cp.internal.RaftService)

Example 2 with CloseSessionOp

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;
}
Also used : ManagedExecutorService(com.hazelcast.internal.util.executor.ManagedExecutorService) CloseSessionOp(com.hazelcast.cp.internal.session.operation.CloseSessionOp)

Example 3 with CloseSessionOp

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());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CloseSessionOp(com.hazelcast.cp.internal.session.operation.CloseSessionOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with CloseSessionOp

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());
        }
    }
}
Also used : CloseSessionOp(com.hazelcast.cp.internal.session.operation.CloseSessionOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) Test(org.junit.Test)

Example 5 with CloseSessionOp

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CloseSessionOp(com.hazelcast.cp.internal.session.operation.CloseSessionOp) HeartbeatSessionOp(com.hazelcast.cp.internal.session.operation.HeartbeatSessionOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CloseSessionOp (com.hazelcast.cp.internal.session.operation.CloseSessionOp)5 Test (org.junit.Test)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)1 RaftService (com.hazelcast.cp.internal.RaftService)1 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)1 HeartbeatSessionOp (com.hazelcast.cp.internal.session.operation.HeartbeatSessionOp)1 ManagedExecutorService (com.hazelcast.internal.util.executor.ManagedExecutorService)1