use of com.hazelcast.core.OperationTimeoutException in project hazelcast by hazelcast.
the class LockOperation method onWaitExpire.
@Override
public final void onWaitExpire() {
Object response;
long timeout = getWaitTimeout();
if (timeout < 0 || timeout == Long.MAX_VALUE) {
response = new OperationTimeoutException();
} else {
response = Boolean.FALSE;
}
sendResponse(response);
}
use of com.hazelcast.core.OperationTimeoutException in project hazelcast by hazelcast.
the class InvocationFuture method newOperationTimeoutException.
private Object newOperationTimeoutException(boolean heartbeatTimeout) {
StringBuilder sb = new StringBuilder();
if (heartbeatTimeout) {
sb.append(invocation.op.getClass().getSimpleName()).append(" invocation failed to complete due to operation-heartbeat-timeout. ");
sb.append("Current time: ").append(timeToString(currentTimeMillis())).append(". ");
sb.append("Start time: ").append(timeToString(invocation.firstInvocationTimeMillis)).append(". ");
sb.append("Total elapsed time: ").append(currentTimeMillis() - invocation.firstInvocationTimeMillis).append(" ms. ");
long lastHeartbeatMillis = invocation.lastHeartbeatMillis;
sb.append("Last operation heartbeat: ");
appendHeartbeat(sb, lastHeartbeatMillis);
long lastHeartbeatFromMemberMillis = invocation.context.invocationMonitor.getLastMemberHeartbeatMillis(invocation.invTarget);
sb.append("Last operation heartbeat from member: ");
appendHeartbeat(sb, lastHeartbeatFromMemberMillis);
} else {
sb.append(invocation.op.getClass().getSimpleName()).append(" got rejected before execution due to not starting within the operation-call-timeout of: ").append(invocation.callTimeoutMillis).append(" ms. ");
sb.append("Current time: ").append(timeToString(currentTimeMillis())).append(". ");
sb.append("Start time: ").append(timeToString(invocation.firstInvocationTimeMillis)).append(". ");
sb.append("Total elapsed time: ").append(currentTimeMillis() - invocation.firstInvocationTimeMillis).append(" ms. ");
}
sb.append(invocation);
String msg = sb.toString();
return new ExecutionException(msg, new OperationTimeoutException(msg));
}
use of com.hazelcast.core.OperationTimeoutException in project hazelcast by hazelcast.
the class OperationServiceImpl_timeoutTest method testOperationTimeout.
private void testOperationTimeout(int memberCount, boolean async) {
assertTrue(memberCount > 0);
Config config = new Config();
config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(memberCount);
HazelcastInstance[] instances = factory.newInstances(config);
warmUpPartitions(instances);
final HazelcastInstance hz = instances[memberCount - 1];
Node node = TestUtil.getNode(hz);
NodeEngine nodeEngine = node.nodeEngine;
OperationService operationService = nodeEngine.getOperationService();
int partitionId = (int) (Math.random() * node.getPartitionService().getPartitionCount());
InternalCompletableFuture<Object> future = operationService.invokeOnPartition(null, new TimedOutBackupAwareOperation(), partitionId);
final CountDownLatch latch = new CountDownLatch(1);
if (async) {
future.andThen(new ExecutionCallback<Object>() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
if (t instanceof OperationTimeoutException) {
latch.countDown();
}
}
});
} else {
try {
future.join();
fail("Should throw OperationTimeoutException!");
} catch (OperationTimeoutException ignored) {
latch.countDown();
}
}
assertOpenEventually("Should throw OperationTimeoutException", latch);
for (HazelcastInstance instance : instances) {
OperationServiceImpl_BasicTest.assertNoLitterInOpService(instance);
}
}
use of com.hazelcast.core.OperationTimeoutException in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_whenHeartbeatTimeout.
// ============================ heartbeat timeout =============================================================================
//
// ===========================================================================================================================
@Test
public void sync_whenHeartbeatTimeout() {
int callTimeout = 5000;
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance(config);
HazelcastInstance remote = factory.newHazelcastInstance(config);
warmUpPartitions(factory.getAllHazelcastInstances());
NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
String key = generateKeyOwnedBy(remote);
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
// first we execute an operation that stall the partition.
InternalOperationService opService = nodeEngine.getOperationService();
opService.invokeOnPartition(null, new SlowOperation(5 * callTimeout), partitionId);
// then we execute a lock operation that won't be executed because the partition is blocked.
LockOperation op = new LockOperation(new InternalLockNamespace(key), nodeEngine.toData(key), 1, -1, -1);
InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, op, partitionId).setCallTimeout(callTimeout).invoke();
try {
future.join();
fail("Invocation should failed with timeout!");
} catch (OperationTimeoutException expected) {
ignore(expected);
}
IsLockedOperation isLockedOperation = new IsLockedOperation(new InternalLockNamespace(key), nodeEngine.toData(key), 1);
Boolean isLocked = (Boolean) opService.createInvocationBuilder(null, isLockedOperation, partitionId).setCallTimeout(10 * callTimeout).invoke().join();
assertFalse(isLocked);
}
use of com.hazelcast.core.OperationTimeoutException in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_testWaitingIndefinitely.
@Test
public void sync_testWaitingIndefinitely() throws InterruptedException {
final Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance[] instances = factory.newInstances(config);
// need to warm-up partitions, since waiting for lock backup can take up to 5 seconds
// and that may cause OperationTimeoutException with "No response for 4000 ms" error
warmUpPartitions(instances);
final String name = randomName();
ILock lock = instances[0].getLock(name);
lock.lock();
final CountDownLatch latch = new CountDownLatch(1);
new Thread() {
public void run() {
try {
// because max timeout=3000 we get timeout exception which we should not
instances[1].getLock(name).lock();
latch.countDown();
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}.start();
// wait for enough time which is greater than max-timeout (3000)
sleepSeconds(10);
lock.unlock();
assertTrue(latch.await(20, SECONDS));
}
Aggregations