use of org.apache.ignite.lang.IgniteFutureCancelledException in project ignite by apache.
the class GridTaskCancelSingleNodeSelfTest method checkCancellation.
/**
* @param timeoutBeforeCancel Timeout.
* @throws Exception If failed.
*/
@SuppressWarnings("ErrorNotRethrown")
private void checkCancellation(long timeoutBeforeCancel) throws Exception {
final AtomicInteger finished = new AtomicInteger();
final AtomicInteger cancelled = new AtomicInteger();
final AtomicInteger rejected = new AtomicInteger();
final AtomicBoolean jobStarted = new AtomicBoolean();
grid().events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
info("Received event: " + evt);
switch(evt.type()) {
case EVT_JOB_STARTED:
jobStarted.set(true);
break;
case EVT_JOB_FINISHED:
finished.incrementAndGet();
break;
case EVT_JOB_CANCELLED:
cancelled.incrementAndGet();
break;
case EVT_JOB_REJECTED:
rejected.incrementAndGet();
break;
default:
assert false : "Unexpected event: " + evt;
}
return true;
}
}, EVT_JOB_STARTED, EVT_JOB_FINISHED, EVT_JOB_CANCELLED, EVT_JOB_REJECTED);
ComputeTaskFuture<?> fut = grid().compute().executeAsync(TestTask.class, null);
if (timeoutBeforeCancel > 0L)
Thread.sleep(timeoutBeforeCancel);
assert fut.cancel();
for (int i = 0; i < 3; i++) {
try {
if (timeoutBeforeCancel == 0L) {
if (jobStarted.get())
assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get() + ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']', finished.get() == 1 && cancelled.get() == 1 && rejected.get() == 0);
else {
// job can be rejected if was concurrently cancelled before started
assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get() + ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']', finished.get() == 0 && cancelled.get() == 0 && rejected.get() <= 1);
}
} else
assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get() + ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']', finished.get() == 1 && cancelled.get() == 1 && rejected.get() == 0);
} catch (AssertionError e) {
info("Check failed: " + e.getMessage());
if (timeoutBeforeCancel == 0L && i == 2)
throw e;
}
if (i < 2)
U.sleep(500);
}
try {
fut.get();
fail();
} catch (IgniteFutureCancelledException e) {
info("Caught expected exception: " + e);
}
}
use of org.apache.ignite.lang.IgniteFutureCancelledException in project ignite by apache.
the class DataStreamProcessorSelfTest method testLoaderApi.
/**
* @throws Exception If failed.
*/
public void testLoaderApi() throws Exception {
useCache = true;
try {
Ignite g1 = startGrid(1);
IgniteDataStreamer<Object, Object> ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
ldr.close(false);
try {
ldr.addData(0, 0);
assert false;
} catch (IllegalStateException e) {
info("Caught expected exception: " + e);
}
assert ldr.future().isDone();
ldr.future().get();
try {
// Create another loader.
ldr = g1.dataStreamer("UNKNOWN_CACHE");
assert false;
} catch (IllegalStateException e) {
info("Caught expected exception: " + e);
}
ldr.close(true);
assert ldr.future().isDone();
ldr.future().get();
// Create another loader.
ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
// Cancel with future.
ldr.future().cancel();
try {
ldr.addData(0, 0);
assert false;
} catch (IllegalStateException e) {
info("Caught expected exception: " + e);
}
assert ldr.future().isDone();
try {
ldr.future().get();
assert false;
} catch (IgniteFutureCancelledException e) {
info("Caught expected exception: " + e);
}
// Create another loader.
ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
// This will close loader.
stopGrid(getTestIgniteInstanceName(1), false);
try {
ldr.addData(0, 0);
assert false;
} catch (IllegalStateException e) {
info("Caught expected exception: " + e);
}
assert ldr.future().isDone();
ldr.future().get();
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.lang.IgniteFutureCancelledException 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);
}
});
return m;
}
Aggregations