Search in sources :

Example 11 with GridTestClassLoader

use of org.apache.ignite.testframework.GridTestClassLoader 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 12 with GridTestClassLoader

use of org.apache.ignite.testframework.GridTestClassLoader in project ignite by apache.

the class GridP2PUndeploySelfTest method processTestUndeployLocalTasks.

/**
     * @param depMode deployment mode.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
private void processTestUndeployLocalTasks(DeploymentMode depMode) throws Exception {
    try {
        this.depMode = depMode;
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        ClassLoader tstClsLdr = new GridTestClassLoader(GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName());
        Class<? extends ComputeTask<?, ?>> task1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr.loadClass(GridP2PTestTask.class.getName());
        ignite1.compute().localDeployTask(task1, tstClsLdr);
        ignite1.compute().execute(task1.getName(), 1);
        ignite2.compute().localDeployTask(task1, tstClsLdr);
        ignite2.compute().execute(task1.getName(), 2);
        LocalDeploymentSpi spi1 = spis.get(ignite1.name());
        LocalDeploymentSpi spi2 = spis.get(ignite2.name());
        assert spi1.findResource(task1.getName()) != null;
        assert spi2.findResource(task1.getName()) != null;
        assert ignite1.compute().localTasks().containsKey(task1.getName());
        assert ignite2.compute().localTasks().containsKey(task1.getName());
        ignite2.compute().undeployTask(task1.getName());
        // Wait for undeploy.
        Thread.sleep(1000);
        assert spi1.findResource(task1.getName()) == null;
        assert spi2.findResource(task1.getName()) == null;
        assert !ignite1.compute().localTasks().containsKey(task1.getName());
        assert !ignite2.compute().localTasks().containsKey(task1.getName());
    } 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) URLClassLoader(java.net.URLClassLoader) Ignite(org.apache.ignite.Ignite) LocalDeploymentSpi(org.apache.ignite.spi.deployment.local.LocalDeploymentSpi)

Example 13 with GridTestClassLoader

use of org.apache.ignite.testframework.GridTestClassLoader 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 14 with GridTestClassLoader

use of org.apache.ignite.testframework.GridTestClassLoader 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 15 with GridTestClassLoader

use of org.apache.ignite.testframework.GridTestClassLoader in project ignite by apache.

the class MarshallerContextLockingSelfTest method testMultithreadedUpdate.

/**
     * Multithreaded test, used custom class loader
     */
public void testMultithreadedUpdate() throws Exception {
    multithreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            GridTestClassLoader classLoader = new GridTestClassLoader(InternalExecutor.class.getName(), MarshallerContextImpl.class.getName(), MarshallerContextImpl.CombinedMap.class.getName(), MappingStoreTask.class.getName(), MarshallerMappingFileStore.class.getName(), MarshallerMappingTransport.class.getName());
            Thread.currentThread().setContextClassLoader(classLoader);
            Class clazz = classLoader.loadClass(InternalExecutor.class.getName());
            Object internelExecutor = clazz.newInstance();
            clazz.getMethod("executeTest", GridTestLog4jLogger.class, GridKernalContext.class).invoke(internelExecutor, log, ctx);
            return null;
        }
    }, THREADS);
    final CountDownLatch arrive = new CountDownLatch(THREADS);
    // Wait for all pending tasks in closure processor to complete.
    for (int i = 0; i < THREADS; i++) {
        ctx.closure().runLocalSafe(new GridPlainRunnable() {

            @Override
            public void run() {
                arrive.countDown();
                try {
                    arrive.await();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new IgniteInterruptedException(e);
                }
            }
        }, true);
    }
    arrive.await();
    assertTrue(InternalExecutor.counter.get() == 0);
    assertTrue(!innerLog.contains("Exception"));
    assertTrue(innerLog.contains("File already locked"));
}
Also used : GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable)

Aggregations

GridTestClassLoader (org.apache.ignite.testframework.GridTestClassLoader)15 ComputeTask (org.apache.ignite.compute.ComputeTask)13 Ignite (org.apache.ignite.Ignite)11 CountDownLatch (java.util.concurrent.CountDownLatch)2 ComputeTaskFuture (org.apache.ignite.compute.ComputeTaskFuture)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URLClassLoader (java.net.URLClassLoader)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeJob (org.apache.ignite.compute.ComputeJob)1 Gridify (org.apache.ignite.compute.gridify.Gridify)1 Event (org.apache.ignite.events.Event)1 GridPlainRunnable (org.apache.ignite.internal.util.lang.GridPlainRunnable)1 GridP2PTestJob (org.apache.ignite.p2p.GridP2PTestJob)1 GridP2PTestTask (org.apache.ignite.p2p.GridP2PTestTask)1 LocalDeploymentSpi (org.apache.ignite.spi.deployment.local.LocalDeploymentSpi)1