Search in sources :

Example 16 with ComputeTask

use of org.apache.ignite.compute.ComputeTask in project ignite by apache.

the class GridP2PRemoteClassLoadersSelfTest method processTestDifferentRemoteClassLoader.

/**
 * @param depMode deployment mode.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void processTestDifferentRemoteClassLoader(DeploymentMode depMode) throws Exception {
    try {
        this.depMode = depMode;
        GridP2PTestStaticVariable.staticVar = 0;
        Ignite ignite1 = startGrid(1);
        startGrid(2);
        waitForRemoteNodes(ignite1, 1);
        ClassLoader tstClsLdr1 = new GridTestClassLoader(Collections.EMPTY_MAP, getClass().getClassLoader(), GridP2PRemoteTestTask.class.getName(), GridP2PRemoteTestJob.class.getName());
        ClassLoader tstClsLdr2 = new GridTestClassLoader(Collections.EMPTY_MAP, getClass().getClassLoader(), GridP2PRemoteTestTask1.class.getName(), GridP2PRemoteTestJob.class.getName());
        Class<? extends ComputeTask<?, ?>> task1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr1.loadClass(GridP2PRemoteTestTask.class.getName());
        Class<? extends ComputeTask<?, ?>> task2 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr2.loadClass(GridP2PRemoteTestTask1.class.getName());
        Object res1 = ignite1.compute().execute(task1.newInstance(), null);
        Object res2 = ignite1.compute().execute(task2.newInstance(), null);
        info("Check results.");
        // One remote p2p class loader
        assert res1 != null : "res1 != null";
        assert res1 instanceof Long : "res1 instanceof Long != true";
        assert res1.equals(0L) : "Invalid res2 value: " + res1;
        // Another remote p2p class loader.
        assert res2 != null : "res2 == null";
        assert res2 instanceof Long : "res2 instanceof Long != true";
        assert res2.equals(0L) : "Invalid res2 value: " + res2;
        info("Tests passed.");
    } finally {
        stopGrid(2);
        stopGrid(1);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) Ignite(org.apache.ignite.Ignite)

Example 17 with ComputeTask

use of org.apache.ignite.compute.ComputeTask in project ignite by apache.

the class IgniteExplicitImplicitDeploymentSelfTest method execExplicitDeployP2P.

/**
 * @param byCls If {@code true} than executes task by Class.
 * @param byTask If {@code true} than executes task instance.
 * @param byName If {@code true} than executes task by class name.
 * @throws Exception If test failed.
 */
@SuppressWarnings("unchecked")
private void execExplicitDeployP2P(boolean byCls, boolean byTask, boolean byName) throws Exception {
    Ignite ignite1 = null;
    Ignite ignite2 = null;
    try {
        ignite1 = startGrid(1);
        ignite2 = startGrid(2);
        ClassLoader ldr1 = new GridTestClassLoader(Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), GridDeploymentResourceTestTask.class.getName(), GridDeploymentResourceTestJob.class.getName());
        ClassLoader ldr2 = new GridTestClassLoader(Collections.singletonMap("testResource", "2"), getClass().getClassLoader(), GridDeploymentResourceTestTask.class.getName(), GridDeploymentResourceTestJob.class.getName());
        Class<? extends ComputeTask<String, Integer>> taskCls = (Class<? extends ComputeTask<String, Integer>>) ldr2.loadClass(GridDeploymentResourceTestTask.class.getName());
        if (byCls) {
            ignite1.compute().localDeployTask(taskCls, ldr1);
            // Even though the task is deployed with resource class loader,
            // when we execute it, it will be redeployed with task class-loader.
            Integer res = ignite1.compute().execute(taskCls, null);
            assert res != null;
            assert res == 2 : "Invalid response: " + res;
        }
        if (byTask) {
            ignite1.compute().localDeployTask(taskCls, ldr1);
            // Even though the task is deployed with resource class loader,
            // when we execute it, it will be redeployed with task class-loader.
            Integer res = ignite1.compute().execute(taskCls.newInstance(), null);
            assert res != null;
            assert res == 2 : "Invalid response: " + res;
        }
        if (byName) {
            ignite1.compute().localDeployTask(taskCls, ldr1);
            // Even though the task is deployed with resource class loader,
            // when we execute it, it will be redeployed with task class-loader.
            Integer res = (Integer) ignite1.compute().execute(taskCls.getName(), null);
            assert res != null;
            assert res == 1 : "Invalid response: " + res;
        }
    } finally {
        stopGrid(ignite2);
        stopGrid(ignite1);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) Ignite(org.apache.ignite.Ignite)

