Search in sources :

Example 1 with OperationTimeoutException

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);
}
Also used : OperationTimeoutException(com.hazelcast.core.OperationTimeoutException)

Example 2 with OperationTimeoutException

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));
}
Also used : OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) StringUtil.timeToString(com.hazelcast.util.StringUtil.timeToString) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with OperationTimeoutException

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);
    }
}
Also used : OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) CountDownLatch(java.util.concurrent.CountDownLatch) NodeEngine(com.hazelcast.spi.NodeEngine) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 4 with OperationTimeoutException

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);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with OperationTimeoutException

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ILock(com.hazelcast.core.ILock) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)5 Config (com.hazelcast.config.Config)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)1 IsLockedOperation (com.hazelcast.concurrent.lock.operations.IsLockedOperation)1 LockOperation (com.hazelcast.concurrent.lock.operations.LockOperation)1 ILock (com.hazelcast.core.ILock)1 Node (com.hazelcast.instance.Node)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 OperationService (com.hazelcast.spi.OperationService)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)1 StringUtil.timeToString (com.hazelcast.util.StringUtil.timeToString)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1