Search in sources :

Example 6 with GridTestExternalClassLoader

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

the class GridP2PDifferentClassLoaderSelfTest method processTest.

/**
 * Test.
 * @param isSameTask whether load same task or different task
 * @param expectEquals whether expected
 * @throws Exception if error occur
 */
@SuppressWarnings({ "ObjectEquality", "unchecked" })
private void processTest(boolean isSameTask, boolean expectEquals) throws Exception {
    try {
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        Class task1;
        Class task2;
        if (isSameTask) {
            ClassLoader ldr1 = new URLClassLoader(URLS, getClass().getClassLoader());
            ClassLoader ldr2 = new URLClassLoader(URLS, getClass().getClassLoader());
            task1 = ldr1.loadClass(TEST_TASK1_NAME);
            task2 = ldr2.loadClass(TEST_TASK1_NAME);
        } else {
            ClassLoader ldr1 = new GridTestExternalClassLoader(URLS, TEST_TASK2_NAME);
            ClassLoader ldr2 = new GridTestExternalClassLoader(URLS, TEST_TASK1_NAME);
            task1 = ldr1.loadClass(TEST_TASK1_NAME);
            task2 = ldr2.loadClass(TEST_TASK2_NAME);
        }
        // Execute task1 and task2 from node1 on node2 and make sure that they reuse same class loader on node2.
        Integer res1 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        Integer res2 = (Integer) ignite1.compute().execute(task2, ignite2.cluster().localNode().id());
        if (expectEquals)
            assert res1.equals(res2);
        else
            assert !res1.equals(res2);
    } finally {
        stopGrid(1);
        stopGrid(2);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Ignite(org.apache.ignite.Ignite)

Example 7 with GridTestExternalClassLoader

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

the class GridP2PTimeoutSelfTest method processTest.

/**
 * @param depMode deployment mode.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void processTest(DeploymentMode depMode) throws Exception {
    this.depMode = depMode;
    try {
        Ignite g1 = startGrid(1);
        Ignite g2 = startGrid(2);
        String path = GridTestProperties.getProperty("p2p.uri.cls");
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(path) });
        Class task1 = ldr.loadClass("org.apache.ignite.tests.p2p.P2PTestTaskExternalPath1");
        Class task2 = ldr.loadClass("org.apache.ignite.tests.p2p.P2PTestTaskExternalPath2");
        ldr.setTimeout(100);
        g1.compute().execute(task1, g2.cluster().localNode().id());
        ldr.setTimeout(2000);
        try {
            g1.compute().execute(task2, g2.cluster().localNode().id());
            // Timeout exception must be thrown.
            assert false;
        } catch (IgniteException ignored) {
        // Throwing exception is a correct behaviour.
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Ignite(org.apache.ignite.Ignite) URL(java.net.URL)

Example 8 with GridTestExternalClassLoader

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

the class GridP2PTimeoutSelfTest method processFilterTest.

/**
 * @param depMode deployment mode.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void processFilterTest(DeploymentMode depMode) throws Exception {
    this.depMode = depMode;
    try {
        Ignite ignite = startGrid(1);
        startGrid(2);
        // Create events.
        ignite.compute().execute(GridP2PTestTask.class, 777);
        String path = GridTestProperties.getProperty("p2p.uri.cls");
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(path) });
        Class filter1 = ldr.loadClass("org.apache.ignite.tests.p2p.GridP2PEventFilterExternalPath1");
        Class filter2 = ldr.loadClass("org.apache.ignite.tests.p2p.GridP2PEventFilterExternalPath2");
        ldr.setTimeout(100);
        ignite.events().remoteQuery((IgnitePredicate<Event>) filter1.newInstance(), 0);
        ldr.setTimeout(2000);
        try {
            ignite.events().remoteQuery((IgnitePredicate<Event>) filter2.newInstance(), 0);
            // Timeout exception must be thrown.
            assert false;
        } catch (IgniteException ignored) {
        // Throwing exception is a correct behaviour.
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) URL(java.net.URL)

Example 9 with GridTestExternalClassLoader

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

the class GridP2PMissedResourceCacheSizeSelfTest method processSize0Test.

/**
 * @param depMode deployment mode.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void processSize0Test(DeploymentMode depMode) throws Exception {
    this.depMode = depMode;
    missedRsrcCacheSize = 0;
    try {
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        String path = GridTestProperties.getProperty("p2p.uri.cls");
        info("Using path: " + path);
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(path) });
        Class task = ldr.loadClass(TASK_NAME1);
        ignite1.compute().localDeployTask(task, task.getClassLoader());
        ldr.setExcludeClassNames(TASK_NAME1);
        executeFail(ignite1, ignite2, task);
        ldr.setExcludeClassNames();
        ignite1.compute().execute(task, ignite2.cluster().localNode().id());
    } finally {
        stopGrid(1);
        stopGrid(2);
    }
}
Also used : GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Ignite(org.apache.ignite.Ignite) URL(java.net.URL)

Example 10 with GridTestExternalClassLoader

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

the class SharedDeploymentTest method testDeploymentFromSecondAndThird.

/**
 * @throws Exception if failed.
 */
public void testDeploymentFromSecondAndThird() throws Exception {
    try {
        startGrid(1);
        final Ignite ignite2 = startGrid(2);
        Ignite ignite3 = startGrid(3);
        Collection<Object> res = runJob0(new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, RUN_CLS1), ignite2, 10_000, 1);
        for (Object o : res) assertEquals(o, 42);
        res = runJob1(new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, RUN_CLS, RUN_CLS2), ignite3, 10_000, 2);
        for (Object o : res) assertEquals(o, 42);
        res = runJob2(new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, RUN_CLS, RUN_CLS1), ignite3, 10_000, 3);
        for (Object o : res) assertEquals(o, 42);
        ignite3.close();
        ignite3 = startGrid(3);
        res = runJob2(new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls.second")) }, RUN_CLS, RUN_CLS1), ignite3, 10_000, 4);
        for (Object o : res) assertEquals(o, 43);
    } finally {
        stopAllGrids();
    }
}
Also used : GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Ignite(org.apache.ignite.Ignite) URL(java.net.URL)

Aggregations

GridTestExternalClassLoader (org.apache.ignite.testframework.GridTestExternalClassLoader)14 URL (java.net.URL)11 Ignite (org.apache.ignite.Ignite)9 Event (org.apache.ignite.events.Event)4 Constructor (java.lang.reflect.Constructor)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 DeploymentEvent (org.apache.ignite.events.DeploymentEvent)3 IgniteException (org.apache.ignite.IgniteException)2 URLClassLoader (java.net.URLClassLoader)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 PAX (org.apache.ignite.internal.util.typedef.PAX)1 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)1 IgniteIgnore (org.apache.ignite.testsuites.IgniteIgnore)1