Example 18 with ComputeTask

use of org.apache.ignite.compute.ComputeTask 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)

Example 19 with ComputeTask

use of org.apache.ignite.compute.ComputeTask in project ignite by apache.

the class P2PGridifySelfTest method processTestBothNodesDeploy.

/**
 * @param depMode deployment mode.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void processTestBothNodesDeploy(DeploymentMode depMode) throws Exception {
    int res = 0;
    try {
        this.depMode = depMode;
        Ignite ignite1 = startGrid(1);
        startGrid(2);
        GridTestClassLoader tstClsLdr = new GridTestClassLoader(Collections.singletonMap("org/apache/ignite/p2p/p2p.properties", "resource=loaded"), getClass().getClassLoader(), GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName());
        Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr.loadClass(GridP2PTestTask.class.getName());
        ignite1.compute().localDeployTask(taskCls1, taskCls1.getClassLoader());
        res = executeGridify(1);
        ignite1.compute().undeployTask(taskCls1.getName());
    } finally {
        stopGrid(2);
        stopGrid(1);
    }
    // P2P deployment
    assert res == 10 : "Invalid gridify result: " + res;
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) Ignite(org.apache.ignite.Ignite)

Example 20 with ComputeTask

use of org.apache.ignite.compute.ComputeTask in project ignite by apache.

the class GridP2PHotRedeploymentSelfTest method processTestClassLoaderHotRedeployment.

/**
 * @param depMode deployment mode.
 * @throws Exception If failed.
 */
private void processTestClassLoaderHotRedeployment(DeploymentMode depMode) throws Exception {
    try {
        this.depMode = depMode;
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        waitForDiscovery(ignite1, ignite2);
        ClassLoader ldr1 = getExternalClassLoader();
        ClassLoader ldr2 = getExternalClassLoader();
        Class<? extends ComputeTask<Object, Integer>> taskCls1 = (Class<? extends ComputeTask<Object, Integer>>) ldr1.loadClass(TASK_NAME);
        Class<? extends ComputeTask<Object, Integer>> taskCls2 = (Class<? extends ComputeTask<Object, Integer>>) ldr2.loadClass(TASK_NAME);
        // Check that different instances used.
        assert taskCls1.getClassLoader() != taskCls2.getClassLoader();
        assert taskCls1 != taskCls2;
        // final AtomicBoolean undeployed = new AtomicBoolean(false);
        // 
        // grid2.events().localListen(new GridLocalEventListener() {
        // @Override public void onEvent(GridEvent evt) {
        // if (evt.type() == EVT_TASK_UNDEPLOYED) {
        // assert ((GridDeploymentEvent)evt).alias().equals(TASK_NAME);
        // 
        // undeployed.set(true);
        // }
        // }
        // }, EVT_TASK_UNDEPLOYED);
        ignite2.compute().localDeployTask(taskCls1, taskCls1.getClassLoader());
        Integer res1 = ignite1.compute().execute(taskCls1, Collections.singletonList(ignite2.cluster().localNode().id()));
        assert res1 != null;
        info("Result1: " + res1);
        Integer res2 = ignite1.compute().execute(taskCls2, Collections.singletonList(ignite2.cluster().localNode().id()));
        assert res2 != null;
        info("Result2: " + res2);
        assert !res1.equals(res2);
    // Thread.sleep(P2P_TIMEOUT * 2);
    // 
    // assert undeployed.get();
    } finally {
        stopGrid(2);
        stopGrid(1);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) Ignite(org.apache.ignite.Ignite)

Aggregations

ComputeTask (org.apache.ignite.compute.ComputeTask)25 Ignite (org.apache.ignite.Ignite)17 GridTestClassLoader (org.apache.ignite.testframework.GridTestClassLoader)14 URLClassLoader (java.net.URLClassLoader)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 Map (java.util.Map)2 ComputeJob (org.apache.ignite.compute.ComputeJob)2 ComputeTaskFuture (org.apache.ignite.compute.ComputeTaskFuture)2 LocalDeploymentSpi (org.apache.ignite.spi.deployment.local.LocalDeploymentSpi)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1