use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.
the class GridJobCollisionCancelSelfTest method testCancel.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "AssignmentToCatchBlockParameter" })
@Test
public void testCancel() throws Exception {
Ignite ignite = G.ignite(getTestIgniteInstanceName());
ignite.compute().localDeployTask(GridCancelTestTask.class, GridCancelTestTask.class.getClassLoader());
ComputeTaskFuture<?> res0 = executeAsync(ignite.compute().withTimeout(maxJobExecTime * 2), GridCancelTestTask.class.getName(), null);
try {
Object res = res0.get();
info("Cancel test result: " + res);
synchronized (mux) {
// Every execute must be called.
assert execCnt <= SPLIT_COUNT : "Invalid execute count: " + execCnt;
// Job returns 1 if was cancelled.
assert (Integer) res <= SPLIT_COUNT : "Invalid task result: " + res;
// Should be exactly the same as Jobs number.
assert cancelCnt <= SPLIT_COUNT : "Invalid cancel count: " + cancelCnt;
// One per start and one per stop and some that come with metrics update.
assert colResolutionCnt > SPLIT_COUNT + 1 : "Invalid collision resolution count: " + colResolutionCnt;
}
} catch (ComputeTaskTimeoutException e) {
error("Task execution got timed out.", e);
} catch (Exception e) {
assert e.getCause() != null;
if (e.getCause() instanceof IgniteCheckedException)
e = (Exception) e.getCause();
if (e.getCause() instanceof IOException)
e = (Exception) e.getCause();
assert e.getCause() instanceof InterruptedException : "Invalid exception cause: " + e.getCause();
}
}
use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.
the class ComputeTaskRemoteSecurityContextTest method doNodeTest.
/**
*/
public void doNodeTest(boolean isClient) throws Exception {
String login = isClient ? "cli" : "srv";
IgniteEx ignite = grid(login);
IgniteCompute compute = ignite.compute(ignite.cluster().forNodes(ignite.cluster().nodes()));
if (failWithTimeout)
compute.withTimeout(TEST_TASK_TIMEOUT);
String taskName = mapAsync ? MapAsyncTestTask.class.getName() : TestTask.class.getName();
ComputeTaskTimeoutException timeoutE = null;
try {
if (async)
compute.executeAsync(taskName, login).get();
else
compute.execute(taskName, login);
checkTaskEvents(login, login, REDUCER_SUCCEEDED_TASK_EVENTS, MAP_NODE_SUCCEEDED_TASK_EVENTS);
} catch (ComputeTaskTimeoutException e) {
if (!failWithTimeout)
throw e;
timeoutE = e;
}
if (failWithTimeout) {
assertNotNull(timeoutE);
checkTaskEvents(login, login, REDUCER_FAILED_TASK_EVENTS, MAP_NODE_FAILED_TASK_EVENTS);
}
}
use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.
the class GridTaskTimeoutSelfTest method testSynchronousTimeoutMultithreaded.
/**
* @throws Exception If failed.
*/
@Test
public void testSynchronousTimeoutMultithreaded() throws Exception {
final Ignite ignite = G.ignite(getTestIgniteInstanceName());
final AtomicBoolean finish = new AtomicBoolean();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch finishLatch = new CountDownLatch(N_THREADS);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(PERIOD);
info("Stopping test.");
finish.set(true);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}
}).start();
multithreaded(new Runnable() {
@Override
public void run() {
while (!finish.get()) {
try {
ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null);
fut.get();
assert false : "Task has not been timed out. Future: " + fut;
} catch (ComputeTaskTimeoutException ignored) {
// Expected.
} catch (IgniteCheckedException e) {
// shouldn't happen
throw new IllegalStateException(e);
} finally {
int cnt0 = cnt.incrementAndGet();
if (cnt0 % 100 == 0)
info("Tasks finished: " + cnt0);
}
}
info("Thread " + Thread.currentThread().getId() + " finishing.");
finishLatch.countDown();
}
}, N_THREADS);
finishLatch.await();
// Grid will be stopped automatically on tearDown().
}
use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.
the class IgniteUtils method exceptionConverters.
/**
* Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
*
* @return Exception converters.
*/
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
}
});
m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureCancelledException(e.getMessage(), e);
}
});
m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureTimeoutException(e.getMessage(), e);
}
});
m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ClusterGroupEmptyException(e.getMessage(), e);
}
});
m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
if (checked.retryReadyFuture() != null)
topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
return topEx;
}
});
m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteDeploymentException(e.getMessage(), e);
}
});
m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskTimeoutException(e.getMessage(), e);
}
});
m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskCancelledException(e.getMessage(), e);
}
});
m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionRollbackException(e.getMessage(), e);
}
});
m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionHeuristicException(e.getMessage(), e);
}
});
m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
if (e.getCause() instanceof TransactionDeadlockException)
return new TransactionTimeoutException(e.getMessage(), e.getCause());
return new TransactionTimeoutException(e.getMessage(), e);
}
});
m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionOptimisticException(e.getMessage(), e);
}
});
m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
}
});
m.put(IgniteTxSerializationCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionSerializationException(e.getMessage(), e);
}
});
m.put(IgniteTxDuplicateKeyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionDuplicateKeyException(e.getMessage(), e);
}
});
m.put(IgniteTxAlreadyCompletedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionAlreadyCompletedException(e.getMessage(), e);
}
});
return m;
}
use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.
the class GridTaskTimeoutSelfTest method testSynchronousTimeout.
/**
* @throws Exception If failed.
*/
@Test
public void testSynchronousTimeout() throws Exception {
Ignite ignite = G.ignite(getTestIgniteInstanceName());
ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader());
ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null);
try {
fut.get();
assert false : "ComputeTaskTimeoutException was not thrown (synchronous apply)";
} catch (ComputeTaskTimeoutException e) {
info("Received expected timeout exception (synchronous apply): " + e);
}
Thread.sleep(TIMEOUT + 500);
checkTimedOutEvents(fut.getTaskSession().getId());
}
Aggregations