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();
}
}
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;
}
Aggregations