You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2014/12/19 14:32:59 UTC
[7/9] incubator-ignite git commit: IGNITE-35 Removed tests on
IgniteUserResource resources.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedTaskSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedTaskSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedTaskSelfTest.java
deleted file mode 100644
index 22eeb13..0000000
--- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceIsolatedTaskSelfTest.java
+++ /dev/null
@@ -1,442 +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_task mode.
- */
-@GridCommonTest(group = "Resource Self")
-@SuppressWarnings( {"PublicInnerClass"})
-public class GridResourceIsolatedTaskSelfTest 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 GridResourceIsolatedTaskSelfTest() {
- 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(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- cfg.setDeploymentMode(IgniteDeploymentMode.PRIVATE);
-
- 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_TASK mode tasks should have different class
- // loaders and different resources.
- // So 2 different resources locally and 2 remotely
- assert task1Rsrc1 != task2Rsrc1;
- assert task1Rsrc2 != task2Rsrc2;
- assert task1Rsrc3 != task2Rsrc3;
- assert task1Rsrc4 != task2Rsrc4;
-
- checkUsageCount(createClss, UserResource1.class, 8);
- checkUsageCount(createClss, UserResource2.class, 8);
-
- checkUsageCount(deployClss, UserResource1.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({"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().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(undeployClss, UserResource1.class, 4);
-
- // Execute the same tasks.
- ignite1.compute().execute(SharedResourceTask1.class, null);
-
- // In ISOLATED_TASK mode being undeployed task will
- // loose all resources. After redeploy new one should be created.
- checkUsageCount(createClss, UserResource1.class, 8);
- checkUsageCount(deployClss, UserResource1.class, 8);
- }
- finally {
- GridTestUtils.close(ignite1, log());
- GridTestUtils.close(ignite2, log());
- }
-
- checkUsageCount(undeployClss, UserResource1.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.
- ClassLoader tstClsLdr = new GridTestClassLoader(null, getClass().getClassLoader(),
- SharedResourceTask1.class.getName(),
- GridResourceIsolatedTaskSelfTest.SharedResourceTask1.GridSharedJob1.class.getName(),
- GridResourceIsolatedTaskSelfTest.class.getName());
-
- Class<? extends ComputeTask<Object, Object>> taskCls =
- (Class<? extends ComputeTask<Object, Object>>)tstClsLdr.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;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodInjectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodInjectionSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodInjectionSelfTest.java
deleted file mode 100644
index a2e0536..0000000
--- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodInjectionSelfTest.java
+++ /dev/null
@@ -1,403 +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.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 GridResourceMethodInjectionSelfTest extends GridCommonAbstractTest {
- /** */
- private static final String SPRING_BEAN_RSRC_NAME = "test-bean";
-
- /** */
- public GridResourceMethodInjectionSelfTest() {
- super(/*start grid*/false);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testMethodInjection() 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(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);
- }
-
- /** */
- 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 {
- /** */
- private UserSpringBean springBean;
-
- /**
- * @param springBean Bean provided from Spring context.
- */
- @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME)
- @SuppressWarnings("unused")
- public void setSpringBean(UserSpringBean springBean) {
- this.springBean = springBean;
- }
- }
-
- /** */
- public static class UserSpringBean implements Serializable {
- // No-op.
- }
-
- /**
- * 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> {
- /** */
- private transient GridAbstractUserResource rsrc1;
-
- /** */
- private transient UserResource2 rsrc2;
-
- /** */
- private transient GridAbstractUserResource rsrc3;
-
- /** */
- private transient UserResource2 rsrc4;
-
- /** */
- private IgniteLogger log;
-
- /** */
- private Ignite ignite;
-
- /** */
- private String ggHome;
-
- /** */
- private String locHost;
-
- /** */
- private ApplicationContext springCtx;
-
- /** */
- private ComputeTaskSession ses;
-
- /** */
- private ComputeLoadBalancer balancer;
-
- /** */
- private ComputeJobContext jobCtx;
-
- /** */
- private UserSpringBean springBean;
-
- /** */
- private transient ComputeTaskContinuousMapper mapper;
-
- /**
- * @param log Logger.
- */
- @IgniteLoggerResource
- public void setLog(IgniteLogger log) {
- this.log = log;
- }
-
- /**
- * @param ignite Grid.
- */
- @IgniteInstanceResource
- public void setIgnite(Ignite ignite) {
- this.ignite = ignite;
- }
-
- /**
- * @param springCtx Spring context.
- */
- @IgniteSpringApplicationContextResource
- public void setSpringContext(ApplicationContext springCtx) {
- this.springCtx = springCtx;
- }
-
- /**
- * @param ses Task session.
- */
- @IgniteTaskSessionResource
- public void setSession(ComputeTaskSession ses) {
- this.ses = ses;
- }
-
- /**
- * @param balancer Load balancer.
- */
- @IgniteLoadBalancerResource
- public void setBalancer(ComputeLoadBalancer balancer) {
- this.balancer = balancer;
- }
-
- /**
- * @param jobCtx Job context.
- */
- @IgniteJobContextResource
- public void setJobContext(ComputeJobContext jobCtx) {
- this.jobCtx = jobCtx;
- }
-
- /**
- * @param springBean Bean provided from Spring context.
- */
- @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME)
- public void setSpringBean(UserSpringBean springBean) {
- this.springBean = springBean;
- }
-
- /**
- * @param mapper Task Continuous Mapper.
- */
- @IgniteTaskContinuousMapperResource
- public void setMapper(ComputeTaskContinuousMapper mapper) {
- this.mapper = mapper;
- }
-
- /** {@inheritDoc} */
- @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException {
- assert rsrc1 != null;
- assert rsrc2 != null;
- assert rsrc3 != null;
- assert rsrc4 != null;
- assert log != null;
- assert ignite != null;
- assert ggHome != null;
- assert locHost != null;
- assert springCtx != null;
- assert ses != null;
- assert balancer != null;
- assert springBean != null;
- assert mapper != null;
-
- // Job context belongs to job, not to task.
- assert jobCtx == null;
-
- log.info("Injected shared resource1 into task: " + rsrc1);
- log.info("Injected shared resource2 into task: " + rsrc2);
- log.info("Injected shared resource3 into task: " + rsrc3);
- log.info("Injected shared resource4 into task: " + rsrc4);
- log.info("Injected log resource into task: " + log);
- log.info("Injected grid resource into task: " + ignite);
- log.info("Injected gridgain home resource into task: " + ggHome);
- log.info("Injected local host resource into task: " + locHost);
- log.info("Injected spring context resource into task: " + springCtx);
- log.info("Injected session resource into task: " + ses);
- log.info("Injected load balancer into task: " + balancer);
- log.info("Injected spring bean resource into task: " + springBean);
- log.info("Injected continuous mapper: " + mapper);
-
- Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize);
-
- for (int i = 0; i < gridSize; i++) {
- jobs.add(new ComputeJobAdapter() {
- /** */
- private transient GridAbstractUserResource rsrc5;
-
- /** */
- private transient UserResource4 rsrc6;
-
- /** */
- private transient UserResource5 rsrc7;
-
- /** */
- private transient GridAbstractUserResource rsrc8;
-
- /** */
- private transient UserResource4 rsrc9;
-
- /** */
- private transient UserResource5 rsrc10;
-
- /** */
- private UserSpringBean springBean2;
-
- /** */
- @IgniteJobContextResource
- private ComputeJobContext jobCtx;
-
- /**
- * @param springBean2 Bean provided from Spring context.
- */
- @IgniteSpringResource(resourceName = SPRING_BEAN_RSRC_NAME)
- public void setSpringBean2(UserSpringBean springBean2) {
- this.springBean2 = springBean2;
- }
-
- /** {@inheritDoc} */
- @Override public Serializable execute() {
- assert rsrc1 != null;
- assert rsrc2 != null;
- assert rsrc3 != null;
- assert rsrc4 != null;
- assert log != null;
- assert ignite != null;
- assert ggHome != null;
- assert locHost != null;
- assert springCtx != null;
- assert ses != null;
- assert jobCtx != null;
- assert springBean != null;
- assert springBean2 != null;
-
- assert rsrc5 != null;
- assert rsrc6 != null;
- assert rsrc7 != null;
- assert rsrc8 != null;
- assert rsrc9 != null;
- assert rsrc10 != null;
-
- log.info("Injected shared resource1 into job: " + rsrc1);
- log.info("Injected shared resource2 into job: " + rsrc2);
- log.info("Injected shared resource3 into job: " + rsrc3);
- log.info("Injected shared resource4 into job: " + rsrc4);
- log.info("Injected shared resource5 into job: " + rsrc5);
- log.info("Injected shared resource6 into job: " + rsrc6);
- log.info("Injected shared resource7 into job: " + rsrc7);
- log.info("Injected shared resource8 into job: " + rsrc8);
- log.info("Injected shared resource9 into job: " + rsrc9);
- log.info("Injected shared resource10 into job: " + rsrc10);
- log.info("Injected log resource into job: " + log);
- log.info("Injected grid resource into job: " + ignite);
- log.info("Injected local Host resource into job: " + locHost);
- log.info("Injected gridgain home resource into job: " + ggHome);
- log.info("Injected grid name resource into job: " + ggHome);
- log.info("Injected spring context resource into job: " + springCtx);
- log.info("Injected session resource into job: " + ses);
- log.info("Injected job context resource into job: " + jobCtx);
- log.info("Injected spring bean2 resource into job: " + springBean2);
-
- return null;
- }
- });
- }
-
- return jobs;
- }
-
- /** {@inheritDoc} */
- @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException {
- assert rsrc1 != null;
- assert rsrc2 != null;
- assert rsrc3 != null;
- assert rsrc4 != null;
- assert log != null;
- assert ignite != null;
- assert locHost != null;
- assert ggHome != null;
- assert springCtx != null;
- assert ses != null;
- assert balancer != null;
- assert springBean != 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/GridResourceMethodOverrideInjectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodOverrideInjectionSelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodOverrideInjectionSelfTest.java
deleted file mode 100644
index 75b4f15..0000000
--- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceMethodOverrideInjectionSelfTest.java
+++ /dev/null
@@ -1,323 +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.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.*;
-
-/**
- *
- */
-public class GridResourceMethodOverrideInjectionSelfTest extends GridCommonAbstractTest {
- /** */
- public GridResourceMethodOverrideInjectionSelfTest() {
- super(/*start grid*/false);
- }
-
- /**
- * @throws Exception in the case of failures.
- */
- public void testMethodResourceOverride() throws Exception {
- Ignite ignite1 = null;
- Ignite ignite2 = null;
-
- try {
- ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
- ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));
-
- ignite1.compute().execute(MethodResourceOverrideTask.class, null);
-
- 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);
- }
-
- /** */
- @SuppressWarnings("PublicInnerClass")
- public static class UserResource1 extends GridAbstractUserResource {
- // No-op.
- }
-
- /** */
- @SuppressWarnings("PublicInnerClass")
- public static class UserResource2 extends GridAbstractUserResource {
- // No-op.
- }
-
- /**
- *
- */
- private abstract static class AbstractResourceTask extends ComputeTaskSplitAdapter<Object, Object> {
- /** */
- protected transient GridAbstractUserResource rsrc1;
-
- /** */
- protected transient UserResource2 rsrc2;
-
- /** */
- protected transient GridAbstractUserResource rsrc3;
-
- /** */
- protected transient UserResource2 rsrc4;
-
- /** */
- protected IgniteLogger log;
-
- /** */
- protected Ignite ignite;
-
- /** */
- protected String ggHome;
-
- /** */
- protected String gridName;
-
- /** */
- protected ApplicationContext springCtx;
-
- /** */
- protected ComputeTaskSession ses;
-
- /** */
- protected ComputeJobContext jobCtx;
-
- /** */
- protected transient ComputeTaskContinuousMapper mapper;
-
- /**
- * @param log GridLogger.
- */
- @SuppressWarnings({"UnusedDeclaration", "unused"})
- @IgniteLoggerResource
- private void setLog(IgniteLogger log) { this.log = log; }
-
- /**
- * @param ignite Grid.
- */
- @IgniteInstanceResource
- @SuppressWarnings("unused")
- void setIgnite(Ignite ignite) { this.ignite = ignite; }
-
- /**
- * @param springCtx Spring Application Context.
- */
- @IgniteSpringApplicationContextResource
- @SuppressWarnings("unused")
- void setSpringContext(ApplicationContext springCtx) { this.springCtx = springCtx; }
-
- /**
- * @param ses GridComputeTaskSession.
- */
- @IgniteTaskSessionResource
- @SuppressWarnings("unused")
- public void setSession(ComputeTaskSession ses) {
- this.ses = ses;
- }
-
- /**
- * @param jobCtx Job context.
- */
- @IgniteJobContextResource
- @SuppressWarnings("unused")
- public void setJobContext(ComputeJobContext jobCtx) {
- this.jobCtx = jobCtx;
- }
-
- /**
- * @param mapper continuous mapper.
- */
- @IgniteTaskContinuousMapperResource
- @SuppressWarnings("unused")
- public void setMapper(ComputeTaskContinuousMapper mapper) {
- this.mapper = mapper;
- }
- }
-
- /**
- *
- */
- private static class MethodResourceOverrideTask extends AbstractResourceTask {
- /**
- * @param log GridLogger. The grid logger resource.
- */
- @SuppressWarnings({"MethodOverridesPrivateMethodOfSuperclass", "unused"})
- @IgniteLoggerResource
- public void setLog(IgniteLogger log) {
- this.log = log;
- }
-
- /**
- * @param ignite Grid.
- */
- @IgniteInstanceResource
- @Override public void setIgnite(Ignite ignite) {
- this.ignite = ignite;
- }
-
- /**
- * @param jobCtx Job context.
- */
- @IgniteJobContextResource
- @Override public void setJobContext(ComputeJobContext jobCtx) {
- this.jobCtx = jobCtx;
-
- log.info("-->setJobContext identity: " + System.identityHashCode(this));
- }
-
- /** {@inheritDoc} */
- @Override protected Collection<ComputeJobAdapter> split(int gridSize, Object arg) throws IgniteCheckedException {
- assert rsrc1 != null;
- assert rsrc2 != null;
- assert rsrc3 != null;
- assert rsrc4 != null;
- assert log != null;
- assert ignite != null;
- assert ggHome != null;
- assert gridName != null;
- assert springCtx != null;
- assert ses != null;
- assert mapper != null;
-
- // Job context belongs to job, not task.
- assert jobCtx == null;
- log.info("-->Identity in the split: " + System.identityHashCode(this));
-
- log.info("Injected shared resource1 into task: " + rsrc1);
- log.info("Injected shared resource2 into task: " + rsrc2);
- log.info("Injected shared resource3 into task: " + rsrc3);
- log.info("Injected shared resource4 into task: " + rsrc4);
- log.info("Injected log resource into task: " + log);
- log.info("Injected grid resource into task: " + ignite);
- log.info("Injected gridgain home resource into task: " + ggHome);
- log.info("Injected grid name resource into task: " + gridName);
- log.info("Injected spring context resource into task: " + springCtx);
- 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() {
- /** */
- private transient GridAbstractUserResource rsrc5;
-
- /** */
- private transient UserResource2 rsrc6;
-
- /** */
- private transient GridAbstractUserResource rsrc7;
-
- /** */
- private transient UserResource2 rsrc8;
-
- /** */
- private ComputeJobContext jobCtx;
-
- /**
- * @param jobCtx Job context.
- */
- @SuppressWarnings("unused")
- @IgniteJobContextResource
- public void setJobContext(ComputeJobContext jobCtx) { this.jobCtx = jobCtx; }
-
- /** {@inheritDoc} */
- @Override public Serializable execute() {
- assert rsrc1 != null;
- assert rsrc2 != null;
- assert rsrc3 != null;
- assert rsrc4 != null;
- assert log != null;
- assert ignite != null;
- assert ggHome != null;
- assert gridName != null;
- assert springCtx != null;
- assert ses != null;
- assert jobCtx != null;
-
- assert rsrc5 != null;
- assert rsrc6 != null;
- assert rsrc7 != null;
- assert rsrc8 != null;
-
- //Job context is job resource, not task resource.
- assert MethodResourceOverrideTask.this.jobCtx == null;
- assert jobCtx != null;
-
- log.info("Injected shared resource1 into job: " + rsrc1);
- log.info("Injected shared resource2 into job: " + rsrc2);
- log.info("Injected shared resource3 into job: " + rsrc3);
- log.info("Injected shared resource4 into job: " + rsrc4);
- log.info("Injected shared resource5 into job: " + rsrc5);
- log.info("Injected shared resource6 into job: " + rsrc6);
- log.info("Injected shared resource7 into job: " + rsrc7);
- log.info("Injected shared resource8 into job: " + rsrc8);
- log.info("Injected log resource into job: " + log);
- log.info("Injected grid resource into job: " + ignite);
- log.info("Injected gridgain home resource into job: " + ggHome);
- log.info("Injected grid grid name resource into job: " + gridName);
- log.info("Injected spring context resource into job: " + springCtx);
- log.info("Injected session resource into job: " + ses);
- log.info("Injected job context resource into job: " + jobCtx);
-
- return null;
- }
- });
- }
-
- return jobs;
- }
-
- /** {@inheritDoc} */
- @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException {
- assert rsrc1 != null;
- assert rsrc2 != null;
- assert rsrc3 != null;
- assert rsrc4 != null;
- assert log != null;
- assert ignite != null;
- assert ggHome != null;
- assert gridName != null;
- assert springCtx != null;
- assert ses != null;
-
- // Job context belongs to job, not task.
- assert jobCtx == null;
-
- log.info("-->Identity in reduce: " + System.identityHashCode(this));
-
- // 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/GridResourceSharedUndeploySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceSharedUndeploySelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceSharedUndeploySelfTest.java
deleted file mode 100644
index 03885d7..0000000
--- a/modules/spring/src/test/java/org/gridgain/grid/kernal/processors/resource/GridResourceSharedUndeploySelfTest.java
+++ /dev/null
@@ -1,519 +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 shared class loader undeploy mode.
- */
-@GridCommonTest(group = "Resource Self")
-public class GridResourceSharedUndeploySelfTest 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 GridResourceSharedUndeploySelfTest() {
- 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(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- cfg.setDeploymentMode(IgniteDeploymentMode.SHARED);
-
- return cfg;
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testSameTaskLocally() 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.
- */
- public void testDifferentTaskLocally() throws Exception {
- Ignite ignite = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext()));
-
- try {
- // Execute the tasks with the same class loaders.
- // 1 resource created locally
- ignite.compute().execute(SharedResourceTask1.class, null);
- ignite.compute().execute(SharedResourceTask2.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.
- */
- public void testDifferentTaskNameLocally() throws Exception {
- Ignite ignite = startGrid(0, new GridSpringResourceContextImpl(new GenericApplicationContext()));
-
- // Versions are different - should not share
- // 2 resource created locally
- try {
- ignite.compute().execute(SharedResourceTask1Version1.class, null);
-
- try {
- ignite.compute().execute(SharedResourceTask1Version2.class, null);
-
- assert false : "SharedResourceTask4 should not be allowed to deploy.";
- }
- catch (IgniteCheckedException e) {
- info("Received expected exception: " + e);
- }
- }
- finally {
- GridTestUtils.close(ignite, log());
- }
- }
-
- /**
- * @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);
- 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 same task with different class loaders. Second execution should redeploy first one.
- 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.
- ClassLoader tstClsLdr = new GridTestClassLoader(null, getClass().getClassLoader(),
- SharedResourceTask1.class.getName(),
- GridResourceSharedUndeploySelfTest.SharedResourceTask1.GridSharedJob1.class.getName(),
- GridResourceSharedUndeploySelfTest.class.getName());
-
- Class<? extends ComputeTask<Object, Object>> taskCls =
- (Class<? extends ComputeTask<Object, Object>>)tstClsLdr.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 testSameTaskFromTwoNodesUndeploy() throws Exception {
- Ignite ignite1 = null;
- Ignite ignite2 = null;
- Ignite ignite3 = null;
-
- try {
- ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
- ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));
- ignite3 = startGrid(3, new GridSpringResourceContextImpl(new GenericApplicationContext()));
-
- ignite1.compute().execute(SharedResourceTask1.class, null);
- ignite2.compute().execute(SharedResourceTask1.class, null);
-
- checkUsageCount(createClss, UserResource1.class, 6);
- checkUsageCount(deployClss, UserResource1.class, 6);
- checkUsageCount(createClss, UserResource2.class, 6);
- checkUsageCount(deployClss, UserResource2.class, 6);
-
- checkUsageCount(undeployClss, UserResource1.class, 0);
- checkUsageCount(undeployClss, UserResource2.class, 0);
-
- ignite1.compute().undeployTask(SharedResourceTask1.class.getName());
-
- // Wait until resources get undeployed remotely
- // because undeploy is asynchronous apply.
- Thread.sleep(3000);
-
- checkUsageCount(undeployClss, UserResource1.class, 6);
- checkUsageCount(undeployClss, UserResource2.class, 6);
-
- ignite2.compute().undeployTask(SharedResourceTask1.class.getName());
-
- // Wait until resources get undeployed remotely
- // because undeploy is asynchronous apply.
- Thread.sleep(3000);
-
- // All Tasks from originating nodes were undeployed. All resources should be cleaned up.
- checkUsageCount(undeployClss, UserResource1.class, 6);
- checkUsageCount(undeployClss, UserResource2.class, 6);
- }
- finally {
- GridTestUtils.close(ignite1, log());
- GridTestUtils.close(ignite2, log());
- GridTestUtils.close(ignite3, log());
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testSameTaskFromTwoNodesLeft() throws Exception {
- Ignite ignite1 = null;
- Ignite ignite2 = null;
- Ignite ignite3 = null;
-
- try {
- ignite1 = startGrid(1, new GridSpringResourceContextImpl(new GenericApplicationContext()));
- ignite2 = startGrid(2, new GridSpringResourceContextImpl(new GenericApplicationContext()));
- ignite3 = startGrid(3, new GridSpringResourceContextImpl(new GenericApplicationContext()));
-
- ignite1.compute().execute(SharedResourceTask1.class, null);
- ignite2.compute().execute(SharedResourceTask1.class, null);
-
- checkUsageCount(createClss, UserResource1.class, 6);
- checkUsageCount(deployClss, UserResource1.class, 6);
- checkUsageCount(createClss, UserResource2.class, 6);
- checkUsageCount(deployClss, UserResource2.class, 6);
-
- checkUsageCount(undeployClss, UserResource1.class, 0);
- checkUsageCount(undeployClss, UserResource2.class, 0);
-
- GridTestUtils.close(ignite1, log());
-
- // Wait until other nodes get notified
- // this grid1 left.
- Thread.sleep(1000);
-
- // Undeployment happened only on Grid1.
- checkUsageCount(undeployClss, UserResource1.class, 2);
- checkUsageCount(undeployClss, UserResource2.class, 2);
-
- GridTestUtils.close(ignite2, log());
-
- // Wait until resources get undeployed remotely
- // because undeploy is asynchronous apply.
- Thread.sleep(1000);
-
- // Grid1 and Grid2
- checkUsageCount(undeployClss, UserResource1.class, 4);
- checkUsageCount(undeployClss, UserResource2.class, 4);
- }
- finally {
- GridTestUtils.close(ignite1, log());
- GridTestUtils.close(ignite2, log());
- GridTestUtils.close(ignite3, log());
- }
- }
-
- /** */
- public static class UserResource1 extends GridAbstractUserResource {
- // No-op.
- }
-
- /** */
- public static class UserResource2 extends GridAbstractUserResource {
- // No-op.
- }
-
- /** */
- @ComputeTaskName("SharedResourceTask1")
- public static class SharedResourceTask1Version1 extends SharedResourceTask1 {
- // No-op.
- }
-
- /** */
- @ComputeTaskName("SharedResourceTask1")
- public static class SharedResourceTask1Version2 extends SharedResourceTask1 {
- // 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;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PAbstractUserResource.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PAbstractUserResource.java b/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PAbstractUserResource.java
deleted file mode 100644
index 3c442a0..0000000
--- a/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PAbstractUserResource.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/* @java.file.header */
-
-/* _________ _____ __________________ _____
- * __ ____/___________(_)______ /__ ____/______ ____(_)_______
- * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
- * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
- * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
- */
-
-package org.gridgain.grid.p2p;
-
-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 GridP2PAbstractUserResource {
- /** */
- protected static final Map<Class<?>, Integer> createClss = new HashMap<>();
-
- /** */
- protected static final Map<Class<?>, Integer> deployClss = new HashMap<>();
-
- /** */
- protected static final Map<Class<?>, Integer> undeployClss = new HashMap<>();
-
- /** */
- @IgniteLoggerResource
- private IgniteLogger log;
-
- /** */
- @IgniteInstanceResource
- private Ignite ignite;
-
- /** */
- @IgniteSpringApplicationContextResource
- private ApplicationContext springCtx;
-
- /** */
- GridP2PAbstractUserResource() {
- addUsage(createClss);
- }
-
- /**
- * Resets counters.
- */
- public static void resetResourceCounters() {
- clearMap(createClss);
- clearMap(deployClss);
- clearMap(undeployClss);
- }
-
- /**
- * @param cls Class.
- * @param cnt Expected usage count.
- */
- public static void checkCreateCount(Class<?> cls, int cnt) {
- checkUsageCount(createClss, cls, cnt);
- }
-
- /**
- * @param cls Class.
- * @param cnt Expected usage count.
- */
- public static void checkDeployCount(Class<?> cls, int cnt) {
- checkUsageCount(deployClss, cls, cnt);
- }
-
- /**
- * @param cls Class.
- * @param cnt Expected usage count.
- */
- public static void checkUndeployCount(Class<?> cls, int cnt) {
- checkUsageCount(undeployClss, cls, cnt);
- }
-
- /**
- * @param usage Usage map.
- * @param cls Class.
- * @param cnt Expected usage count.
- */
- public static void checkUsageCount(Map<Class<?>, Integer> usage, Class<?> cls, int cnt) {
- Integer used;
-
- synchronized (usage) {
- used = usage.get(cls);
- }
-
- if (used == null)
- used = 0;
-
- assert used == cnt : "Invalid count [expected=" + cnt + ", actual=" + used + ", usageMap=" + usage + ']';
- }
-
- /**
- * @param map Map to clear.
- */
- private static void clearMap(final Map<Class<?>, Integer> map) {
- synchronized (map) {
- map.clear();
- }
- }
-
- /** */
- @SuppressWarnings("unused")
- private void neverCalled() {
- assert false;
- }
-
- /**
- * @param map Usage map to check.
- */
- protected void addUsage(final 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/p2p/GridP2PContinuousLocalDeploySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PContinuousLocalDeploySelfTest.java b/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PContinuousLocalDeploySelfTest.java
deleted file mode 100644
index c285781..0000000
--- a/modules/spring/src/test/java/org/gridgain/grid/p2p/GridP2PContinuousLocalDeploySelfTest.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/* @java.file.header */
-
-/* _________ _____ __________________ _____
- * __ ____/___________(_)______ /__ ____/______ ____(_)_______
- * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
- * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
- * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
- */
-
-package org.gridgain.grid.p2p;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
-import org.apache.ignite.compute.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.resources.*;
-import org.gridgain.grid.*;
-import org.gridgain.grid.kernal.processors.resource.*;
-import org.gridgain.testframework.junits.common.*;
-import org.jetbrains.annotations.*;
-import org.springframework.context.support.*;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * The test do the following:
- *
- * First test:
- * 1. Start 3 nodes: N1, N2, N3
- * 2. execute task1 from N1 on N2.
- * 3. execute task2 from N3 on N2.
- * 4. Make sure that task1 and task2 share class loader on N2
- * (of course assuming that they share class loader on their originating nodes).
- * 5. Make sure that user resources are created once and shared thereafter.
- *
- * Second Test:
- * 1. Start 3 nodes in SHARED_DEPLOY mode: N1, N2, N3
- * 2. execute task1 from N1 on N2.
- * 3. Stop N1.
- * 3. execute task2 from N3 on N2.
- * 4. Make sure that task1 and task2 share class loader on N2 (of course assuming that they share class loader on their originating nodes).
- * 5. Make sure that user resources are created once and shared thereafter.
- */
-@SuppressWarnings({"ProhibitedExceptionDeclared", "PublicInnerClass"})
-@GridCommonTest(group = "P2P")
-public class GridP2PContinuousLocalDeploySelfTest extends GridCommonAbstractTest {
- /** */
- private static UUID node2Id;
-
- /** */
- private static ClassLoader clsLdr1;
-
- /** */
- private static ClassLoader clsLdr2;
-
- /** */
- public GridP2PContinuousLocalDeploySelfTest() {
- super(/*start grid*/false);
- }
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- cfg.setDeploymentMode(IgniteDeploymentMode.CONTINUOUS);
-
- return cfg;
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- GridP2PAbstractUserResource.resetResourceCounters();
- }
-
- /**
- * @throws Exception if error occur
- */
- public void testContinuousMode() throws Exception {
- 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()));
-
- node2Id = ignite2.cluster().localNode().id();
-
- ignite1.compute().execute(SharedResourceTask1.class, null);
- ignite1.compute().execute(SharedResourceTask2.class, null);
-
- // 2 instances: one instance of resource for task and one instance for
- // job, because job execute on remote node.
- GridP2PAbstractUserResource.checkCreateCount(UserResource1.class, 2);
- GridP2PAbstractUserResource.checkCreateCount(UserResource2.class, 2);
-
- assertEquals(clsLdr1, clsLdr2);
-
- ignite3.compute().execute(SharedResourceTask1.class, null);
- ignite3.compute().execute(SharedResourceTask2.class, null);
-
- // 3 instances: one instance for each nodes.
- GridP2PAbstractUserResource.checkCreateCount(UserResource1.class, 3);
- GridP2PAbstractUserResource.checkCreateCount(UserResource2.class, 3);
-
- assertEquals(clsLdr1, clsLdr2);
- }
- finally {
- stopGrid(3);
- stopGrid(2);
- stopGrid(1);
- }
-
- GridP2PAbstractUserResource.checkUndeployCount(UserResource1.class, 3);
- GridP2PAbstractUserResource.checkUndeployCount(UserResource2.class, 3);
- }
-
- /**
- * @throws Exception if error occur
- */
- public void testContinuousModeNodeRestart() throws Exception {
- 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()));
-
- node2Id = ignite2.cluster().localNode().id();
-
- ignite1.compute().execute(SharedResourceTask1.class, null);
- ignite1.compute().execute(SharedResourceTask2.class, null);
-
- GridP2PAbstractUserResource.checkCreateCount(UserResource1.class, 2);
- GridP2PAbstractUserResource.checkCreateCount(UserResource2.class, 2);
-
- assertEquals(clsLdr1, clsLdr2);
-
- stopGrid(1);
-
- Thread.sleep(2000);
-
- GridP2PAbstractUserResource.checkUndeployCount(UserResource1.class, 1);
- GridP2PAbstractUserResource.checkUndeployCount(UserResource2.class, 1);
-
- ignite3.compute().execute(SharedResourceTask1.class, null);
- ignite3.compute().execute(SharedResourceTask2.class, null);
-
- // 3 instances: one instance for each nodes.
- GridP2PAbstractUserResource.checkCreateCount(UserResource1.class, 3);
- GridP2PAbstractUserResource.checkCreateCount(UserResource2.class, 3);
-
- assertEquals(clsLdr1, clsLdr2);
- }
- finally {
- stopGrid(1);
- stopGrid(2);
- stopGrid(3);
- }
-
- GridP2PAbstractUserResource.checkUndeployCount(UserResource1.class, 3);
- GridP2PAbstractUserResource.checkUndeployCount(UserResource2.class, 3);
- }
-
- /** */
- public static class UserResource1 extends GridP2PAbstractUserResource {
- // No-op.
- }
-
- /** */
- public static class UserResource2 extends GridP2PAbstractUserResource {
- // No-op.
- }
-
-
- /**
- * First task.
- */
- public static class SharedResourceTask1 extends ComputeTaskAdapter<Object, Object> {
- /** Logger. */
- @IgniteLoggerResource
- private IgniteLogger log;
-
- /** Grid instance. */
- @IgniteInstanceResource
- private Ignite ignite;
-
- /** {@inheritDoc} */
- @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) throws IgniteCheckedException {
- return Collections.<ComputeJob, ClusterNode>singletonMap(
- new GridSharedJob1(), ignite.cluster().node(node2Id));
- }
-
- /** {@inheritDoc} */
- @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException {
- // Nothing to reduce.
- return null;
- }
- }
-
- /**
- * Job class for the 1st task.
- */
- public static final class GridSharedJob1 extends ComputeJobAdapter {
- /** */
- @IgniteLoggerResource
- private IgniteLogger log;
-
- /** {@inheritDoc} */
- @SuppressWarnings({"ObjectEquality"})
- @Override public Serializable execute() {
- log.info("Injected log resource into job: " + log);
-
- clsLdr1 = getClass().getClassLoader();
-
- return null;
- }
- }
-
- /**
- * Second task.
- */
- public static class SharedResourceTask2 extends ComputeTaskAdapter<Object, Object> {
- /** Logger. */
- @IgniteLoggerResource
- private IgniteLogger log;
-
- /** Grid instance. */
- @IgniteInstanceResource
- private Ignite ignite;
-
- /** {@inheritDoc} */
- @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) throws IgniteCheckedException {
- return Collections.<ComputeJob, ClusterNode>singletonMap(
- new GridSharedJob2(), ignite.cluster().node(node2Id));
- }
-
- /** {@inheritDoc} */
- @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException {
- // Nothing to reduce.
- return null;
- }
- }
-
- /**
- * Job class for the 2st task.
- */
- public static final class GridSharedJob2 extends ComputeJobAdapter {
- /** */
- @IgniteLoggerResource
- private IgniteLogger log;
-
- /** {@inheritDoc} */
- @SuppressWarnings({"ObjectEquality"})
- @Override public Serializable execute() {
- log.info("Injected log resource into job: " + log);
-
- clsLdr2 = getClass().getClassLoader();
-
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a1763213/modules/spring/src/test/java/org/gridgain/testsuites/GridResourceSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/gridgain/testsuites/GridResourceSelfTestSuite.java b/modules/spring/src/test/java/org/gridgain/testsuites/GridResourceSelfTestSuite.java
index 03fa099..b1ec9aa 100644
--- a/modules/spring/src/test/java/org/gridgain/testsuites/GridResourceSelfTestSuite.java
+++ b/modules/spring/src/test/java/org/gridgain/testsuites/GridResourceSelfTestSuite.java
@@ -24,19 +24,9 @@ public class GridResourceSelfTestSuite extends TestSuite {
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite("Gridgain Resource Injection Test Suite");
- suite.addTest(new TestSuite(GridResourceFieldInjectionSelfTest.class));
- suite.addTest(new TestSuite(GridResourceFieldOverrideInjectionSelfTest.class));
- suite.addTest(new TestSuite(GridResourceMethodInjectionSelfTest.class));
- suite.addTest(new TestSuite(GridResourceMethodOverrideInjectionSelfTest.class));
suite.addTest(new TestSuite(GridResourceProcessorSelfTest.class));
- suite.addTest(new TestSuite(GridResourceIsolatedTaskSelfTest.class));
- suite.addTest(new TestSuite(GridResourceIsolatedClassLoaderSelfTest.class));
- suite.addTest(new TestSuite(GridResourceSharedUndeploySelfTest.class));
- suite.addTest(new TestSuite(GridResourceEventFilterSelfTest.class));
suite.addTest(new TestSuite(GridLoggerInjectionSelfTest.class));
suite.addTest(new TestSuite(GridServiceInjectionSelfTest.class));
- suite.addTest(new TestSuite(GridResourceConcurrentUndeploySelfTest.class));
- suite.addTest(new TestSuite(GridResourceIocSelfTest.class));
return suite;
}