IGNITE-35 Removed tests on IgniteUserResource resources.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/a1763213 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/a1763213 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/a1763213 Branch: refs/heads/ignite-35 Commit: a1763213c4abb3359440eae381255927c13522f3 Parents: ad57f8e Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Thu Dec 18 15:25:37 2014 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Fri Dec 19 16:29:13 2014 +0300 ---------------------------------------------------------------------- .../resource/GridAbstractUserResource.java | 87 ---- .../GridResourceConcurrentUndeploySelfTest.java | 445 ---------------- .../GridResourceEventFilterSelfTest.java | 163 ------ .../GridResourceFieldInjectionSelfTest.java | 463 ----------------- ...dResourceFieldOverrideInjectionSelfTest.java | 179 ------- .../resource/GridResourceIocSelfTest.java | 395 -------------- ...GridResourceIsolatedClassLoaderSelfTest.java | 461 ---------------- .../GridResourceIsolatedTaskSelfTest.java | 442 ---------------- .../GridResourceMethodInjectionSelfTest.java | 403 -------------- ...ResourceMethodOverrideInjectionSelfTest.java | 323 ------------ .../GridResourceSharedUndeploySelfTest.java | 519 ------------------- .../grid/p2p/GridP2PAbstractUserResource.java | 126 ----- .../GridP2PContinuousLocalDeploySelfTest.java | 259 --------- .../testsuites/GridResourceSelfTestSuite.java | 10 - 14 files changed, 4275 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridAbstractUserResource.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridAbstractUserResource.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridAbstractUserResource.java deleted file mode 100644 index 26a75b7..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridAbstractUserResource.java +++ /dev/null @@ -1,87 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.resources.*; -import org.springframework.context.*; - -import javax.management.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * Tests task resource injection. - */ -@SuppressWarnings({"UnusedDeclaration"}) -abstract class GridAbstractUserResource { - /** */ - public static final Map<Class<?>, Integer> createClss = new HashMap<>(); - - /** */ - public static final Map<Class<?>, Integer> deployClss = new HashMap<>(); - - /** */ - public static final Map<Class<?>, Integer> undeployClss = new HashMap<>(); - - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - @IgniteSpringApplicationContextResource - private ApplicationContext springCtx; - - /** */ - GridAbstractUserResource() { - addUsage(createClss); - } - - /** - * Resets counters. - */ - public static void resetResourceCounters() { - clearMap(createClss); - clearMap(deployClss); - clearMap(undeployClss); - } - - /** - * @param map Map to clear. - */ - @SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"}) - private static void clearMap(Map<Class<?>, Integer> map) { - synchronized (map) { - map.clear(); - } - } - - /** */ - @SuppressWarnings("unused") - private void neverCalled() { - assert false; - } - - /** - * @param map Usage map to check. - */ - @SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"}) - protected void addUsage(Map<Class<?>, Integer> map) { - synchronized (map) { - Integer cnt = map.get(getClass()); - - map.put(getClass(), cnt == null ? 1 : cnt + 1); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceConcurrentUndeploySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceConcurrentUndeploySelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceConcurrentUndeploySelfTest.java deleted file mode 100644 index fba23d2..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceConcurrentUndeploySelfTest.java +++ /dev/null @@ -1,445 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.events.*; -import org.apache.ignite.resources.*; -import org.gridgain.grid.*; -import org.gridgain.grid.kernal.*; -import org.gridgain.grid.util.typedef.*; -import org.gridgain.testframework.junits.common.*; -import org.jetbrains.annotations.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import static org.apache.ignite.events.IgniteEventType.*; -import static org.gridgain.grid.kernal.processors.resource.GridResourceTestUtils.*; - -/** - * Tests concurrent undeployment of resources. - */ -@SuppressWarnings( {"PublicInnerClass", "BusyWait"}) -@GridCommonTest(group = "Resource Self") -public class GridResourceConcurrentUndeploySelfTest extends GridCommonAbstractTest { - /** Current deployment mode. Used in {@link #getConfiguration(String)}. */ - private IgniteDeploymentMode depMode; - - /** Semaphore. */ - private static CountDownLatch cnt; - - /** Node executing all tasks. */ - private static UUID nodeToExec; - - /** Undeploy count. */ - private static int undeployCnt; - - /** Name of user resource class. */ - private static final String TEST_USER_RESOURCE = "org.gridgain.grid.tests.p2p.GridTestUserResource"; - - /** */ - private static ClassLoader saveTask1Ldr; - - /** */ - private static ClassLoader saveTask2Ldr; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setDeploymentMode(depMode); - - return cfg; - } - - /** - * Wait for specified event came. - * - * @param ignite grid for waiting. - * @param type type of event. - * @throws InterruptedException if thread was interrupted. - */ - private void waitForEvent(Ignite ignite, int type) throws InterruptedException { - Collection<IgniteEvent> evts; - - do { - evts = ignite.events().localQuery(F.<IgniteEvent>alwaysTrue(), type); - - Thread.sleep(500); - } - while (!Thread.currentThread().isInterrupted() && evts.isEmpty()); - - info("Events: " + evts); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() { - GridAbstractUserResource.resetResourceCounters(); - - nodeToExec = null; - - cnt = null; - - undeployCnt = 0; - } - - /** - * @throws Exception if error occur. - */ - public void testNodeLeftInSharedMode() throws Exception { - depMode = IgniteDeploymentMode.SHARED; - - try { - Ignite ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - Ignite ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - Ignite ignite3 = startGrid(3, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - nodeToExec = ignite2.cluster().localNode().id(); - - cnt = new CountDownLatch(2); - - ComputeTaskFuture<?> res = executeAsync(ignite1.compute(), UserResourceTask1.class, true); - - executeAsync(ignite3.compute(), UserResourceTask2.class, false).get(); - - cnt.await(); - - assert saveTask1Ldr == saveTask2Ldr; - - G.stop(getTestGridName(3), true); - - undeployCnt++; - - Thread.sleep(500); - - checkUsageCount(GridAbstractUserResource.undeployClss, UserResource2.class, 0); - - checkUsageCount(GridAbstractUserResource.undeployClss, UserResource.class, 1); - - GridResourceIoc ioc = ((GridKernal) ignite2).context().resource().getResourceIoc(); - - assert ioc.isCached(UserResource.class); - - info("Waiting for task to complete..."); - - res.cancel(); - } - finally { - G.stop(getTestGridName(1), true); - G.stop(getTestGridName(2), true); - G.stop(getTestGridName(3), true); - } - } - - /** - * @param mode deployment mode. - * @throws Exception if error occur. - */ - private void processTestLocalNode(IgniteDeploymentMode mode) throws Exception { - depMode = mode; - - try { - Ignite ignite = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - nodeToExec = ignite.cluster().localNode().id(); - - cnt = new CountDownLatch(1); - - ComputeTaskFuture<?> res = executeAsync(ignite.compute(), UserResourceTask1.class, true); - - cnt.await(); - - ignite.compute().undeployTask(UserResourceTask1.class.getName()); - - GridResourceIoc ioc = ((GridKernal) ignite).context().resource().getResourceIoc(); - - assert ioc.isCached(UserResource.class); - - res.cancel(); - - info("Received task result."); - - waitForEvent(ignite, EVT_TASK_UNDEPLOYED); - - assert !ioc.isCached(UserResource.class); - } - finally { - G.stop(getTestGridName(1), true); - } - } - - /** - * @param mode deployment mode. - * @throws Exception if error occur. - */ - private void processTestRemoteNode(IgniteDeploymentMode mode) throws Exception { - depMode = mode; - - try { - Ignite ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - Ignite ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - nodeToExec = ignite2.cluster().localNode().id(); - - cnt = new CountDownLatch(1); - - ComputeTaskFuture<?> res = executeAsync(ignite1.compute(), UserResourceTask1.class, true); - - cnt.await(); - - ignite1.compute().undeployTask(UserResourceTask1.class.getName()); - - undeployCnt++; - - Thread.sleep(1000); - - GridResourceIoc ioc = ((GridKernal) ignite2).context().resource().getResourceIoc(); - - assert ioc.isCached(UserResource.class); - - res.cancel(); - - waitForEvent(ignite2, EVT_TASK_UNDEPLOYED); - - assert !ioc.isCached(UserResource.class); - } - finally { - G.stop(getTestGridName(1), true); - G.stop(getTestGridName(2), true); - } - } - - /** - * @param mode deployment mode. - * @throws Exception if error occur. - */ - @SuppressWarnings({"unchecked"}) - private void processTestRemoteNodeP2P(IgniteDeploymentMode mode) throws Exception { - depMode = mode; - - try { - Ignite ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - Ignite ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - ClassLoader ldr = getExternalClassLoader(); - - Class task1 = ldr.loadClass("org.gridgain.grid.tests.p2p.GridP2PTestTaskExternalPath1"); - - ComputeTaskFuture res = - executeAsync(ignite1.compute(), task1, new Object[] {ignite2.cluster().localNode().id(), true}); - - waitForEvent(ignite2, EVT_JOB_STARTED); - - ignite1.compute().undeployTask(task1.getName()); - - Thread.sleep(500); - - GridResourceIoc ioc = ((GridKernal) ignite2).context().resource().getResourceIoc(); - - assert ioc.isCached(TEST_USER_RESOURCE); - - res.cancel(); - - waitForEvent(ignite2, EVT_TASK_UNDEPLOYED); - - assert !ioc.isCached(TEST_USER_RESOURCE); - } - finally { - G.stop(getTestGridName(1), true); - G.stop(getTestGridName(2), true); - } - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testLocalNodePrivateMode() throws Exception { - processTestLocalNode(IgniteDeploymentMode.PRIVATE); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testLocalNodeIsolatedMode() throws Exception { - processTestLocalNode(IgniteDeploymentMode.ISOLATED); - } - - /** - * Test GridDeploymentMode.CONTINUOUS mode. - * - * @throws Exception if error occur. - */ - public void testLocalNodeContinuousMode() throws Exception { - processTestLocalNode(IgniteDeploymentMode.CONTINUOUS); - } - - /** - * Test GridDeploymentMode.SHARED mode. - * - * @throws Exception if error occur. - */ - public void testLocalNodeSharedMode() throws Exception { - processTestLocalNode(IgniteDeploymentMode.SHARED); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testRemoteNodePrivateMode() throws Exception { - processTestRemoteNode(IgniteDeploymentMode.PRIVATE); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testRemoteNodeIsolatedMode() throws Exception { - processTestRemoteNode(IgniteDeploymentMode.ISOLATED); - } - - /** - * Test GridDeploymentMode.CONTINUOUS mode. - * - * @throws Exception if error occur. - */ - public void testRemoteNodeContinuousMode() throws Exception { - processTestRemoteNode(IgniteDeploymentMode.CONTINUOUS); - } - - /** - * Test GridDeploymentMode.SHARED mode. - * - * @throws Exception if error occur. - */ - public void testRemoteNodeSharedMode() throws Exception { - processTestRemoteNode(IgniteDeploymentMode.SHARED); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testP2PRemoteNodePrivateMode() throws Exception { - processTestRemoteNodeP2P(IgniteDeploymentMode.PRIVATE); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testP2PRemoteNodeIsolatedMode() throws Exception { - processTestRemoteNodeP2P(IgniteDeploymentMode.ISOLATED); - } - - /** - * Test GridDeploymentMode.CONTINUOUS mode. - * - * @throws Exception if error occur. - */ - public void testP2PRemoteNodeContinuousMode() throws Exception { - processTestRemoteNodeP2P(IgniteDeploymentMode.CONTINUOUS); - } - - /** - * Test GridDeploymentMode.SHARED mode. - * - * @throws Exception if error occur. - */ - public void testP2PRemoteNodeSharedMode() throws Exception { - processTestRemoteNodeP2P(IgniteDeploymentMode.SHARED); - } - - /** - * Simple resource. - */ - public static class UserResource extends GridAbstractUserResource { - // No-op. - } - - /** - * Simple resource. - */ - public static class UserResource2 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class UserResourceTask2 extends UserResourceTask1 { - /** {@inheritDoc} */ - @Override protected void saveLdr(ClassLoader ldr) { - saveTask2Ldr = ldr; - } - } - - /** */ - public static class UserResourceTask1 extends ComputeTaskAdapter<Boolean, Object> { - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Boolean arg) throws IgniteCheckedException { - for (ClusterNode node : subgrid) { - if (node.id().equals(nodeToExec)) { - return Collections.singletonMap(new ComputeJobAdapter(arg) { - /** {@inheritDoc} */ - @SuppressWarnings({"ObjectEquality"}) - @Override public Serializable execute() { - saveLdr(getClass().getClassLoader()); - - if (cnt != null) - cnt.countDown(); - - Boolean arg = argument(0); - - if (arg != null && arg) { - try { - Thread.sleep(Long.MAX_VALUE); - } - catch (InterruptedException ignore) { - // Task has been canceled. - } - } - - checkUsageCount(GridAbstractUserResource.undeployClss, UserResource.class, undeployCnt); - - return null; - } - }, node); - } - } - - throw new IgniteCheckedException("Node not found"); - } - - /** - * @param ldr Class loader to save. - */ - protected void saveLdr(ClassLoader ldr) { - saveTask1Ldr = ldr; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceEventFilterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceEventFilterSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceEventFilterSelfTest.java deleted file mode 100644 index deb66a3..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceEventFilterSelfTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; -import org.gridgain.grid.*; -import org.gridgain.grid.util.typedef.*; -import org.gridgain.testframework.junits.common.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.util.*; - -import static org.gridgain.grid.kernal.processors.resource.GridAbstractUserResource.*; -import static org.gridgain.grid.kernal.processors.resource.GridResourceTestUtils.*; - -/** - * Test resource injection for event filters. - */ -@SuppressWarnings({"ProhibitedExceptionDeclared"}) -@GridCommonTest(group = "Kernal Self") -public class GridResourceEventFilterSelfTest extends GridCommonAbstractTest { - /** - * @throws Exception If test failed. - */ - public void testCustomFilter1() throws Exception { - resetResourceCounters(); - - try { - Ignite ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - // Executes task and creates events - ignite1.compute().execute(TestTask.class, null); - - List<IgniteEvent> evts = ignite1.events().remoteQuery(new CustomEventFilter1(), 0); - - assert !F.isEmpty(evts); - - checkUsageCount(createClss, UserResource1.class, 2); - checkUsageCount(deployClss, UserResource1.class, 2); - } - finally { - stopGrid(1); - stopGrid(2); - } - - checkUsageCount(undeployClss, UserResource1.class, 2); - } - - /** - * @throws Exception If test failed. - */ - public void testCustomFilter2() throws Exception { - resetResourceCounters(); - - try { - Ignite ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - // Executes task and creates events. - ignite1.compute().execute(TestTask.class, null); - - List<IgniteEvent> evts = ignite1.events().remoteQuery(new CustomEventFilter2(), 0); - - assert evts != null; - assert evts.size() == 3; - - // Checks event list. It should have only GridTaskEvent. - for (IgniteEvent evt : evts) { - assert evt instanceof IgniteTaskEvent; - } - - checkUsageCount(createClss, UserResource1.class, 2); - checkUsageCount(deployClss, UserResource1.class, 2); - } - finally { - stopGrid(1); - stopGrid(2); - } - - checkUsageCount(undeployClss, UserResource1.class, 2); - } - - /** - * Simple resource class. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static class UserResource1 extends GridAbstractUserResource { - // No-op. - } - - /** - * Simple event filter. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static final class CustomEventFilter1 implements IgnitePredicate<IgniteEvent> { - /** {@inheritDoc} */ - @Override public boolean apply(IgniteEvent evt) { - return true; - } - } - - /** - * Simple event filter. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static final class CustomEventFilter2 implements IgnitePredicate<IgniteEvent> { - /** Logger. */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override public boolean apply(IgniteEvent evt) { - if (evt instanceof IgniteTaskEvent) { - log.info("Received task event: [evt=" + evt + ']'); - - return true; - } - - return false; - } - } - - /** - * Simple task. - */ - @SuppressWarnings({"PublicInnerClass"}) - @ComputeTaskName("name") - public static class TestTask extends ComputeTaskSplitAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** {@inheritDoc} */ - @Override public Serializable execute() { - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldInjectionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldInjectionSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldInjectionSelfTest.java deleted file mode 100644 index c6ebe05..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldInjectionSelfTest.java +++ /dev/null @@ -1,463 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.marshaller.*; -import org.apache.ignite.resources.*; -import org.gridgain.grid.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.common.*; -import org.springframework.beans.factory.support.*; -import org.springframework.context.*; -import org.springframework.context.support.*; - -import javax.management.*; -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import static org.gridgain.grid.kernal.processors.resource.GridAbstractUserResource.*; -import static org.gridgain.grid.kernal.processors.resource.GridResourceTestUtils.*; - -/** - * Tests task resource injection. - */ -@GridCommonTest(group = "Resource Self") -@SuppressWarnings({"PublicInnerClass"}) -public class GridResourceFieldInjectionSelfTest extends GridCommonAbstractTest { - /** */ - private static final String SPRING_BEAN_RSRC_NAME = "test-bean"; - - /** */ - public GridResourceFieldInjectionSelfTest() { - super(/*start grid*/false); - } - - /** - * @throws Exception If failed. - */ - public void testFieldInjection() throws Exception { - Ignite ignite1 = null; - Ignite ignite2 = null; - - try { - GenericApplicationContext ctx = new GenericApplicationContext(); - - RootBeanDefinition bf = new RootBeanDefinition(); - - bf.setBeanClass(UserSpringBean.class); - - ctx.registerBeanDefinition(SPRING_BEAN_RSRC_NAME, bf); - - ctx.refresh(); - - ignite1 = startGrid(1, new GridSpringResourceContextImpl(ctx)); - ignite2 = startGrid(2, new GridSpringResourceContextImpl(ctx)); - - assert ignite1.cluster().forRemotes().nodes().size() == 1; - assert ignite2.cluster().forRemotes().nodes().size() == 1; - - ignite1.compute().execute(UserResourceTask.class, null); - - checkUsageCount(createClss, UserResource1.class, 4); - checkUsageCount(createClss, UserResource2.class, 4); - checkUsageCount(createClss, UserResource3.class, 4); - checkUsageCount(createClss, UserResource4.class, 4); - checkUsageCount(createClss, UserResource5.class, 4); - - checkUsageCount(deployClss, UserResource1.class, 4); - checkUsageCount(deployClss, UserResource2.class, 4); - checkUsageCount(deployClss, UserResource3.class, 4); - checkUsageCount(deployClss, UserResource4.class, 4); - } - finally { - GridTestUtils.close(ignite1, log()); - GridTestUtils.close(ignite2, log()); - } - checkUsageCount(deployClss, UserResource5.class, 8); - - checkUsageCount(undeployClss, UserResource1.class, 4); - checkUsageCount(undeployClss, UserResource2.class, 4); - checkUsageCount(undeployClss, UserResource3.class, 4); - checkUsageCount(undeployClss, UserResource4.class, 4); - checkUsageCount(undeployClss, UserResource5.class, 8); - } - - /** - * @throws Exception If failed. - */ - public void testNonTransientFieldInjection() throws Exception { - Ignite ignite = startGrid(getTestGridName(), new GridSpringResourceContextImpl(createContext())); - - try { - ignite.compute().execute(NonTransientUserResourceTask.class, null); - - assert false : "Did not get exception for non-transient field."; - } - catch (IgniteCheckedException e) { - info("Got correct exception for non-transient field: " + e.getMessage()); - } - finally { - GridTestUtils.close(ignite, log()); - } - } - - /** - * @throws Exception If failed. - */ - public void testNonTransientSpringBeanFieldInjection() throws Exception { - Ignite ignite = startGrid(getTestGridName(), new GridSpringResourceContextImpl(createContext())); - - try { - ignite.compute().execute(NonTransientSpringBeanResourceTask.class, null); - - assert false : "Did not get exception for non-transient field."; - } - catch (IgniteCheckedException e) { - info("Got correct exception for non-transient field: " + e.getMessage()); - } - - stopGrid(getTestGridName()); - } - - /** - * @throws Exception If failed. - */ - public void testUnknownNameSpringBeanFieldInjection() throws Exception { - Ignite ignite = startGrid(getTestGridName(), new GridSpringResourceContextImpl(createContext())); - - try { - ignite.compute().execute(UnknownNameSpringBeanResourceTask.class, null); - - assert false : "Did not get exception for unknown Spring bean name."; - } - catch (IgniteCheckedException e) { - info("Got correct exception for with unknown Spring bean name: " + e.getMessage()); - } - - stopGrid(getTestGridName()); - } - - /** - * @throws Exception If failed. - */ - public void testInvalidTypeSpringBeanFieldInjection() throws Exception { - Ignite ignite = startGrid(getTestGridName(), new GridSpringResourceContextImpl(createContext())); - - try { - ignite.compute().execute(InvalidTypeSpringBeanResourceTask.class, null); - - assert false : "Did not get exception for different Spring bean classes."; - } - catch (IgniteCheckedException e) { - info("Got correct exception for for different Spring bean classes: " + e.getMessage()); - } - - stopGrid(getTestGridName()); - } - - /** - * @throws Exception If failed. - */ - public void testInjectInClosure() throws Exception { - Ignite ignite = startGrid(); - - try { - ignite.compute().apply(new IgniteClosure<Object, Object>() { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - @Override public Object apply(Object o) { - assertNotNull(this.ignite); - - return null; - } - }, new Object()); - - ignite.compute().broadcast(new IgniteClosure<Object, Object>() { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - @Override public Object apply(Object o) { - assertNotNull(this.ignite); - - return null; - } - }, new Object()); - - ignite.compute().apply(new TestClosure(), new Object()); - - ignite.compute().broadcast(new TestClosure(), new Object()); - } - finally { - stopAllGrids(); - } - } - - /** - * Creates Spring context with registered test bean. - * - * @return Test Spring context. - */ - private ApplicationContext createContext() { - GenericApplicationContext ctx = new GenericApplicationContext(); - - BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(UserSpringBean.class); - - ctx.registerBeanDefinition(SPRING_BEAN_RSRC_NAME, builder.getBeanDefinition()); - - return ctx; - } - - /** */ - public static class UserResource1 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class UserResource2 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class UserResource3 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class UserResource4 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class UserResource5 extends GridAbstractUserResource { - /** */ - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private UserSpringBean springBean; - } - - /** */ - public static class UserSpringBean { - // No-op. - } - - /** - * Task that will always fail due to non-transient resource injection. - */ - public static class NonTransientSpringBeanResourceTask extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @SuppressWarnings({"UnusedDeclaration", "unused"}) - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private Object rsrc; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - } - - /** - * Task that will always fail due to resource injection with unknown Spring bean name. - */ - public static class UnknownNameSpringBeanResourceTask extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @SuppressWarnings({"UnusedDeclaration", "unused"}) - @IgniteSpringResource(resourceName = "unknown-bean-name") - private transient Object springBean; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - } - - /** - * Task that will always fail due to resource injection with invalid declared bean type. - */ - public static class InvalidTypeSpringBeanResourceTask extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @SuppressWarnings({"UnusedDeclaration", "unused"}) - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private transient Serializable springBean; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - } - - /** - * Task that will always fail due to non-transient resource injection. - */ - public static class NonTransientUserResourceTask extends ComputeTaskSplitAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - // Never reached. - assert false; - - return null; - } - } - - /** */ - public static class UserResourceTask extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - @IgniteLoadBalancerResource - private ComputeLoadBalancer balancer; - - /** */ - @IgniteSpringApplicationContextResource - private ApplicationContext springCtx; - - /** */ - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private transient UserSpringBean springBean; - - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession ses; - - /** Job context is job resource, not task resource. */ - @IgniteJobContextResource - private ComputeJobContext outerJobCtx; - - /** */ - @IgniteTaskContinuousMapperResource - private transient ComputeTaskContinuousMapper mapper; - - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - assert log != null; - assert ignite != null; - assert springCtx != null; - assert springBean != null; - assert ses != null; - assert balancer != null; - assert mapper != null; - - assert outerJobCtx == null; - - assert gridSize == 2; - - log.info("Injected log resource into task: " + log); - log.info("Injected grid resource into task: " + ignite); - log.info("Injected spring context resource into task: " + springCtx); - log.info("Injected spring bean resource into task: " + springBean); - log.info("Injected load balancer into task: " + balancer); - log.info("Injected session resource into task: " + ses); - log.info("Injected continuous mapper: " + mapper); - - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** */ - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private transient UserSpringBean springBean2; - - /** */ - @IgniteJobContextResource - private ComputeJobContext jobCtx; - - /** {@inheritDoc} */ - @Override public Serializable execute() { - assert log != null; - assert ignite != null; - assert springCtx != null; - assert springBean != null; - assert springBean2 != null; - assert ses != null; - assert jobCtx != null; - assert outerJobCtx == null; - - log.info("Injected log resource into job: " + log); - log.info("Injected grid resource into job: " + ignite); - log.info("Injected spring context resource into job: " + springCtx); - log.info("Injected spring bean resource into job: " + springBean2); - log.info("Injected session resource into job: " + ses); - log.info("Injected job context resource into job: " + jobCtx); - log.info("Injected job context resource into outer class: " + outerJobCtx); - - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert log != null; - assert ignite != null; - assert springCtx != null; - assert springBean != null; - assert ses != null; - assert balancer != null; - - // Nothing to reduce. - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldOverrideInjectionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldOverrideInjectionSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldOverrideInjectionSelfTest.java deleted file mode 100644 index d46f0c4..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceFieldOverrideInjectionSelfTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.resources.*; -import org.gridgain.grid.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.common.*; -import org.springframework.beans.factory.support.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.util.*; - -import static org.gridgain.grid.kernal.processors.resource.GridAbstractUserResource.*; -import static org.gridgain.grid.kernal.processors.resource.GridResourceTestUtils.*; - -/** - * - */ -@SuppressWarnings({"InnerClassFieldHidesOuterClassField"}) -@GridCommonTest(group = "Resource Self") -public class GridResourceFieldOverrideInjectionSelfTest extends GridCommonAbstractTest { - /** */ - private static final String SPRING_BEAN_RSRC_NAME = "test-bean"; - - /** */ - public GridResourceFieldOverrideInjectionSelfTest() { - super(/*start grid*/false); - } - - /** - * @throws Exception in the case of failures. - */ - public void testFieldResourceOverride() throws Exception { - Ignite ignite1 = null; - Ignite ignite2 = null; - - try { - GenericApplicationContext ctx = new GenericApplicationContext(); - - RootBeanDefinition bf = new RootBeanDefinition(); - - bf.setBeanClass(UserSpringBean.class); - - ctx.registerBeanDefinition(SPRING_BEAN_RSRC_NAME, bf); - - ctx.refresh(); - - ignite1 = startGrid(1, new GridSpringResourceContextImpl(ctx)); - ignite2 = startGrid(2, new GridSpringResourceContextImpl(ctx)); - - ignite1.compute().execute(ResourceOverrideTask.class, null); - - checkUsageCount(createClss, UserResource.class, 2); - checkUsageCount(deployClss, UserResource.class, 2); - } - finally { - GridTestUtils.close(ignite1, log()); - GridTestUtils.close(ignite2, log()); - } - - checkUsageCount(undeployClss, UserResource.class, 2); - } - - /** - * - */ - @SuppressWarnings("PublicInnerClass") - public static class UserResource extends GridAbstractUserResource { - // No-op. - } - - /** - * - */ - private static class UserSpringBean { - // No-op. - } - - /** */ - private static class ResourceOverrideTask extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private transient UserSpringBean springBean; - - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession ses; - - /** */ - @IgniteJobContextResource - private ComputeJobContext jobCtx; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - assert log != null; - assert springBean != null; - - // Job context is job resource, not task resource. - assert jobCtx == null; - - log.info("Injected logger into task: " + log); - log.info("Injected session into task: " + ses); - log.info("Injected spring bean into task: " + springBean); - - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession ses; - - /** */ - @IgniteJobContextResource - private ComputeJobContext jobCtx; - - /** */ - @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME) - private transient UserSpringBean jobSpringBean; - - /** {@inheritDoc} */ - @SuppressWarnings({"ObjectEquality"}) - @Override public Serializable execute() { - assert log != null; - assert jobSpringBean != null; - - assert ResourceOverrideTask.this.log != null; - //Job context is never setup on the task. - assert ResourceOverrideTask.this.jobCtx == null; - - assert springBean != null; - - assert ses == ResourceOverrideTask.this.ses; - assert jobCtx != null; - assert jobSpringBean == springBean; - - log.info("Injected logger into job: " + log); - log.info("Injected session into job: " + ses); - log.info("Injected spring bean into job: " + jobSpringBean); - - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert log != null; - - // Job context is job resource, not task resource. - assert jobCtx == null; - - // Nothing to reduce. - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIocSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIocSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIocSelfTest.java deleted file mode 100644 index 65975f4..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIocSelfTest.java +++ /dev/null @@ -1,395 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; -import org.gridgain.grid.*; -import org.gridgain.grid.kernal.*; -import org.gridgain.grid.kernal.managers.deployment.*; -import org.apache.ignite.spi.deployment.uri.*; -import org.gridgain.grid.util.typedef.internal.*; -import org.gridgain.testframework.junits.*; -import org.gridgain.testframework.junits.common.*; -import org.jetbrains.annotations.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import static java.util.concurrent.TimeUnit.*; -import static org.apache.ignite.events.IgniteEventType.*; -import static org.gridgain.grid.kernal.processors.resource.GridAbstractUserResource.*; -import static org.gridgain.grid.kernal.processors.resource.GridResourceTestUtils.*; - -/** - * Tests for {@link GridResourceIoc} class. - */ -@SuppressWarnings({"ProhibitedExceptionDeclared"}) -@GridCommonTest(group = "Resource Self") -public class GridResourceIocSelfTest extends GridCommonAbstractTest { - /** Name of user resource class from gar file. */ - private static final String TEST_USER_RSRC = "org.gridgain.grid.tests.p2p.GridTestUserResource"; - - /** Name of task from gar file. */ - private static final String TEST_EXT_TASK = "org.gridgain.grid.tests.p2p.GridP2PTestTaskExternalPath1"; - - /** Current deployment mode. Used in {@link #getConfiguration(String)}. */ - private IgniteDeploymentMode depMode; - - /** Path to GAR file. */ - private String garFile; - - /** - * Constructor. - */ - public GridResourceIocSelfTest() { - super(/*start grid*/false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName, - GridTestResources rsrcs) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName, rsrcs); - - cfg.setDeploymentMode(depMode); - - cfg.setCacheConfiguration(); - cfg.setIncludeProperties(); - cfg.setPeerClassLoadingLocalClassPathExclude("org.gridgain.grid.kernal.processors.resource.*"); - - if (garFile != null) { - GridUriDeploymentSpi depSpi = new GridUriDeploymentSpi(); - - depSpi.setUriList(Collections.singletonList(garFile)); - - cfg.setDeploymentSpi(depSpi); - } - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - resetResourceCounters(); - } - - /** - * Executes test task on one node and explicitly undeploy it. - * Checks ioc for both deployed and undeployed states. - * - * @throws Exception If failed. - */ - private void processTestWithUndeploy() throws Exception { - try { - Ignite ignite = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - GridResourceIoc ioc = ((GridKernal) ignite).context().resource().getResourceIoc(); - - ignite.compute().execute(TestTask.class, null); - - checkUsageCount(createClss, UserResource1.class, 1); - checkUsageCount(deployClss, UserResource1.class, 1); - - assert ioc.isCached(UserResource1.class); - - ignite.compute().undeployTask(TestTask.class.getName()); - - assert !ioc.isCached(UserResource1.class); - - checkUsageCount(undeployClss, UserResource1.class, 1); - } - finally { - stopGrid(1); - } - } - - /** - * Executes test task on two nodes and then stop master node. - * Checks ioc before master node stop and after. - * - * @throws Exception If failed. - */ - private void processTestWithNodeStop() throws Exception { - try { - Ignite ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - Ignite ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - final CountDownLatch latch = new CountDownLatch(2); - - ignite2.events().localListen( - new IgnitePredicate<IgniteEvent>() { - @Override public boolean apply(IgniteEvent evt) { - info("Received event: " + evt); - - latch.countDown(); - - return true; - } - }, EVT_TASK_UNDEPLOYED - ); - - GridResourceIoc ioc = ((GridKernal) ignite2).context().resource().getResourceIoc(); - - ignite1.compute().execute(TestTask.class, null); - - checkUsageCount(createClss, UserResource1.class, 1); - checkUsageCount(deployClss, UserResource1.class, 1); - - assert ioc.isCached(UserResource1.class); - - stopGrid(1); - - Thread.sleep(2000); - - assert !ioc.isCached(UserResource1.class); - - checkUsageCount(undeployClss, UserResource1.class, 1); - - assert latch.await(5000, MILLISECONDS); - } - finally { - stopGrid(1); - stopGrid(2); - } - } - - /** - * Executes tasks from deployed gar file and checks ioc cache on deployed/undeployed events. - * - * @throws Exception If error occur. - */ - private void processTestGarUndeployed() throws Exception { - String garDir = "modules/extdata/p2p/deploy"; - String garFileName = "p2p.gar"; - - File origGarPath = U.resolveGridGainPath(garDir + '/' + garFileName); - - File tmpPath = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); - - if (!tmpPath.mkdir()) - throw new IOException("Can not create temp directory"); - - try { - File newGarFile = new File(tmpPath, garFileName); - - U.copy(origGarPath, newGarFile, false); - - assert newGarFile.exists(); - - try { - garFile = "file:///" + tmpPath.getAbsolutePath(); - - try { - Ignite ignite = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - int[] res = ignite.compute().execute(TEST_EXT_TASK, ignite.cluster().localNode().id()); - - assert res.length == 2; - - GridResourceIoc ioc = ((GridKernal) ignite).context().resource(). - getResourceIoc(); - - assert ioc.isCached(TEST_USER_RSRC); - - if (!newGarFile.delete()) - throw new IOException("Can not delete temp gar file"); - - newGarFile = null; - - Thread.sleep(GridUriDeploymentSpi.DFLT_DISK_SCAN_FREQUENCY + 1000); - - // Cache must contains no GridTestUserResource. - assert !ioc.isCached(TEST_USER_RSRC); - - try { - ignite.compute().execute(TEST_EXT_TASK, - ignite.cluster().localNode().id()); - - assert false : "Task must be undeployed"; - } - catch (IgniteCheckedException e) { - info("Caught expected exception: " + e); - } - } - finally { - stopGrid(1); - } - } - finally { - if (newGarFile != null && !newGarFile.delete()) - error("Can not delete temp gar file"); - } - } - finally { - if (!tmpPath.delete()) - error("Can not delete temp directory"); - } - } - - /** - * Simple task. - */ - @SuppressWarnings({"PublicInnerClass"}) - @ComputeTaskName("TestTask") - public static class TestTask extends ComputeTaskSplitAdapter<Object, Void> { - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - @Override public Serializable execute() { - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Nullable @Override public Void reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } - - /** */ - @SuppressWarnings({"PublicInnerClass"}) - public static class UserResource1 extends GridAbstractUserResource { - // No-op. - } - - /** - * Test GridDeploymentMode.PRIVATE mode. - * - * @throws Exception if error occur. - */ - public void testUndeployPrivateMode() throws Exception { - depMode = IgniteDeploymentMode.PRIVATE; - - processTestWithUndeploy(); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testUndeployIsolatedMode() throws Exception { - depMode = IgniteDeploymentMode.ISOLATED; - - processTestWithUndeploy(); - } - - /** - * Test GridDeploymentMode.CONTINUOUS mode. - * - * @throws Exception if error occur. - */ - public void testUndeployContinuousMode() throws Exception { - depMode = IgniteDeploymentMode.CONTINUOUS; - - processTestWithUndeploy(); - } - - /** - * Test GridDeploymentMode.SHARED mode. - * - * @throws Exception if error occur. - */ - public void testUndeploySharedMode() throws Exception { - depMode = IgniteDeploymentMode.SHARED; - - processTestWithUndeploy(); - } - - /** - * Test GridDeploymentMode.PRIVATE mode. - * - * @throws Exception if error occur. - */ - public void testStopNodePrivateMode() throws Exception { - depMode = IgniteDeploymentMode.PRIVATE; - - processTestWithNodeStop(); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testStopNodeIsolatedMode() throws Exception { - depMode = IgniteDeploymentMode.ISOLATED; - - processTestWithNodeStop(); - } - - /** - * Test GridDeploymentMode.SHARED mode. - * - * @throws Exception if error occur. - */ - public void testStopNodeSharedMode() throws Exception { - depMode = IgniteDeploymentMode.SHARED; - - processTestWithNodeStop(); - } - - /** - * Test GridDeploymentMode.PRIVATE mode. - * - * @throws Exception if error occur. - */ - public void testGarPrivateMode() throws Exception { - depMode = IgniteDeploymentMode.PRIVATE; - - processTestGarUndeployed(); - } - - /** - * Test GridDeploymentMode.ISOLATED mode. - * - * @throws Exception if error occur. - */ - public void testGarIsolatedMode() throws Exception { - depMode = IgniteDeploymentMode.ISOLATED; - - processTestGarUndeployed(); - } - - /** - * Test GridDeploymentMode.CONTINUOUS mode. - * - * @throws Exception if error occur. - */ - public void testGarContinuousMode() throws Exception { - depMode = IgniteDeploymentMode.CONTINUOUS; - - processTestGarUndeployed(); - } - - /** - * Test GridDeploymentMode.SHARED mode. - * - * @throws Exception if error occur. - */ - public void testGarSharedMode() throws Exception { - depMode = IgniteDeploymentMode.SHARED; - - processTestGarUndeployed(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedClassLoaderSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedClassLoaderSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedClassLoaderSelfTest.java deleted file mode 100644 index e30d9ec..0000000 --- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedClassLoaderSelfTest.java +++ /dev/null @@ -1,461 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.resource; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.resources.*; -import org.gridgain.grid.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.common.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.util.*; - -import static org.gridgain.grid.kernal.processors.resource.GridAbstractUserResource.*; -import static org.gridgain.grid.kernal.processors.resource.GridResourceTestUtils.*; - -/** - * Tests resources injection for the tasks executed in isolated class loaders mode. - */ -@GridCommonTest(group = "Resource Self") -public class GridResourceIsolatedClassLoaderSelfTest extends GridCommonAbstractTest { - /** */ - private static Object task1Rsrc1; - - /** */ - private static Object task1Rsrc2; - - /** */ - private static Object task1Rsrc3; - - /** */ - private static Object task1Rsrc4; - - /** */ - private static Object task2Rsrc1; - - /** */ - private static Object task2Rsrc2; - - /** */ - private static Object task2Rsrc3; - - /** */ - private static Object task2Rsrc4; - - /** */ - public GridResourceIsolatedClassLoaderSelfTest() { - super(/*start grid*/false); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - task1Rsrc1 = null; - task1Rsrc2 = null; - task1Rsrc3 = null; - task1Rsrc4 = null; - - task2Rsrc1 = null; - task2Rsrc2 = null; - task2Rsrc3 = null; - task2Rsrc4 = null; - - resetResourceCounters(); - } - - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration() throws Exception { - IgniteConfiguration cfg = super.getConfiguration(); - - cfg.setDeploymentMode(IgniteDeploymentMode.ISOLATED); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - public void testSameTask() throws Exception { - Ignite ignite = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - try { - // Execute the same task twice. - // 1 resource created locally - ignite.compute().execute(SharedResourceTask1.class, null); - ignite.compute().execute(SharedResourceTask1.class, null); - - checkUsageCount(createClss, UserResource1.class, 2); - checkUsageCount(createClss, UserResource2.class, 2); - - checkUsageCount(deployClss, UserResource1.class, 2); - checkUsageCount(deployClss, UserResource2.class, 2); - } - finally { - GridTestUtils.close(ignite, log()); - } - - checkUsageCount(undeployClss, UserResource1.class, 2); - checkUsageCount(undeployClss, UserResource2.class, 2); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"ObjectEquality"}) - public void testDifferentTasks() throws Exception { - Ignite ignite1 = null; - Ignite ignite2 = null; - - try { - ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - // Execute different tasks. - ignite1.compute().execute(SharedResourceTask1.class, null); - ignite1.compute().execute(SharedResourceTask2.class, null); - - // In ISOLATED_CLASSLOADER mode tasks should have the class - // loaders because they have the same CL locally and thus the same - // resources. - // So 1 resource locally and 1 remotely - assert task1Rsrc1 == task2Rsrc1; - assert task1Rsrc2 == task2Rsrc2; - assert task1Rsrc3 == task2Rsrc3; - assert task1Rsrc4 == task2Rsrc4; - - checkUsageCount(createClss, UserResource1.class, 4); - checkUsageCount(createClss, UserResource2.class, 4); - - checkUsageCount(deployClss, UserResource1.class, 4); - checkUsageCount(deployClss, UserResource2.class, 4); - } - finally { - GridTestUtils.close(ignite1, log()); - GridTestUtils.close(ignite2, log()); - } - - checkUsageCount(undeployClss, UserResource1.class, 4); - checkUsageCount(undeployClss, UserResource2.class, 4); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"ObjectEquality"}) - public void testUndeployedTask() throws Exception { - Ignite ignite1 = null; - Ignite ignite2 = null; - - try { - ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext())); - ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - // Execute tasks. - ignite1.compute().execute(SharedResourceTask1.class, null); - ignite1.compute().execute(SharedResourceTask2.class, null); - - ignite1.compute().undeployTask(SharedResourceTask1.class.getName()); - - // Wait until resources get undeployed remotely - // because undeploy is asynchronous apply. - Thread.sleep(3000); - - // 1 local and 1 remote resource instances - checkUsageCount(createClss, UserResource1.class, 4); - checkUsageCount(deployClss, UserResource1.class, 4); - checkUsageCount(createClss, UserResource2.class, 4); - checkUsageCount(deployClss, UserResource2.class, 4); - - // Since tasks shares resources and we undeployed only 1 task, - // then another one should be undeployed automatically. - checkUsageCount(undeployClss, UserResource1.class, 4); - checkUsageCount(undeployClss, UserResource2.class, 4); - - ignite1.compute().undeployTask(SharedResourceTask2.class.getName()); - - // Wait until resources get undeployed remotely - // because undeploy is asynchronous apply. - Thread.sleep(3000); - - // We undeployed last task for this class loader and resources. - // All resources should be undeployed. - checkUsageCount(undeployClss, UserResource1.class, 4); - checkUsageCount(undeployClss, UserResource2.class, 4); - - // Execute the same tasks. - ignite1.compute().execute(SharedResourceTask1.class, null); - ignite1.compute().execute(SharedResourceTask2.class, null); - - // 2 new resources. - checkUsageCount(createClss, UserResource1.class, 8); - checkUsageCount(deployClss, UserResource1.class, 8); - checkUsageCount(createClss, UserResource2.class, 8); - checkUsageCount(deployClss, UserResource2.class, 8); - } - finally { - GridTestUtils.close(ignite1, log()); - GridTestUtils.close(ignite2, log()); - } - - checkUsageCount(undeployClss, UserResource1.class, 8); - checkUsageCount(undeployClss, UserResource2.class, 8); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings("unchecked") - public void testRedeployedTask() throws Exception { - Ignite ignite = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - try { - // Execute the same task twice. - // 1 resource created locally - ignite.compute().execute(SharedResourceTask1.class, null); - - checkUsageCount(createClss, UserResource1.class, 2); - checkUsageCount(createClss, UserResource2.class, 2); - - checkUsageCount(deployClss, UserResource1.class, 2); - checkUsageCount(deployClss, UserResource2.class, 2); - - // Change class loader of the task. So it's just implicit redeploy. - GridTestClassLoader ldr = new GridTestClassLoader(null, getClass().getClassLoader(), - SharedResourceTask1.class.getName(), - GridResourceIsolatedClassLoaderSelfTest.SharedResourceTask1.GridSharedJob1.class.getName(), - GridResourceIsolatedClassLoaderSelfTest.class.getName()); - - Class<? extends ComputeTask<Object, Object>> taskCls = (Class<? extends ComputeTask<Object, Object>>) - ldr.loadClass(SharedResourceTask1.class.getName()); - - ignite.compute().execute(taskCls, null); - - // Old resources should be undeployed at this point. - checkUsageCount(undeployClss, UserResource1.class, 2); - checkUsageCount(undeployClss, UserResource2.class, 2); - - // We should detect redeployment and create new resources. - checkUsageCount(createClss, UserResource1.class, 4); - checkUsageCount(createClss, UserResource2.class, 4); - - checkUsageCount(deployClss, UserResource1.class, 4); - checkUsageCount(deployClss, UserResource2.class, 4); - } - finally { - GridTestUtils.close(ignite, log()); - } - - checkUsageCount(undeployClss, UserResource1.class, 4); - checkUsageCount(undeployClss, UserResource2.class, 4); - } - - /** - * @throws Exception If failed. - */ - public void testDuplicateTaskName() throws Exception { - Ignite ignite = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext())); - - // Execute different tasks but with the same name and version. - // 2 resource created locally - ignite.compute().execute(SharedResourceTask3.class, null); - - try { - ignite.compute().execute(SharedResourceTask4.class, null); - - assert false : "SharedResourceTask4 should not be allowed to deploy."; - } - catch (IgniteCheckedException e) { - info("Received expected exception: " + e); - } - finally { - GridTestUtils.close(ignite, log()); - } - } - - /** */ - public static class UserResource1 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class UserResource2 extends GridAbstractUserResource { - // No-op. - } - - /** */ - public static class SharedResourceTask1 extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - assert log != null; - - log.info("Injected log resource into task: " + log); - - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) - jobs.add(new GridSharedJob1()); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert log != null; - - // Nothing to reduce. - return null; - } - - /** - * Job class for the 1st task. To avoid illegal - * access when loading class with different class loader. - */ - public final class GridSharedJob1 extends ComputeJobAdapter { - /** {@inheritDoc} */ - @SuppressWarnings({"ObjectEquality"}) - @Override public Serializable execute() { - assert log != null; - - log.info("Injected log resource into job: " + log); - - return null; - } - } - } - - /** */ - public static class SharedResourceTask2 extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - assert log != null; - - log.info("Injected log resource into task: " + log); - - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** {@inheritDoc} */ - @SuppressWarnings({"ObjectEquality"}) - @Override public Serializable execute() { - assert log != null; - - log.info("Injected log resource into job: " + log); - - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert log != null; - - // Nothing to reduce. - return null; - } - } - - /** */ - @ComputeTaskName("name") - public static class SharedResourceTask3 extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - assert log != null; - - log.info("Injected log resource into task: " + log); - - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** {@inheritDoc} */ - @SuppressWarnings({"ObjectEquality"}) - @Override public Serializable execute() { - assert log != null; - - log.info("Injected log resource into job: " + log); - - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert log != null; - - // Nothing to reduce. - return null; - } - } - - /** */ - @ComputeTaskName("name") - public static class SharedResourceTask4 extends ComputeTaskSplitAdapter<Object, Object> { /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException { - assert log != null; - - log.info("Injected log resource into task: " + log); - - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** {@inheritDoc} */ - @SuppressWarnings({"ObjectEquality"}) - @Override public Serializable execute() { - assert log != null; - - log.info("Injected log resource into job: " + log); - - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert log != null; - - // Nothing to reduce. - return null; - } - } -}