Search in sources :

Example 6 with RaftInvocationManager

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

the class AtomicLongBasicTest method testRecreate_afterGroupDestroy.

@Test
public void testRecreate_afterGroupDestroy() throws Exception {
    atomicLong.destroy();
    CPGroupId groupId = getGroupId(atomicLong);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
    assertTrueEventually(() -> {
        CPGroup group = invocationManager.<CPGroup>query(getMetadataGroupId(instances[0]), new GetRaftGroupOp(groupId), LINEARIZABLE).join();
        assertEquals(CPGroupStatus.DESTROYED, group.status());
    });
    try {
        atomicLong.incrementAndGet();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    atomicLong = createAtomicLong(name);
    CPGroupId newGroupId = getGroupId(atomicLong);
    assertNotEquals(groupId, newGroupId);
    atomicLong.incrementAndGet();
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) TriggerDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with RaftInvocationManager

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

the class AbstractFencedLockFailureTest method testNewUnlockCancelsPendingLockRequest.

@Test(timeout = 300_000)
public void testNewUnlockCancelsPendingLockRequest() {
    lockByOtherThread();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    try {
        lock.unlock();
        fail();
    } catch (IllegalMonitorStateException ignored) {
    }
    try {
        f.joinInternal();
        fail();
    } catch (WaitKeyCancelledException ignored) {
    }
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with RaftInvocationManager

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

the class AbstractCPMessageTask method query.

protected void query(CPGroupId groupId, RaftOp op, QueryPolicy policy) {
    RaftInvocationManager invocationManager = getInvocationManager();
    InternalCompletableFuture<Object> future = invocationManager.query(groupId, op, policy, false);
    future.whenCompleteAsync(this);
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager)

Example 9 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager 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 10 with RaftInvocationManager

use of com.hazelcast.cp.internal.RaftInvocationManager 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)

Aggregations

RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)35 Test (org.junit.Test)32 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)30 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)25 UUID (java.util.UUID)25 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)16 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)12 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)12 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)9 CountDownLatch (java.util.concurrent.CountDownLatch)4 CPGroup (com.hazelcast.cp.CPGroup)2 CPGroupId (com.hazelcast.cp.CPGroupId)2 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)2 RaftService (com.hazelcast.cp.internal.RaftService)2 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)2 TriggerDestroyRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)2 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2