Search in sources :

Example 16 with RaftGroupId

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

the class AbstractSemaphoreFailureTest method testRetriedDrainRequestIsNotProcessedAgain.

@Test(timeout = 300_000)
public void testRetriedDrainRequestIsNotProcessedAgain() throws InterruptedException, ExecutionException {
    assumeFalse(isJDKCompatible());
    semaphore.init(1);
    semaphore.acquire();
    final RaftGroupId groupId = getGroupId(semaphore);
    long sessionId = getSessionId(proxyInstance, groupId);
    long threadId = getThreadId(groupId);
    UUID invUid = newUnsecureUUID();
    RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
    InternalCompletableFuture<Integer> f1 = invocationManager.invoke(groupId, new DrainPermitsOp(objectName, sessionId, threadId, invUid));
    assertEquals(0, (int) f1.joinInternal());
    spawn(() -> semaphore.release()).get();
    InternalCompletableFuture<Integer> f2 = invocationManager.invoke(groupId, new DrainPermitsOp(objectName, sessionId, threadId, invUid));
    assertEquals(0, (int) f2.joinInternal());
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) DrainPermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp) Test(org.junit.Test)

Example 17 with RaftGroupId

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

the class AbstractSemaphoreFailureTest method testDrainCancelsPendingAcquireRequestWhenNotAcquired.

@Test(timeout = 300_000)
public void testDrainCancelsPendingAcquireRequestWhenNotAcquired() throws InterruptedException {
    semaphore.init(1);
    semaphore.acquire();
    semaphore.release();
    // if the session-aware semaphore is used, we guarantee that there is a session id now...
    RaftGroupId groupId = getGroupId(semaphore);
    long sessionId = getSessionId(proxyInstance, groupId);
    long threadId = getThreadId(groupId);
    UUID invUid = newUnsecureUUID();
    RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
    InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid, 2, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    semaphore.drainPermits();
    try {
        f.joinInternal();
        fail();
    } catch (WaitKeyCancelledException ignored) {
    }
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) AcquirePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with RaftGroupId

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

the class AbstractSemaphoreFailureTest method testRetriedAcquireReceivesPermitsOnlyOnce.

@Test(timeout = 300_000)
public void testRetriedAcquireReceivesPermitsOnlyOnce() throws InterruptedException, ExecutionException {
    semaphore.init(1);
    semaphore.acquire();
    semaphore.release();
    // if the session-aware semaphore is used, we guarantee that there is a session id now...
    RaftGroupId groupId = getGroupId(semaphore);
    long sessionId = getSessionId(proxyInstance, groupId);
    long threadId = getThreadId(groupId);
    UUID invUid1 = newUnsecureUUID();
    RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
    InternalCompletableFuture<Object> f1 = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid1, 2, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    spawn(() -> {
        try {
            semaphore.tryAcquire(20, 5, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    assertTrueEventually(() -> {
        SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertEquals(2, registry.getWaitTimeouts().size());
    });
    InternalCompletableFuture<Object> f2 = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid1, 2, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        Semaphore semaphore = registry.getResourceOrNull(objectName);
        assertEquals(2, semaphore.getInternalWaitKeysMap().size());
    });
    spawn(() -> semaphore.increasePermits(3)).get();
    f1.joinInternal();
    f2.joinInternal();
    assertEquals(2, semaphore.availablePermits());
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) AcquirePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ISemaphore(com.hazelcast.cp.ISemaphore) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with RaftGroupId

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

the class RestCPSubsystemTest method test_reset.

@Test
public void test_reset() throws ExecutionException, InterruptedException, IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    CPGroup cpGroup1 = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(DEFAULT_GROUP_NAME).toCompletableFuture().get();
    sleepAtLeastMillis(10);
    ConnectionResponse response = new HTTPCommunicator(instance1).restart(clusterName, null);
    assertEquals(200, response.responseCode);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    CPGroup cpGroup2 = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(DEFAULT_GROUP_NAME).toCompletableFuture().get();
    RaftGroupId id1 = (RaftGroupId) cpGroup1.id();
    RaftGroupId id2 = (RaftGroupId) cpGroup2.id();
    assertTrue(id2.getSeed() > id1.getSeed());
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 20 with RaftGroupId

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

the class ClientSessionManagerTest method testClientSessionManagerShutdown.

@Test
public void testClientSessionManagerShutdown() throws ExecutionException, InterruptedException {
    AbstractProxySessionManager sessionManager = getSessionManager();
    SessionProxyImpl proxy = new SessionProxyImpl(sessionManager, groupId);
    proxy.createSession();
    Map<RaftGroupId, InternalCompletableFuture<Object>> futures = sessionManager.shutdown();
    assertEquals(1, futures.size());
    Entry<RaftGroupId, InternalCompletableFuture<Object>> e = futures.entrySet().iterator().next();
    assertEquals(groupId, e.getKey());
    e.getValue().get();
    exception.expect(IllegalStateException.class);
    proxy.createSession();
}
Also used : AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) AbstractProxySessionManagerTest(com.hazelcast.cp.internal.session.AbstractProxySessionManagerTest)

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