use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class GridContinuousTaskSelfTest method testContinuousJobsChainMultiThreaded.
/**
* @throws Exception If test failed.
*/
public void testContinuousJobsChainMultiThreaded() throws Exception {
try {
final Ignite ignite = startGrid(0);
startGrid(1);
GridTestUtils.runMultiThreaded(new Runnable() {
/** {@inheritDoc} */
@Override
public void run() {
try {
ComputeTaskFuture<Integer> fut1 = ignite.compute().executeAsync(TestJobsChainTask.class, true);
ComputeTaskFuture<Integer> fut2 = ignite.compute().executeAsync(TestJobsChainTask.class, false);
assert fut1.get() == 55;
assert fut2.get() == 55;
} catch (IgniteException e) {
assert false : "Test task failed: " + e;
}
}
}, THREAD_COUNT, "continuous-jobs-chain");
} finally {
stopGrid(0);
stopGrid(1);
}
}
use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class GridMultipleVersionsDeploymentSelfTest method testMultipleVersionsLocalDeploy.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings("unchecked")
public void testMultipleVersionsLocalDeploy() throws Exception {
try {
Ignite ignite = startGrid(1);
ClassLoader ldr1 = new GridTestClassLoader(Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), EXCLUDE_CLASSES);
ClassLoader ldr2 = new GridTestClassLoader(Collections.singletonMap("testResource", "2"), getClass().getClassLoader(), EXCLUDE_CLASSES);
Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>) ldr1.loadClass(GridDeploymentTestTask.class.getName());
Class<? extends ComputeTask<?, ?>> taskCls2 = (Class<? extends ComputeTask<?, ?>>) ldr2.loadClass(GridDeploymentTestTask.class.getName());
ignite.compute().localDeployTask(taskCls1, ldr1);
// Task will wait for the signal.
ComputeTaskFuture fut = executeAsync(ignite.compute(), "GridDeploymentTestTask", null);
// We should wait here when to be sure that job has been started.
// Since we loader task/job classes with different class loaders we cannot
// use any kind of mutex because of the illegal state exception.
// We have to use timer here. DO NOT CHANGE 2 seconds. This should be enough
// on Bamboo.
Thread.sleep(2000);
assert checkDeployed(ignite, "GridDeploymentTestTask");
// Deploy new one - this should move first task to the obsolete list.
ignite.compute().localDeployTask(taskCls2, ldr2);
boolean deployed = checkDeployed(ignite, "GridDeploymentTestTask");
Object res = fut.get();
ignite.compute().undeployTask("GridDeploymentTestTask");
// New one should be deployed.
assert deployed;
// Wait for the execution.
assert res.equals(1);
} finally {
stopGrid(1);
}
}
Aggregations