Search in sources :

Example 6 with RaftSessionService

use of com.hazelcast.cp.internal.session.RaftSessionService in project hazelcast by hazelcast.

the class AbstractFencedLockAdvancedTest method testActiveSessionIsNotClosedWhenPendingWaitKey.

@Test
public void testActiveSessionIsNotClosedWhenPendingWaitKey() {
    FencedLock other = null;
    for (HazelcastInstance instance : instances) {
        if (instance != proxyInstance) {
            other = instance.getCPSubsystem().getLock(lock.getName());
            break;
        }
    }
    assertNotNull(other);
    // lock from another instance
    other.lock();
    spawn(() -> {
        lock.tryLock(30, TimeUnit.MINUTES);
    });
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertEquals(2, sessionService.getAllSessions(lock.getGroupId()).get().size());
        }
    });
    assertTrueAllTheTime(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertEquals(2, sessionService.getAllSessions(lock.getGroupId()).get().size());
        }
    }, 20);
}
Also used : RaftSessionService(com.hazelcast.cp.internal.session.RaftSessionService) FencedLock(com.hazelcast.cp.lock.FencedLock) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Test(org.junit.Test)

Example 7 with RaftSessionService

use of com.hazelcast.cp.internal.session.RaftSessionService in project hazelcast by hazelcast.

the class AbstractFencedLockAdvancedTest method testInactiveSessionsAreEventuallyClosed.

@Test
public void testInactiveSessionsAreEventuallyClosed() throws ExecutionException, InterruptedException {
    lock.lock();
    RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertFalse(sessionService.getAllSessions(groupId).get().isEmpty());
        }
    });
    RaftSessionService sessionService = getNodeEngineImpl(primaryInstance).getService(RaftSessionService.SERVICE_NAME);
    long sessionId = sessionService.getAllSessions(groupId).get().iterator().next().id();
    getRaftInvocationManager(proxyInstance).invoke(groupId, new UnlockOp(objectName, sessionId, getThreadId(), newUnsecureUUID())).joinInternal();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService service = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertTrue(service.getAllSessions(groupId).get().isEmpty());
        }
        ProxySessionManagerService service = getNodeEngineImpl(proxyInstance).getService(ProxySessionManagerService.SERVICE_NAME);
        assertEquals(NO_SESSION_ID, service.getSession(groupId));
    });
}
Also used : RaftSessionService(com.hazelcast.cp.internal.session.RaftSessionService) UnlockOp(com.hazelcast.cp.internal.datastructures.lock.operation.UnlockOp) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ProxySessionManagerService(com.hazelcast.cp.internal.session.ProxySessionManagerService) Test(org.junit.Test)

Example 8 with RaftSessionService

use of com.hazelcast.cp.internal.session.RaftSessionService 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));
    });
}
Also used : RaftSessionService(com.hazelcast.cp.internal.session.RaftSessionService) ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) RaftOp(com.hazelcast.cp.internal.RaftOp) Test(org.junit.Test)

Example 9 with RaftSessionService

use of com.hazelcast.cp.internal.session.RaftSessionService in project hazelcast by hazelcast.

the class AbstractSemaphoreAdvancedTest method testActiveSessionWithPendingPermitIsNotClosed.

@Test
public void testActiveSessionWithPendingPermitIsNotClosed() {
    spawn(() -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertFalse(sessionService.getAllSessions(getGroupId()).get().isEmpty());
        }
    });
    assertTrueAllTheTime(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertFalse(sessionService.getAllSessions(getGroupId()).get().isEmpty());
        }
    }, 20);
}
Also used : RaftSessionService(com.hazelcast.cp.internal.session.RaftSessionService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Test(org.junit.Test)

Aggregations

RaftSessionService (com.hazelcast.cp.internal.session.RaftSessionService)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Test (org.junit.Test)6 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)2 RaftOp (com.hazelcast.cp.internal.RaftOp)1 UnlockOp (com.hazelcast.cp.internal.datastructures.lock.operation.UnlockOp)1 ReleasePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp)1 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)1 ProxySessionManagerService (com.hazelcast.cp.internal.session.ProxySessionManagerService)1 FencedLock (com.hazelcast.cp.lock.FencedLock)1