Search in sources :

Example 21 with WaitKeyCancelledException

use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.

the class AbstractSemaphoreFailureTest method testNewAcquireCancelsPendingAcquireRequestWhenAlreadyAcquired.

@Test(timeout = 300_000)
public void testNewAcquireCancelsPendingAcquireRequestWhenAlreadyAcquired() throws InterruptedException {
    semaphore.init(1);
    semaphore.acquire();
    RaftGroupId groupId = getGroupId(semaphore);
    long sessionId = getSessionId(proxyInstance, groupId);
    long threadId = getThreadId(groupId);
    UUID invUid1 = newUnsecureUUID();
    UUID invUid2 = newUnsecureUUID();
    RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
    InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid1, 1, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid2, 1, -1));
    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 22 with WaitKeyCancelledException

use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.

the class AbstractSemaphoreFailureTest method testReleaseCancelsPendingAcquireRequestWhenNoPermitsAcquired.

@Test(timeout = 300_000)
public void testReleaseCancelsPendingAcquireRequestWhenNoPermitsAcquired() 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());
    });
    try {
        semaphore.release();
    } catch (IllegalStateException ignored) {
    }
    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)

Aggregations

WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)22 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)20 UUID (java.util.UUID)20 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)13 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)12 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)12 Test (org.junit.Test)12 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)7 RaftOp (com.hazelcast.cp.internal.RaftOp)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)3 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)3 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)2 LockAcquireLimitReachedException (com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException)2 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)1