Search in sources :

Example 21 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.

the class FencedLockClientBasicTest method test_sessionIsClosedOnCPSubsystemReset.

@Test
public void test_sessionIsClosedOnCPSubsystemReset() throws Exception {
    lock.lock();
    instances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    assertTrueEventually(() -> {
        HazelcastClientProxy clientProxy = (HazelcastClientProxy) client;
        ClientProxySessionManager proxySessionManager = clientProxy.client.getProxySessionManager();
        assertEquals(NO_SESSION_ID, proxySessionManager.getSession((RaftGroupId) lock.getGroupId()));
    });
}
Also used : ClientProxySessionManager(com.hazelcast.client.cp.internal.session.ClientProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) FencedLockBasicTest(com.hazelcast.cp.internal.datastructures.lock.FencedLockBasicTest)

Example 22 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.

the class SessionAwareSemaphoreClientBasicTest method testDrain_ReleasesSessionProperly.

@Test
public void testDrain_ReleasesSessionProperly() throws InterruptedException {
    int permits = 20;
    assertTrue(semaphore.init(permits));
    final int drainPermits = semaphore.drainPermits();
    HazelcastClientProxy clientProxy = (HazelcastClientProxy) client;
    ClientProxySessionManager proxySessionManager = clientProxy.client.getProxySessionManager();
    SessionAwareSemaphoreProxy proxy = (SessionAwareSemaphoreProxy) semaphore;
    RaftGroupId groupId = (RaftGroupId) proxy.getGroupId();
    final long session = proxySessionManager.getSession(groupId);
    assertEquals(drainPermits, proxySessionManager.getSessionAcquireCount(groupId, session));
}
Also used : ClientProxySessionManager(com.hazelcast.client.cp.internal.session.ClientProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) SessionAwareSemaphoreBasicTest(com.hazelcast.cp.internal.datastructures.semaphore.SessionAwareSemaphoreBasicTest) Test(org.junit.Test)

Example 23 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.

the class ClientRaftProxyFactory method createProxy.

@Nonnull
public <T extends DistributedObject> T createProxy(String serviceName, String proxyName) {
    proxyName = withoutDefaultGroupName(proxyName);
    String objectName = getObjectNameForProxy(proxyName);
    RaftGroupId groupId = getGroupId(proxyName, objectName);
    if (serviceName.equals(AtomicLongService.SERVICE_NAME)) {
        return (T) new AtomicLongProxy(context, groupId, proxyName, objectName);
    } else if (serviceName.equals(AtomicRefService.SERVICE_NAME)) {
        return (T) new AtomicRefProxy(context, groupId, proxyName, objectName);
    } else if (serviceName.equals(CountDownLatchService.SERVICE_NAME)) {
        return (T) new CountDownLatchProxy(context, groupId, proxyName, objectName);
    } else if (serviceName.equals(LockService.SERVICE_NAME)) {
        return (T) createFencedLock(groupId, proxyName, objectName);
    } else if (serviceName.equals(SemaphoreService.SERVICE_NAME)) {
        return (T) createSemaphore(groupId, proxyName, objectName);
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : CountDownLatchProxy(com.hazelcast.client.cp.internal.datastructures.countdownlatch.CountDownLatchProxy) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) AtomicLongProxy(com.hazelcast.client.cp.internal.datastructures.atomiclong.AtomicLongProxy) AtomicRefProxy(com.hazelcast.client.cp.internal.datastructures.atomicref.AtomicRefProxy) Nonnull(javax.annotation.Nonnull)

Example 24 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.

the class RaftAtomicValueService method createProxy.

@Override
public final DistributedObject createProxy(String proxyName) {
    try {
        proxyName = withoutDefaultGroupName(proxyName);
        RaftGroupId groupId = raftService.createRaftGroupForProxy(proxyName);
        return newRaftAtomicProxy(nodeEngine, groupId, proxyName, getObjectNameForProxy(proxyName));
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException)

Example 25 with RaftGroupId

use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.

the class AbstractProxySessionManager method shutdown.

/**
 * Invokes a shutdown call on server to close all existing sessions.
 */
public Map<RaftGroupId, InternalCompletableFuture<Object>> shutdown() {
    lock.writeLock().lock();
    try {
        Map<RaftGroupId, InternalCompletableFuture<Object>> futures = new HashMap<>();
        for (Entry<RaftGroupId, SessionState> e : sessions.entrySet()) {
            RaftGroupId groupId = e.getKey();
            long sessionId = e.getValue().id;
            InternalCompletableFuture<Object> f = closeSession(groupId, sessionId);
            futures.put(groupId, f);
        }
        sessions.clear();
        running = false;
        return futures;
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId)

Aggregations

RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)59 Test (org.junit.Test)51 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)30 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)30 UUID (java.util.UUID)30 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)16 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)13 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)13 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)10 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)9 LockOwnershipLostException (com.hazelcast.cp.lock.exception.LockOwnershipLostException)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 RaftOp (com.hazelcast.cp.internal.RaftOp)4 RaftService (com.hazelcast.cp.internal.RaftService)4 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)4 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)3