Search in sources :

Example 11 with RaftGroupId

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

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

the class CountDownLatchService method createProxy.

@Override
public ICountDownLatch createProxy(String proxyName) {
    try {
        proxyName = withoutDefaultGroupName(proxyName);
        RaftService service = nodeEngine.getService(RaftService.SERVICE_NAME);
        RaftGroupId groupId = service.createRaftGroupForProxy(proxyName);
        return new CountDownLatchProxy(nodeEngine, groupId, proxyName, getObjectNameForProxy(proxyName));
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : CountDownLatchProxy(com.hazelcast.cp.internal.datastructures.countdownlatch.proxy.CountDownLatchProxy) RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId)

Example 13 with RaftGroupId

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

the class SemaphoreService method createProxy.

@Override
public ISemaphore createProxy(String proxyName) {
    try {
        proxyName = withoutDefaultGroupName(proxyName);
        RaftGroupId groupId = raftService.createRaftGroupForProxy(proxyName);
        String objectName = getObjectNameForProxy(proxyName);
        SemaphoreConfig config = getConfig(proxyName);
        return config != null && config.isJDKCompatible() ? new SessionlessSemaphoreProxy(nodeEngine, groupId, proxyName, objectName) : new SessionAwareSemaphoreProxy(nodeEngine, groupId, proxyName, objectName);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : SessionlessSemaphoreProxy(com.hazelcast.cp.internal.datastructures.semaphore.proxy.SessionlessSemaphoreProxy) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) SemaphoreConfig(com.hazelcast.config.cp.SemaphoreConfig) SessionAwareSemaphoreProxy(com.hazelcast.cp.internal.datastructures.semaphore.proxy.SessionAwareSemaphoreProxy) WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)

Example 14 with RaftGroupId

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

the class ClientProxySessionManager method shutdownAndAwait.

public void shutdownAndAwait() {
    Map<RaftGroupId, InternalCompletableFuture<Object>> futures = super.shutdown();
    ILogger logger = client.getLoggingService().getLogger(getClass());
    long remainingTimeNanos = TimeUnit.SECONDS.toNanos(SHUTDOWN_TIMEOUT_SECONDS);
    while (remainingTimeNanos > 0) {
        int closed = 0;
        for (Entry<RaftGroupId, InternalCompletableFuture<Object>> entry : futures.entrySet()) {
            CPGroupId groupId = entry.getKey();
            InternalCompletableFuture<Object> f = entry.getValue();
            if (f.isDone()) {
                closed++;
                try {
                    f.get();
                    logger.fine("Session closed for " + groupId);
                } catch (Exception e) {
                    logger.warning("Close session failed for " + groupId, e);
                }
            }
        }
        if (closed == futures.size()) {
            break;
        }
        try {
            Thread.sleep(SHUTDOWN_WAIT_SLEEP_MILLIS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
        remainingTimeNanos -= MILLISECONDS.toNanos(SHUTDOWN_WAIT_SLEEP_MILLIS);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ILogger(com.hazelcast.logging.ILogger)

Example 15 with RaftGroupId

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

the class RaftInvocationManagerAnswer method answer.

@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
    String methodName = invocation.getMethod().getName();
    Object[] arguments = invocation.getArguments();
    Class[] argumentClasses = new Class[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
        if (arguments[i] instanceof RaftOp) {
            // transfer the operation to the delegateClassloader via (de)serialization
            Object dataOperation = serializationService.toData(arguments[i]);
            Object delegateDataOperation = proxyObjectForStarter(delegateClassloader, dataOperation);
            Object delegateOperation = delegateToObjectMethod.invoke(delegateSerializationService, delegateDataOperation);
            arguments[i] = delegateOperationClass.cast(delegateOperation);
            argumentClasses[i] = delegateOperationClass;
        } else if (arguments[i] instanceof Integer) {
            argumentClasses[i] = Integer.TYPE;
        } else if (arguments[i] instanceof RaftGroupId) {
            argumentClasses[i] = delegateCPGroupIdClass;
        } else if (arguments[i] instanceof QueryPolicy) {
            argumentClasses[i] = delegateQueryPolicyClass;
        } else {
            argumentClasses[i] = arguments[i].getClass();
        }
    }
    Method delegateMethod = getDelegateMethod(methodName, argumentClasses);
    Object[] proxiedArguments = proxyArgumentsIfNeeded(arguments, delegateClassloader);
    Object result = invoke(false, delegateMethod, proxiedArguments);
    if (invocation.getMethod().getName().equals("invoke")) {
        return mock(invocation.getMethod().getReturnType(), new DelegatingAnswer(result));
    } else {
        return proxyObjectForStarter(targetClassloader, result);
    }
}
Also used : RaftOp(com.hazelcast.cp.internal.RaftOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) Method(java.lang.reflect.Method) QueryPolicy(com.hazelcast.cp.internal.raft.QueryPolicy)

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