use of com.hazelcast.spi.exception.TargetDisconnectedException in project hazelcast by hazelcast.
the class ClientInvocation method notifyException.
public void notifyException(Throwable exception) {
if (!lifecycleService.isRunning()) {
clientInvocationFuture.complete(new HazelcastClientNotActiveException(exception.getMessage(), exception));
return;
}
if ((isBindToSingleConnection() && exception instanceof IOException) || System.currentTimeMillis() > retryTimeoutPointInMillis) {
clientInvocationFuture.complete(exception);
return;
}
if (isRetrySafeException(exception) || invocationService.isRedoOperation() || (exception instanceof TargetDisconnectedException && clientMessage.isRetryable())) {
try {
ClientExecutionServiceImpl executionServiceImpl = (ClientExecutionServiceImpl) this.executionService;
executionServiceImpl.schedule(this, RETRY_WAIT_TIME_IN_SECONDS, TimeUnit.SECONDS);
} catch (RejectedExecutionException e) {
if (logger.isFinestEnabled()) {
logger.finest("Retry could not be scheduled ", e);
}
clientInvocationFuture.complete(exception);
}
return;
}
clientInvocationFuture.complete(exception);
}
use of com.hazelcast.spi.exception.TargetDisconnectedException in project hazelcast by hazelcast.
the class ClientClusterStateTest method testClusterShutdownDuringMapPutAll.
@Test
public void testClusterShutdownDuringMapPutAll() {
warmUpPartitions(instances);
waitAllForSafeState(instances);
HazelcastInstance client = factory.newHazelcastClient();
final IMap<Object, Object> map = client.getMap(randomMapName());
final HashMap values = new HashMap<Double, Double>();
for (int i = 0; i < 1000; i++) {
double value = Math.random();
values.put(value, value);
}
final int numThreads = 10;
final CountDownLatch threadsFinished = new CountDownLatch(numThreads);
final CountDownLatch threadsStarted = new CountDownLatch(numThreads);
ExecutorService executor = Executors.newCachedThreadPool();
for (int i = 0; i < numThreads; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
ILogger logger = Logger.getLogger(getClass());
threadsStarted.countDown();
logger.info("putAll thread started");
while (true) {
try {
map.putAll(values);
Thread.sleep(100);
} catch (IllegalStateException e) {
logger.warning("Expected exception for Map putAll during cluster shutdown:", e);
break;
} catch (TargetDisconnectedException e) {
logger.warning("Expected exception for Map putAll during cluster shutdown:", e);
break;
} catch (InterruptedException e) {
// do nothing
}
}
threadsFinished.countDown();
logger.info("putAll thread finishing. Current finished thread count is:" + (numThreads - threadsFinished.getCount()));
}
});
}
try {
assertTrue("All threads could not be started", threadsStarted.await(1, TimeUnit.MINUTES));
} catch (InterruptedException e) {
fail("All threads could not be started due to InterruptedException. Could not start " + threadsStarted.getCount() + " threads out of " + numThreads);
}
instance.getCluster().shutdown();
executor.shutdown();
try {
assertTrue("All threads could not be finished", threadsFinished.await(2, TimeUnit.MINUTES));
} catch (InterruptedException e) {
fail("All threads could not be finished due to InterruptedException. Could not finish " + threadsFinished.getCount() + " threads out of " + numThreads);
} finally {
executor.shutdownNow();
}
}
Aggregations