Search in sources :

Example 1 with GridTestExternalClassLoader

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

the class GridAffinityP2PSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings({ "unchecked" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setDiscoverySpi(disco);
    c.setFailureDetectionTimeout(Integer.MAX_VALUE);
    c.setDeploymentMode(depMode);
    if (igniteInstanceName.endsWith("1"))
        // Empty cache configuration.
        c.setCacheConfiguration();
    else {
        assert igniteInstanceName.endsWith("2") || igniteInstanceName.endsWith("3");
        CacheConfiguration cc = defaultCacheConfiguration();
        cc.setCacheMode(PARTITIONED);
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(URLS);
        cc.setAffinity((AffinityFunction) ldr.loadClass(EXT_AFFINITY_CLS_NAME).newInstance());
        cc.setAffinityMapper((AffinityKeyMapper) ldr.loadClass(EXT_AFFINITY_MAPPER_CLS_NAME).newInstance());
        c.setCacheConfiguration(cc);
        c.setUserAttributes(F.asMap(GridCacheModuloAffinityFunction.IDX_ATTR, igniteInstanceName.endsWith("2") ? 0 : 1));
    }
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 2 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 3 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 4 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 5 with GridTestExternalClassLoader

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

the class GridP2PUserVersionChangeSelfTest method testRedeployOnNodeRestartContinuousMode.

/**
     * @throws Exception If failed.
     */
public void testRedeployOnNodeRestartContinuousMode() throws Exception {
    depMode = DeploymentMode.CONTINUOUS;
    try {
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) });
        Class task1 = ldr.loadClass(TEST_TASK_NAME);
        final CountDownLatch undeployed = new CountDownLatch(1);
        ignite2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (evt.type() == EVT_TASK_UNDEPLOYED && ((DeploymentEvent) evt).alias().equals(TEST_TASK_NAME))
                    undeployed.countDown();
                return true;
            }
        }, EVT_TASK_UNDEPLOYED);
        Integer res1 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        stopGrid(1);
        ignite1 = startGrid(1);
        Integer res2 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        assert !undeployed.await(3000, MILLISECONDS);
        assert res1.equals(res2);
    } finally {
        stopGrid(1);
        stopGrid(2);
    }
}
Also used : GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Event(org.apache.ignite.events.Event) DeploymentEvent(org.apache.ignite.events.DeploymentEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL)

Aggregations

GridTestExternalClassLoader (org.apache.ignite.testframework.GridTestExternalClassLoader)10 Ignite (org.apache.ignite.Ignite)8 URL (java.net.URL)7 Event (org.apache.ignite.events.Event)4 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