Search in sources :

Example 1 with HazelcastOverloadException

use of com.hazelcast.core.HazelcastOverloadException in project hazelcast by hazelcast.

the class ClientMaxAllowedInvocationTest method testMaxAllowed_withUnfinishedCallback.

@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withUnfinishedCallback() throws ExecutionException, InterruptedException {
    int MAX_ALLOWED = 10;
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    String name = randomString();
    IMap map = client.getMap(name);
    IExecutorService executorService = client.getExecutorService(randomString());
    for (int i = 0; i < MAX_ALLOWED - 1; i++) {
        executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
    }
    ClientDelegatingFuture future = (ClientDelegatingFuture) executorService.submit(new SleepyProcessor(2000));
    CountDownLatch countDownLatch = new CountDownLatch(1);
    future.andThenInternal(new SleepyCallback(countDownLatch), false);
    future.get();
    try {
        map.get(1);
    } catch (HazelcastOverloadException e) {
        throw e;
    } finally {
        countDownLatch.countDown();
    }
}
Also used : IMap(com.hazelcast.core.IMap) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) IExecutorService(com.hazelcast.core.IExecutorService) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with HazelcastOverloadException

use of com.hazelcast.core.HazelcastOverloadException in project hazelcast by hazelcast.

the class InvocationRegistry method register.

/**
     * Registers an invocation.
     *
     * @param invocation The invocation to register.
     * @return false when InvocationRegistry is not alive and registration is not successful, true otherwise
     */
public boolean register(Invocation invocation) {
    final long callId;
    try {
        boolean force = invocation.op.isUrgent() || invocation.isRetryCandidate();
        callId = callIdSequence.next(force);
    } catch (TimeoutException e) {
        throw new HazelcastOverloadException("Failed to start invocation due to overload: " + invocation, e);
    }
    try {
        // Fails with IllegalStateException if the operation is already active
        setCallId(invocation.op, callId);
    } catch (IllegalStateException e) {
        callIdSequence.complete();
        throw e;
    }
    invocations.put(callId, invocation);
    if (!alive) {
        invocation.notifyError(new HazelcastInstanceNotActiveException());
        return false;
    }
    return true;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

HazelcastOverloadException (com.hazelcast.core.HazelcastOverloadException)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 IExecutorService (com.hazelcast.core.IExecutorService)1 IMap (com.hazelcast.core.IMap)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1