Search in sources :

Example 6 with ComputeTask

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

the class GridP2PHotRedeploymentSelfTest method processTestHotRedeployment.

/**
     * @param depMode deployment mode.
     * @throws Exception If failed.
     */
private void processTestHotRedeployment(DeploymentMode depMode) throws Exception {
    try {
        this.depMode = depMode;
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        waitForDiscovery(ignite1, ignite2);
        ClassLoader ldr = getExternalClassLoader();
        Class<? extends ComputeTask<Object, Integer>> taskCls = (Class<? extends ComputeTask<Object, Integer>>) ldr.loadClass(TASK_NAME);
        Integer res1 = ignite1.compute().execute(taskCls, Collections.singletonList(ignite2.cluster().localNode().id()));
        info("Result1: " + res1);
        assert res1 != null;
        ignite1.compute().localDeployTask(taskCls, taskCls.getClassLoader());
        Integer res2 = (Integer) ignite1.compute().execute(taskCls.getName(), Collections.singletonList(ignite2.cluster().localNode().id()));
        info("Result2: " + res2);
        assert res2 != null;
        assert res1.equals(res2);
    } finally {
        stopGrid(2);
        stopGrid(1);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) Ignite(org.apache.ignite.Ignite)

Example 7 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 8 with ComputeTask

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

the class GridP2PRemoteClassLoadersSelfTest method processTestSameRemoteClassLoader.

/**
     * @param depMode deployment mode.
     * @throws Exception If failed..
     */
@SuppressWarnings("unchecked")
private void processTestSameRemoteClassLoader(DeploymentMode depMode) throws Exception {
    try {
        this.depMode = depMode;
        GridP2PTestStaticVariable.staticVar = 0;
        Ignite ignite1 = startGrid(1);
        startGrid(2);
        waitForRemoteNodes(ignite1, 1);
        ClassLoader tstClsLdr = new GridTestClassLoader(Collections.<String, String>emptyMap(), getClass().getClassLoader(), GridP2PRemoteTestTask.class.getName(), GridP2PRemoteTestTask1.class.getName(), GridP2PRemoteTestJob.class.getName());
        Class<? extends ComputeTask<?, ?>> task1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr.loadClass(GridP2PRemoteTestTask.class.getName());
        Class<? extends ComputeTask<?, ?>> task2 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr.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) : "Expected 0, got " + res1;
        // The same remote p2p class loader.
        assert res2 != null : "res2 != null";
        assert res2 instanceof Long : "res2 instanceof Long != true";
        assert res2.equals(1L) : "Expected 1 got " + 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 9 with ComputeTask

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

the class GridMultipleVersionsDeploymentSelfTest method testMultipleVersionsP2PDeploy.

/**
     * @throws Exception If test failed.
     */
@SuppressWarnings("unchecked")
public void testMultipleVersionsP2PDeploy() throws Exception {
    try {
        Ignite g1 = startGrid(1);
        Ignite g2 = startGrid(2);
        final CountDownLatch latch = new CountDownLatch(2);
        g2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info("Received event: " + evt);
                latch.countDown();
                return true;
            }
        }, EVT_TASK_UNDEPLOYED);
        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());
        g1.compute().localDeployTask(taskCls1, ldr1);
        // Task will wait for the signal.
        ComputeTaskFuture fut1 = executeAsync(g1.compute(), "GridDeploymentTestTask", null);
        assert checkDeployed(g1, "GridDeploymentTestTask");
        // 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 here.
        Thread.sleep(2000);
        // Deploy new one - this should move first task to the obsolete list.
        g1.compute().localDeployTask(taskCls2, ldr2);
        // Task will wait for the signal.
        ComputeTaskFuture fut2 = executeAsync(g1.compute(), "GridDeploymentTestTask", null);
        boolean deployed = checkDeployed(g1, "GridDeploymentTestTask");
        Object res1 = fut1.get();
        Object res2 = fut2.get();
        g1.compute().undeployTask("GridDeploymentTestTask");
        // New one should be deployed.
        assert deployed;
        // Wait for the execution.
        assert res1.equals(1);
        assert res2.equals(2);
        stopGrid(1);
        assert latch.await(3000, MILLISECONDS);
        assert !checkDeployed(g2, "GridDeploymentTestTask");
    } finally {
        stopGrid(2);
        stopGrid(1);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) CountDownLatch(java.util.concurrent.CountDownLatch) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Event(org.apache.ignite.events.Event) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) Ignite(org.apache.ignite.Ignite)

Example 10 with ComputeTask

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

the class GridMarshallerAbstractTest method testExternalClassesMarshalling.

/**
     * Tests marshal classes
     *
     * @throws Exception If test failed.
     */
public void testExternalClassesMarshalling() throws Exception {
    ClassLoader tstClsLdr = new GridTestClassLoader(Collections.singletonMap("org/apache/ignite/p2p/p2p.properties", "resource=loaded"), getClass().getClassLoader(), GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName());
    ComputeTask<?, ?> inTask = (ComputeTask<?, ?>) tstClsLdr.loadClass(GridP2PTestTask.class.getName()).newInstance();
    byte[] buf = marsh.marshal(inTask);
    ComputeTask<?, ?> outTask = marsh.unmarshal(buf, tstClsLdr);
    assert inTask != outTask;
    assert inTask.getClass().equals(outTask.getClass());
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) GridP2PTestTask(org.apache.ignite.p2p.GridP2PTestTask) GridP2PTestJob(org.apache.ignite.p2p.GridP2PTestJob)

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