Search in sources :

Example 16 with ComputeTaskFuture

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);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Ignite(org.apache.ignite.Ignite)

Example 17 with ComputeTaskFuture

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);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) Ignite(org.apache.ignite.Ignite)

Aggregations

Ignite (org.apache.ignite.Ignite)17 ComputeTaskFuture (org.apache.ignite.compute.ComputeTaskFuture)17 IgniteException (org.apache.ignite.IgniteException)9 GridLoadTestStatistics (org.apache.ignite.loadtest.GridLoadTestStatistics)7 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteCompute (org.apache.ignite.IgniteCompute)2 ComputeTask (org.apache.ignite.compute.ComputeTask)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 GridTestClassLoader (org.apache.ignite.testframework.GridTestClassLoader)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1