http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridExplicitImplicitDeploymentSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridExplicitImplicitDeploymentSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridExplicitImplicitDeploymentSelfTest.java deleted file mode 100644 index 6819f93..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridExplicitImplicitDeploymentSelfTest.java +++ /dev/null @@ -1,476 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -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.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; - -/** - * - */ -@GridCommonTest(group = "Kernal Self") -public class GridExplicitImplicitDeploymentSelfTest extends GridCommonAbstractTest { - /** */ - public GridExplicitImplicitDeploymentSelfTest() { - super(/*start grid*/false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - // Override P2P configuration to exclude Task and Job classes - cfg.setPeerClassLoadingLocalClassPathExclude(GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName()); - - cfg.setDeploymentMode(IgniteDeploymentMode.ISOLATED); - - return cfg; - } - - /** - * @throws Exception If test failed. - */ - public void testImplicitDeployLocally() throws Exception { - execImplicitDeployLocally(true, true, true); - } - - /** - * @throws Exception If test failed. - */ - public void testImplicitDeployP2P() throws Exception { - execImplicitDeployP2P(true, true, true); - } - - /** - * @throws Exception If test failed. - */ - public void testExplicitDeployLocally() throws Exception { - execExplicitDeployLocally(true, true, true); - } - - /** - * @throws Exception If test failed. - */ - public void testExplicitDeployP2P() throws Exception { - execExplicitDeployP2P(true, true, true); - } - - /** - * @param ignite Grid. - */ - @SuppressWarnings({"CatchGenericClass"}) - private void stopGrid(Ignite ignite) { - try { - if (ignite != null) - G.stop(ignite.name(), true); - } - catch (Throwable e) { - error("Got error when stopping grid.", e); - } - } - - /** - * @param byCls If {@code true} than executes task by Class. - * @param byTask If {@code true} than executes task instance. - * @param byName If {@code true} than executes task by class name. - * @throws Exception If test failed. - */ - @SuppressWarnings("unchecked") - private void execExplicitDeployLocally(boolean byCls, boolean byTask, boolean byName) throws Exception { - Ignite ignite = null; - - try { - ignite = startGrid(); - - // Explicit Deployment. Task execution should return 0. - // Say resource class loader - different to task one. - ClassLoader ldr1 = new GridTestClassLoader( - Collections.singletonMap("testResource", "1"), - getClass().getClassLoader()); - - // Assume that users task and job were loaded with this class loader - ClassLoader ldr2 = new GridTestClassLoader( - Collections.singletonMap("testResource", "2"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - info("Loader1: " + ldr1); - info("Loader2: " + ldr2); - - Class<? extends ComputeTask<String, Integer>> taskCls = (Class<? extends ComputeTask<String, Integer>>) - ldr2.loadClass(GridDeploymentResourceTestTask.class.getName()); - - // Check auto-deploy. It should pick up resource class loader. - if (byCls) { - ignite.compute().localDeployTask(taskCls, ldr1); - - Integer res = ignite.compute().execute(taskCls, null); - - assert res != null; - assert res == 2 : "Invalid response: " + res; - } - - if (byTask) { - ignite.compute().localDeployTask(taskCls, ldr1); - - Integer res = ignite.compute().execute(taskCls.newInstance(), null); - - assert res != null; - assert res == 2 : "Invalid response: " + res; - } - - if (byName) { - ignite.compute().localDeployTask(taskCls, ldr1); - - Integer res = (Integer) ignite.compute().execute(taskCls.getName(), null); - - assert res != null; - assert res == 1 : "Invalid response: " + res; - } - } - finally { - stopGrid(ignite); - } - } - - /** - * @param byCls If {@code true} than executes task by Class. - * @param byTask If {@code true} than executes task instance. - * @param byName If {@code true} than executes task by class name. - * @throws Exception If test failed. - */ - @SuppressWarnings("unchecked") - private void execImplicitDeployLocally(boolean byCls, boolean byTask, boolean byName) throws Exception { - Ignite ignite = null; - - try { - ignite = startGrid(); - - // First task class loader. - ClassLoader ldr1 = new GridTestClassLoader( - Collections.singletonMap("testResource", "1"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - // Second task class loader - ClassLoader ldr2 = new GridTestClassLoader( - Collections.singletonMap("testResource", "2"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - // The same name but different classes/ class loaders. - Class<? extends ComputeTask<String, Integer>> taskCls1 = (Class<? extends ComputeTask<String, Integer>>) - ldr1.loadClass(GridDeploymentResourceTestTask.class.getName()); - - Class<? extends ComputeTask<String, Integer>> taskCls2 = (Class<? extends ComputeTask<String, Integer>>) - ldr2.loadClass(GridDeploymentResourceTestTask.class.getName()); - - if (byCls) { - Integer res1 = ignite.compute().execute(taskCls1, null); - Integer res2 = ignite.compute().execute(taskCls2, null); - - assert res1 != null; - assert res2 != null; - - assert res1 == 1 : "Invalid res1: " + res1; - assert res2 == 2 : "Invalid res2: " + res2; - } - - if (byTask) { - Integer res1 = ignite.compute().execute(taskCls1.newInstance(), null); - Integer res2 = ignite.compute().execute(taskCls2.newInstance(), null); - - assert res1 != null; - assert res2 != null; - - assert res1 == 1 : "Invalid res1: " + res1; - assert res2 == 2 : "Invalid res2: " + res2; - } - - if (byName) { - ignite.compute().localDeployTask(taskCls1, ldr1); - - Integer res1 = (Integer) ignite.compute().execute(taskCls1.getName(), null); - - ignite.compute().localDeployTask(taskCls2, ldr2); - - Integer res2 = (Integer) ignite.compute().execute(taskCls2.getName(), null); - - assert res1 != null; - assert res2 != null; - - assert res1 == 1 : "Invalid res1: " + res1; - assert res2 == 2 : "Invalid res2: " + res2; - } - } - finally { - stopGrid(ignite); - } - } - - /** - * @param byCls If {@code true} than executes task by Class. - * @param byTask If {@code true} than executes task instance. - * @param byName If {@code true} than executes task by class name. - * @throws Exception If test failed. - */ - @SuppressWarnings("unchecked") - private void execExplicitDeployP2P(boolean byCls, boolean byTask, boolean byName) throws Exception { - Ignite ignite1 = null; - Ignite ignite2 = null; - - try { - ignite1 = startGrid(1); - ignite2 = startGrid(2); - - ClassLoader ldr1 = new GridTestClassLoader( - Collections.singletonMap("testResource", "1"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - ClassLoader ldr2 = new GridTestClassLoader( - Collections.singletonMap("testResource", "2"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - Class<? extends ComputeTask<String, Integer>> taskCls = (Class<? extends ComputeTask<String, Integer>>) - ldr2.loadClass(GridDeploymentResourceTestTask.class.getName()); - - if (byCls) { - ignite1.compute().localDeployTask(taskCls, ldr1); - - // Even though the task is deployed with resource class loader, - // when we execute it, it will be redeployed with task class-loader. - Integer res = ignite1.compute().execute(taskCls, null); - - assert res != null; - assert res == 2 : "Invalid response: " + res; - } - - - if (byTask) { - ignite1.compute().localDeployTask(taskCls, ldr1); - - // Even though the task is deployed with resource class loader, - // when we execute it, it will be redeployed with task class-loader. - Integer res = ignite1.compute().execute(taskCls.newInstance(), null); - - assert res != null; - assert res == 2 : "Invalid response: " + res; - } - - if (byName) { - ignite1.compute().localDeployTask(taskCls, ldr1); - - // Even though the task is deployed with resource class loader, - // when we execute it, it will be redeployed with task class-loader. - Integer res = (Integer) ignite1.compute().execute(taskCls.getName(), null); - - assert res != null; - assert res == 1 : "Invalid response: " + res; - } - } - finally { - stopGrid(ignite2); - stopGrid(ignite1); - } - } - - /** - * @param byCls If {@code true} than executes task by Class. - * @param byTask If {@code true} than executes task instance. - * @param byName If {@code true} than executes task by class name. - * @throws Exception If test failed. - */ - @SuppressWarnings("unchecked") - private void execImplicitDeployP2P(boolean byCls, boolean byTask, boolean byName) throws Exception { - Ignite ignite1 = null; - Ignite ignite2 = null; - - try { - ignite1 = startGrid(1); - ignite2 = startGrid(2); - - ClassLoader ldr1 = new GridTestClassLoader( - Collections.singletonMap("testResource", "1"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - ClassLoader ldr2 = new GridTestClassLoader( - Collections.singletonMap("testResource", "2"), - getClass().getClassLoader(), - GridDeploymentResourceTestTask.class.getName(), - GridDeploymentResourceTestJob.class.getName() - ); - - Class<? extends ComputeTask<String, Integer>> taskCls1 = (Class<? extends ComputeTask<String, Integer>>) - ldr1.loadClass(GridDeploymentResourceTestTask.class.getName()); - - Class<? extends ComputeTask<String, Integer>> taskCls2 = (Class<? extends ComputeTask<String, Integer>>) - ldr2.loadClass(GridDeploymentResourceTestTask.class.getName()); - - if (byCls) { - Integer res1 = ignite1.compute().execute(taskCls1, null); - Integer res2 = ignite1.compute().execute(taskCls2, null); - - assert res1 != null; - assert res2 != null; - - assert res1 == 1 : "Invalid res1: " + res1; - assert res2 == 2 : "Invalid res2: " + res2; - } - - if (byTask) { - Integer res1 = ignite1.compute().execute(taskCls1.newInstance(), null); - Integer res2 = ignite1.compute().execute(taskCls2.newInstance(), null); - - assert res1 != null; - assert res2 != null; - - assert res1 == 1 : "Invalid res1: " + res1; - assert res2 == 2 : "Invalid res2: " + res2; - } - - if (byName) { - ignite1.compute().localDeployTask(taskCls1, ldr1); - - Integer res1 = (Integer) ignite1.compute().execute(taskCls1.getName(), null); - - ignite1.compute().localDeployTask(taskCls2, ldr2); - - Integer res2 = (Integer) ignite1.compute().execute(taskCls2.getName(), null); - - assert res1 != null; - assert res2 != null; - - assert res1 == 1 : "Invalid res1: " + res1; - assert res2 == 2 : "Invalid res2: " + res2; - } - } - finally { - stopGrid(ignite1); - stopGrid(ignite2); - } - } - - /** - * We use custom name to avoid auto-deployment in the same VM. - */ - @SuppressWarnings({"PublicInnerClass"}) - @ComputeTaskName("GridDeploymentResourceTestTask") - public static class GridDeploymentResourceTestTask extends ComputeTaskAdapter<String, Integer> { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) throws IgniteCheckedException { - Map<ComputeJobAdapter, ClusterNode> map = new HashMap<>(subgrid.size()); - - boolean ignoreLocNode = false; - - UUID locId = ignite.configuration().getNodeId(); - - if (subgrid.size() == 1) - assert subgrid.get(0).id().equals(locId) : "Wrong node id."; - else - ignoreLocNode = true; - - for (ClusterNode node : subgrid) { - // Ignore local node. - if (ignoreLocNode && node.id().equals(locId)) - continue; - - map.put(new GridDeploymentResourceTestJob(), node); - } - - return map; - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return results.get(0).getData(); - } - } - - /** - * Simple job for this test. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static final class GridDeploymentResourceTestJob extends ComputeJobAdapter { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override public Serializable execute() throws IgniteCheckedException { - if (log.isInfoEnabled()) - log.info("Executing grid job: " + this); - - try { - ClassLoader ldr = Thread.currentThread().getContextClassLoader(); - - if (log.isInfoEnabled()) - log.info("Loader (inside job): " + ldr); - - InputStream in = ldr.getResourceAsStream("testResource"); - - if (in != null) { - Reader reader = new InputStreamReader(in); - - try { - char res = (char)reader.read(); - - return Integer.parseInt(Character.toString(res)); - } - finally { - U.close(in, null); - } - } - - return null; - } - catch (IOException e) { - throw new IgniteCheckedException("Failed to execute job.", e); - } - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFactoryVmShutdownTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFactoryVmShutdownTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridFactoryVmShutdownTest.java deleted file mode 100644 index d8e40d8..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFactoryVmShutdownTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.lifecycle.*; -import org.apache.ignite.internal.util.typedef.*; -import org.jetbrains.annotations.*; - -import java.util.concurrent.*; - -import static org.apache.ignite.IgniteState.*; - -/** - * Tests for {@link org.apache.ignite.Ignition}. - */ -public class GridFactoryVmShutdownTest { - /** - * - */ - private GridFactoryVmShutdownTest() { - // No-op. - } - - /** - * @param args Args (optional). - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - final ConcurrentMap<String, IgniteState> states = new ConcurrentHashMap<>(); - - G.addListener(new IgniteListener() { - @Override public void onStateChange(@Nullable String name, IgniteState state) { - if (state == STARTED) { - IgniteState state0 = states.put(maskNull(name), STARTED); - - assert state0 == null; - } - else { - assert state == STOPPED; - - boolean replaced = states.replace(maskNull(name), STARTED, STOPPED); - - assert replaced; - } - } - }); - - // Test with shutdown hook enabled and disabled. - // System.setProperty(GridSystemProperties.GG_NO_SHUTDOWN_HOOK, "true"); - - // Grid will start and add shutdown hook. - G.start(); - - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - @Override public void run() { - IgniteConfiguration cfg = new IgniteConfiguration(); - - cfg.setGridName("test1"); - - try { - G.start(cfg); - } - catch (IgniteCheckedException e) { - throw new IgniteException("Failed to start grid in shutdown hook.", e); - } - finally { - X.println("States: " + states); - } - } - })); - - System.exit(0); - } - - /** - * Masks {@code null} string. - * - * @param s String to mask. - * @return Mask value or string itself if it is not {@code null}. - */ - private static String maskNull(String s) { - return s != null ? s : "null-mask-8AE34BF8"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailedInputParametersSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailedInputParametersSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailedInputParametersSelfTest.java deleted file mode 100644 index 347ce4a..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailedInputParametersSelfTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.junits.common.*; - -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * Test for invalid input parameters. - */ -@GridCommonTest(group = "Kernal Self") -public class GridFailedInputParametersSelfTest extends GridCommonAbstractTest { - /** */ - private static Ignite ignite; - - /** */ - public GridFailedInputParametersSelfTest() { - super(/*start grid*/true); - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - ignite = G.ignite(getTestGridName()); - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testAddEventLocalListener() throws Exception { - try { - ignite.events().localListen(null, EVTS_ALL); - - assert false : "Null listener can't be added."; - } - catch (NullPointerException ignored) { - // No-op. - } - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testRemoveEventLocalListener() throws Exception { - try { - ignite.events().stopLocalListen(null); - - assert false : "Null listener can't be removed."; - } - catch (NullPointerException ignored) { - // No-op. - } - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testAddDiscoveryListener() throws Exception { - try { - ignite.events().localListen(null, EVTS_ALL); - - assert false : "Null listener can't be added."; - } - catch (NullPointerException ignored) { - // No-op. - } - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testRemoveDiscoveryListener() throws Exception { - try { - ignite.events().stopLocalListen(null); - - assert false : "Null listener can't be removed."; - } - catch (NullPointerException ignored) { - // No-op. - } - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testGetNode() throws Exception { - try { - ignite.cluster().node(null); - - assert false : "Null nodeId can't be entered."; - } - catch (NullPointerException ignored) { - // No-op. - } - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testPingNode() throws Exception { - try { - ignite.cluster().pingNode(null); - - assert false : "Null nodeId can't be entered."; - } - catch (NullPointerException ignored) { - // No-op. - } - } - - /** - * @throws Exception Thrown in case of any errors. - */ - public void testDeployTask() throws Exception { - try { - ignite.compute().localDeployTask(null, null); - - assert false : "Null task can't be entered."; - } - catch (NullPointerException ignored) { - // No-op. - } - - try { - ignite.compute().localDeployTask(null, null); - - assert false : "Null task can't be entered."; - } - catch (NullPointerException ignored) { - // No-op. - } - - // Check for exceptions. - ignite.compute().localDeployTask(GridTestTask.class, U.detectClassLoader(GridTestTask.class)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverCustomTopologySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverCustomTopologySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverCustomTopologySelfTest.java deleted file mode 100644 index ed06597..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverCustomTopologySelfTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -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.apache.ignite.spi.failover.*; -import org.apache.ignite.spi.failover.always.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Test failover and custom topology. Topology returns local node if remote node fails. - */ -@GridCommonTest(group = "Kernal Self") -public class GridFailoverCustomTopologySelfTest extends GridCommonAbstractTest { - /** */ - private final AtomicInteger failCnt = new AtomicInteger(0); - - /** */ - private static final Object mux = new Object(); - - /** */ - public GridFailoverCustomTopologySelfTest() { - super(/*start Grid*/false); - } - - /** {@inheritDoc} */ - @SuppressWarnings("deprecation") - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setNodeId(null); - - cfg.setFailoverSpi(new AlwaysFailoverSpi() { - /** {@inheritDoc} */ - @Override public ClusterNode failover(FailoverContext ctx, List<ClusterNode> top) { - failCnt.incrementAndGet(); - - return super.failover(ctx, top); - } - }); - - return cfg; - } - /** - * Tests that failover don't pick local node if it has been excluded from topology. - * - * @throws Exception If failed. - */ - @SuppressWarnings({"WaitNotInLoop", "UnconditionalWait", "unchecked"}) - public void testFailoverTopology() throws Exception { - try { - Ignite ignite1 = startGrid(1); - Ignite ignite2 = startGrid(2); - - assert ignite1 != null; - assert ignite2 != null; - - ignite1.compute().localDeployTask(JobTask.class, JobTask.class.getClassLoader()); - - try { - ComputeTaskFuture<String> fut; - - synchronized(mux){ - IgniteCompute comp = ignite1.compute().enableAsync(); - - comp.execute(JobTask.class, null); - - fut = comp.future(); - - mux.wait(); - } - - stopAndCancelGrid(2); - - String res = fut.get(); - - info("Task result: " + res); - } - catch (IgniteCheckedException e) { - info("Got unexpected grid exception: " + e); - } - - info("Failed over: " + failCnt.get()); - - assert failCnt.get() == 1 : "Invalid fail over counter [expected=1, actual=" + failCnt.get() + ']'; - } - finally { - stopGrid(1); - - // Stopping stopped instance just in case. - stopGrid(2); - } - } - - /** */ - @SuppressWarnings("PublicInnerClass") - public static class JobTask extends ComputeTaskAdapter<String, String> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) throws IgniteCheckedException { - assert ignite != null; - - UUID locNodeId = ignite.configuration().getNodeId(); - - assert locNodeId != null; - - if (log.isInfoEnabled()) - log.info("Mapping jobs [subgrid=" + subgrid + ", arg=" + arg + ']'); - - ClusterNode remoteNode = null; - - for (ClusterNode node : subgrid) { - if (!node.id().equals(locNodeId)) - remoteNode = node; - } - - return Collections.singletonMap(new ComputeJobAdapter(locNodeId) { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @SuppressWarnings("NakedNotify") - @Override public Serializable execute() throws IgniteCheckedException { - assert ignite != null; - - UUID nodeId = ignite.configuration().getNodeId(); - - assert nodeId != null; - - if (!nodeId.equals(argument(0))) { - try { - synchronized(mux) { - mux.notifyAll(); - } - - Thread.sleep(Integer.MAX_VALUE); - } - catch (InterruptedException e) { - throw new ComputeExecutionRejectedException("Expected interruption during execution.", e); - } - } - else - return "success"; - - throw new ComputeExecutionRejectedException("Expected exception during execution."); - } - }, remoteNode); - } - - /** {@inheritDoc} */ - @Override public String reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - return results.get(0).getData(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverSelfTest.java deleted file mode 100644 index 4c63525..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverSelfTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -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.apache.ignite.spi.failover.always.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Failover tests. - */ -@GridCommonTest(group = "Kernal Self") -public class GridFailoverSelfTest extends GridCommonAbstractTest { - /** Initial node that job has been mapped to. */ - private static final AtomicReference<ClusterNode> nodeRef = new AtomicReference<>(null); - - /** */ - public GridFailoverSelfTest() { - super(/*start Grid*/false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setFailoverSpi(new AlwaysFailoverSpi()); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - public void testJobFail() throws Exception { - try { - Ignite ignite1 = startGrid(1); - Ignite ignite2 = startGrid(2); - - assert ignite1 != null; - assert ignite2 != null; - - Integer res = ignite1.compute().withTimeout(10000).execute(JobFailTask.class.getName(), "1"); - - assert res != null; - assert res == 1; - } - finally { - stopGrid(1); - stopGrid(2); - } - } - - /** - * - */ - @ComputeTaskSessionFullSupport - private static class JobFailTask implements ComputeTask<String, Object> { - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession ses; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) throws IgniteCheckedException { - ses.setAttribute("fail", true); - - nodeRef.set(subgrid.get(0)); - - return Collections.singletonMap(new ComputeJobAdapter(arg) { - /** Ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Serializable execute() throws IgniteCheckedException { - boolean fail; - - UUID locId = ignite.configuration().getNodeId(); - - try { - fail = ses.<String, Boolean>waitForAttribute("fail", 0); - } - catch (InterruptedException e) { - throw new IgniteCheckedException("Got interrupted while waiting for attribute to be set.", e); - } - - if (fail) { - ses.setAttribute("fail", false); - - assert nodeRef.get().id().equals(locId); - - throw new IgniteCheckedException("Job exception."); - } - - assert !nodeRef.get().id().equals(locId); - - // This job does not return any result. - return Integer.parseInt(this.<String>argument(0)); - } - }, subgrid.get(0)); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, - List<ComputeJobResult> received) throws IgniteCheckedException { - if (res.getException() != null && !(res.getException() instanceof ComputeUserUndeclaredException)) { - assert res.getNode().id().equals(nodeRef.get().id()); - - return ComputeJobResultPolicy.FAILOVER; - } - - assert !res.getNode().id().equals(nodeRef.get().id()); - - return ComputeJobResultPolicy.REDUCE; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - assert nodeRef.get() != null; - - assert !results.get(0).getNode().id().equals(nodeRef.get().id()) : - "Initial node and result one are the same (should be different)."; - - return results.get(0).getData(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTaskWithPredicateSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTaskWithPredicateSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTaskWithPredicateSelfTest.java deleted file mode 100644 index f355052..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTaskWithPredicateSelfTest.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.marshaller.optimized.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.spi.failover.*; -import org.apache.ignite.spi.failover.always.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Test failover of a task with Node filter predicate. - */ -@GridCommonTest(group = "Kernal Self") -public class GridFailoverTaskWithPredicateSelfTest extends GridCommonAbstractTest { - /** First node's name. */ - private static final String NODE1 = "NODE1"; - - /** Second node's name. */ - private static final String NODE2 = "NODE2"; - - /** Third node's name. */ - private static final String NODE3 = "NODE3"; - - /** Predicate to exclude the second node from topology */ - private final IgnitePredicate<ClusterNode> p = new IgnitePredicate<ClusterNode>() { - @Override - public boolean apply(ClusterNode e) { - return !NODE2.equals(e.attribute(GridNodeAttributes.ATTR_GRID_NAME)); - } - }; - - /** Whether delegating fail over node was found or not. */ - private final AtomicBoolean routed = new AtomicBoolean(); - - /** Whether job execution failed with exception. */ - private final AtomicBoolean failed = new AtomicBoolean(); - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setFailoverSpi(new AlwaysFailoverSpi() { - /** {@inheritDoc} */ - @Override public ClusterNode failover(FailoverContext ctx, List<ClusterNode> grid) { - ClusterNode failoverNode = super.failover(ctx, grid); - - if (failoverNode != null) - routed.set(true); - else - routed.set(false); - - return failoverNode; - } - }); - - cfg.setMarshaller(new IgniteOptimizedMarshaller(false)); - - return cfg; - } - - /** - * Tests that failover doesn't happen on two-node grid when the Task is applicable only for the first node - * and fails on it. - * - * @throws Exception If failed. - */ - public void testJobNotFailedOver() throws Exception { - failed.set(false); - routed.set(false); - - try { - Ignite ignite1 = startGrid(NODE1); - Ignite ignite2 = startGrid(NODE2); - - assert ignite1 != null; - assert ignite2 != null; - - compute(ignite1.cluster().forPredicate(p)).withTimeout(10000).execute(JobFailTask.class.getName(), "1"); - } - catch (ClusterTopologyException ignored) { - failed.set(true); - } - finally { - assertTrue(failed.get()); - assertFalse(routed.get()); - - stopGrid(NODE1); - stopGrid(NODE2); - } - } - - /** - * Tests that failover happens on three-node grid when the Task is applicable for the first node - * and fails on it, but is also applicable on another node. - * - * @throws Exception If failed. - */ - public void testJobFailedOver() throws Exception { - failed.set(false); - routed.set(false); - - try { - Ignite ignite1 = startGrid(NODE1); - Ignite ignite2 = startGrid(NODE2); - Ignite ignite3 = startGrid(NODE3); - - assert ignite1 != null; - assert ignite2 != null; - assert ignite3 != null; - - Integer res = (Integer)compute(ignite1.cluster().forPredicate(p)).withTimeout(10000). - execute(JobFailTask.class.getName(), "1"); - - assert res == 1; - } - catch (ClusterTopologyException ignored) { - failed.set(true); - } - finally { - assertFalse(failed.get()); - assertTrue(routed.get()); - - stopGrid(NODE1); - stopGrid(NODE2); - stopGrid(NODE3); - } - } - - /** - * Tests that in case of failover our predicate is intersected with projection - * (logical AND is performed). - * - * @throws Exception If error happens. - */ - public void testJobNotFailedOverWithStaticProjection() throws Exception { - failed.set(false); - routed.set(false); - - try { - Ignite ignite1 = startGrid(NODE1); - Ignite ignite2 = startGrid(NODE2); - Ignite ignite3 = startGrid(NODE3); - - assert ignite1 != null; - assert ignite2 != null; - assert ignite3 != null; - - // Get projection only for first 2 nodes. - ClusterGroup nodes = ignite1.cluster().forNodeIds(Arrays.asList( - ignite1.cluster().localNode().id(), - ignite2.cluster().localNode().id())); - - // On failover NODE3 shouldn't be taken into account. - Integer res = (Integer)compute(nodes.forPredicate(p)).withTimeout(10000). - execute(JobFailTask.class.getName(), "1"); - - assert res == 1; - } - catch (ClusterTopologyException ignored) { - failed.set(true); - } - finally { - assertTrue(failed.get()); - assertFalse(routed.get()); - - stopGrid(NODE1); - stopGrid(NODE2); - stopGrid(NODE3); - } - } - - /** */ - @ComputeTaskSessionFullSupport - private static class JobFailTask implements ComputeTask<String, Object> { - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession ses; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) throws IgniteCheckedException { - ses.setAttribute("fail", true); - - return Collections.singletonMap(new ComputeJobAdapter(arg) { - /** {@inheritDoc} */ - @SuppressWarnings({"RedundantTypeArguments"}) - @Override - public Serializable execute() throws IgniteCheckedException { - boolean fail; - - try { - fail = ses.<String, Boolean>waitForAttribute("fail", 0); - } - catch (InterruptedException e) { - throw new IgniteCheckedException("Got interrupted while waiting for attribute to be set.", e); - } - - if (fail) { - ses.setAttribute("fail", false); - - throw new IgniteCheckedException("Job exception."); - } - - // This job does not return any result. - return Integer.parseInt(this.<String>argument(0)); - } - }, subgrid.get(0)); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> received) - throws IgniteCheckedException { - if (res.getException() != null && !(res.getException() instanceof ComputeUserUndeclaredException)) - return ComputeJobResultPolicy.FAILOVER; - - return ComputeJobResultPolicy.REDUCE; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - return results.get(0).getData(); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTopologySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTopologySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTopologySelfTest.java deleted file mode 100644 index e8f0f77..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridFailoverTopologySelfTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -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.apache.ignite.spi.failover.*; -import org.apache.ignite.spi.failover.always.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Test failover and topology. It don't pick local node if it has been excluded from topology. - */ -@GridCommonTest(group = "Kernal Self") -public class GridFailoverTopologySelfTest extends GridCommonAbstractTest { - /** */ - private final AtomicBoolean failed = new AtomicBoolean(false); - - /** */ - public GridFailoverTopologySelfTest() { - super(/*start Grid*/false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setNodeId(null); - - cfg.setFailoverSpi(new AlwaysFailoverSpi() { - /** Ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public ClusterNode failover(FailoverContext ctx, List<ClusterNode> grid) { - if (grid.size() != 1) { - failed.set(true); - - error("Unexpected grid size [expected=1, grid=" + grid + ']'); - } - - UUID locNodeId = ignite.configuration().getNodeId(); - - for (ClusterNode node : grid) { - if (node.id().equals(locNodeId)) { - failed.set(true); - - error("Grid shouldn't contain local node [localNodeId=" + locNodeId + ", grid=" + grid + ']'); - } - } - - return super.failover(ctx, grid); - } - }); - - return cfg; - } - - /** - * Tests that failover don't pick local node if it has been excluded from topology. - * - * @throws Exception If failed. - */ - @SuppressWarnings("unchecked") - public void testFailoverTopology() throws Exception { - try { - Ignite ignite1 = startGrid(1); - - startGrid(2); - - ignite1.compute().localDeployTask(JobFailTask.class, JobFailTask.class.getClassLoader()); - - try { - compute(ignite1.cluster().forRemotes()).execute(JobFailTask.class, null); - } - catch (IgniteCheckedException e) { - info("Got expected grid exception: " + e); - } - - assert !failed.get(); - } - finally { - stopGrid(1); - stopGrid(2); - } - } - - /** */ - private static class JobFailTask implements ComputeTask<String, Object> { - /** Ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - private boolean jobFailedOver; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) throws IgniteCheckedException { - assert ignite != null; - - UUID locNodeId = ignite.configuration().getNodeId(); - - assert locNodeId != null; - - ClusterNode remoteNode = null; - - for (ClusterNode node : subgrid) { - if (!node.id().equals(locNodeId)) - remoteNode = node; - } - - return Collections.singletonMap(new ComputeJobAdapter(arg) { - @Override public Serializable execute() throws IgniteCheckedException { - throw new IgniteCheckedException("Job exception."); - } - }, remoteNode); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> received) throws IgniteCheckedException { - if (res.getException() != null && !jobFailedOver) { - jobFailedOver = true; - - return ComputeJobResultPolicy.FAILOVER; - } - - return ComputeJobResultPolicy.REDUCE; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - return results.get(0).getData(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridHomePathSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridHomePathSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridHomePathSelfTest.java deleted file mode 100644 index 1908d07..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridHomePathSelfTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.junits.common.*; - -import static org.apache.ignite.IgniteSystemProperties.*; - -/** - * - */ -public class GridHomePathSelfTest extends GridCommonAbstractTest { - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setLocalHost(getTestResources().getLocalHost()); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - public void testHomeOverride() throws Exception { - try { - startGrid(0); - - // Test home override. - IgniteConfiguration c = getConfiguration(getTestGridName(1)); - - c.setGridGainHome("/new/path"); - - try { - G.start(c); - - assert false : "Exception should have been thrown."; - } - catch (Exception e) { - if (X.hasCause(e, IgniteException.class)) - info("Caught expected exception: " + e); - else - throw e; - } - - // Test no override. - IgniteConfiguration c1 = getConfiguration(getTestGridName(1)); - - c1.setGridGainHome(System.getProperty(GG_HOME)); - - G.start(c1); - } - finally { - stopAllGrids(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCheckpointCleanupSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCheckpointCleanupSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCheckpointCleanupSelfTest.java deleted file mode 100644 index f8961d1..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCheckpointCleanupSelfTest.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -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.apache.ignite.spi.*; -import org.apache.ignite.spi.checkpoint.*; -import org.apache.ignite.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Test for checkpoint cleanup. - */ -public class GridJobCheckpointCleanupSelfTest extends GridCommonAbstractTest { - /** Number of currently alive checkpoints. */ - private final AtomicInteger cntr = new AtomicInteger(); - - /** Checkpoint. */ - private CheckpointSpi checkpointSpi; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration c = super.getConfiguration(gridName); - - c.setCheckpointSpi(checkpointSpi); - - return c; - } - - /** - * Spawns one job on the node other than task node and - * ensures that all checkpoints were removed after task completion. - * - * @throws Exception if failed. - */ - public void testCheckpointCleanup() throws Exception { - try { - checkpointSpi = new TestCheckpointSpi("task-checkpoints", cntr); - - Ignite taskIgnite = startGrid(0); - - checkpointSpi = new TestCheckpointSpi("job-checkpoints", cntr); - - Ignite jobIgnite = startGrid(1); - - taskIgnite.compute().execute(new CheckpointCountingTestTask(), jobIgnite.cluster().localNode()); - } - finally { - stopAllGrids(); - } - - assertEquals(cntr.get(), 0); - } - - /** - * Test checkpoint SPI. - */ - @IgniteSpiMultipleInstancesSupport(true) - private static class TestCheckpointSpi extends IgniteSpiAdapter implements CheckpointSpi { - /** Counter. */ - private final AtomicInteger cntr; - - /** - * @param name Name. - * @param cntr Counter. - */ - TestCheckpointSpi(String name, AtomicInteger cntr) { - setName(name); - - this.cntr = cntr; - } - - /** {@inheritDoc} */ - @Override public byte[] loadCheckpoint(String key) throws IgniteSpiException { - return null; - } - - /** {@inheritDoc} */ - @Override public boolean saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite) - throws IgniteSpiException { - cntr.incrementAndGet(); - - return true; - } - - /** {@inheritDoc} */ - @Override public boolean removeCheckpoint(String key) { - cntr.decrementAndGet(); - - return true; - } - - /** {@inheritDoc} */ - @Override public void setCheckpointListener(CheckpointListener lsnr) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void spiStart(@Nullable String gridName) throws IgniteSpiException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void spiStop() throws IgniteSpiException { - // No-op. - } - } - - /** - * - */ - @ComputeTaskSessionFullSupport - private static class CheckpointCountingTestTask extends ComputeTaskAdapter<ClusterNode, Object> { - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable ClusterNode arg) - throws IgniteCheckedException { - for (ClusterNode node : subgrid) { - if (node.id().equals(arg.id())) - return Collections.singletonMap(new ComputeJobAdapter() { - @IgniteTaskSessionResource - private ComputeTaskSession ses; - - @Nullable @Override public Object execute() throws IgniteCheckedException { - ses.saveCheckpoint("checkpoint-key", "checkpoint-value"); - - return null; - } - }, node); - } - - assert false : "Expected node wasn't found in grid"; - - // Never accessible. - return null; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCollisionCancelSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCollisionCancelSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCollisionCancelSelfTest.java deleted file mode 100644 index 2d92583..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobCollisionCancelSelfTest.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.spi.*; -import org.apache.ignite.spi.collision.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; - -/** - * Job collision cancel test. - */ -@SuppressWarnings( {"PublicInnerClass"}) -@GridCommonTest(group = "Kernal Self") -public class GridJobCollisionCancelSelfTest extends GridCommonAbstractTest { - /** */ - private static final Object mux = new Object(); - - /** */ - private static final int SPLIT_COUNT = 2; - - /** */ - private static final long maxJobExecTime = 10000; - - /** */ - private static int cancelCnt; - - /** */ - private static int execCnt; - - /** */ - private static int colResolutionCnt; - - /** */ - public GridJobCollisionCancelSelfTest() { - super(true); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings( {"AssignmentToCatchBlockParameter"}) - public void testCancel() throws Exception { - Ignite ignite = G.ignite(getTestGridName()); - - ignite.compute().localDeployTask(GridCancelTestTask.class, GridCancelTestTask.class.getClassLoader()); - - ComputeTaskFuture<?> res0 = - executeAsync(ignite.compute().withTimeout(maxJobExecTime * 2), GridCancelTestTask.class.getName(), null); - - try { - Object res = res0.get(); - - info("Cancel test result: " + res); - - synchronized (mux) { - // Every execute must be called. - assert execCnt <= SPLIT_COUNT : "Invalid execute count: " + execCnt; - - // Job returns 1 if was cancelled. - assert (Integer)res <= SPLIT_COUNT : "Invalid task result: " + res; - - // Should be exactly the same as Jobs number. - assert cancelCnt <= SPLIT_COUNT : "Invalid cancel count: " + cancelCnt; - - // One per start and one per stop and some that come with heartbeats. - assert colResolutionCnt > SPLIT_COUNT + 1: - "Invalid collision resolution count: " + colResolutionCnt; - } - } - catch (ComputeTaskTimeoutException e) { - error("Task execution got timed out.", e); - } - catch (Exception e) { - assert e.getCause() != null; - - if (e.getCause() instanceof IgniteCheckedException) - e = (Exception)e.getCause(); - - if (e.getCause() instanceof IOException) - e = (Exception)e.getCause(); - - assert e.getCause() instanceof InterruptedException : "Invalid exception cause: " + e.getCause(); - } - } - - /** - * @return Configuration. - * @throws Exception If failed. - */ - @Override protected IgniteConfiguration getConfiguration() throws Exception { - IgniteConfiguration cfg = super.getConfiguration(); - - cfg.setCollisionSpi(new GridTestCollision()); - - return cfg; - } - - /** - * - */ - public static class GridCancelTestTask extends ComputeTaskSplitAdapter<Serializable, Object> { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override public Collection<? extends ComputeJob> split(int gridSize, Serializable arg) { - if (log.isInfoEnabled()) - log.info("Splitting task [task=" + this + ", gridSize=" + gridSize + ", arg=" + arg + ']'); - - Collection<GridCancelTestJob> jobs = new ArrayList<>(SPLIT_COUNT); - - for (int i = 0; i < SPLIT_COUNT; i++) - jobs.add(new GridCancelTestJob()); - - return jobs; - } - - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) { - if (log.isInfoEnabled()) - log.info("Aggregating job [job=" + this + ", results=" + results + ']'); - - int res = 0; - - for (ComputeJobResult result : results) { - assert result != null; - - if (result.getData() != null) - res += (Integer)result.getData(); - } - - return res; - } - } - - /** - * Test job. - */ - public static class GridCancelTestJob extends ComputeJobAdapter { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteJobContextResource - private ComputeJobContext jobCtx; - - /** */ - @SuppressWarnings( {"FieldAccessedSynchronizedAndUnsynchronized"}) - private boolean isCancelled; - - /** */ - private final long thresholdTime; - - /** */ - public GridCancelTestJob() { - thresholdTime = System.currentTimeMillis() + maxJobExecTime; - } - - /** {@inheritDoc} */ - @Override public Serializable execute() { - synchronized (mux) { - execCnt++; - } - - if (log.isInfoEnabled()) - log.info("Executing job: " + jobCtx.getJobId()); - - long now = System.currentTimeMillis(); - - while (!isCancelled && now < thresholdTime) { - synchronized (mux) { - try { - mux.wait(thresholdTime - now); - } - catch (InterruptedException ignored) { - // No-op. - } - } - - now = System.currentTimeMillis(); - } - - synchronized (mux) { - return isCancelled ? 1 : 0; - } - } - - /** {@inheritDoc} */ - @Override public void cancel() { - synchronized (mux) { - isCancelled = true; - - cancelCnt++; - - mux.notifyAll(); - } - - log.warning("Job cancelled: " + jobCtx.getJobId()); - } - } - - - /** - * Test collision SPI. - */ - @IgniteSpiMultipleInstancesSupport(true) - public static class GridTestCollision extends IgniteSpiAdapter implements CollisionSpi { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override public void onCollision(CollisionContext ctx) { - Collection<CollisionJobContext> activeJobs = ctx.activeJobs(); - Collection<CollisionJobContext> waitJobs = ctx.waitingJobs(); - - synchronized (mux) { - colResolutionCnt++; - } - - for (CollisionJobContext job : waitJobs) - job.activate(); - - for (CollisionJobContext job : activeJobs) - job.cancel(); - } - - /** {@inheritDoc} */ - @Override public void spiStart(String gridName) throws IgniteSpiException { - // Start SPI start stopwatch. - startStopwatch(); - - // Ack start. - if (log.isInfoEnabled()) - log.info(startInfo()); - } - - /** {@inheritDoc} */ - @Override public void spiStop() throws IgniteSpiException { - // Ack stop. - if (log.isInfoEnabled()) - log.info(stopInfo()); - } - - /** {@inheritDoc} */ - @Override public void setExternalCollisionListener(CollisionExternalListener lsnr) { - // No-op. - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobContextSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobContextSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobContextSelfTest.java deleted file mode 100644 index a431fd1..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridJobContextSelfTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; - -/** - * Job context test. - */ -@GridCommonTest(group = "Kernal Self") -public class GridJobContextSelfTest extends GridCommonAbstractTest { - /** - * @throws Exception If anything failed. - */ - public void testJobContext() throws Exception { - Ignite ignite = startGrid(1); - - try { - startGrid(2); - - try { - ignite.compute().execute(JobContextTask.class, null); - } - finally { - stopGrid(2); - } - } - finally{ - stopGrid(1); - } - } - - /** */ - @SuppressWarnings("PublicInnerClass") - public static class JobContextTask extends ComputeTaskSplitAdapter<Object, Object> { - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - /** */ - @IgniteJobContextResource - private ComputeJobContext jobCtx; - - /** Ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Serializable execute() { - UUID locNodeId = ignite.configuration().getNodeId(); - - jobCtx.setAttribute("nodeId", locNodeId); - jobCtx.setAttribute("jobId", jobCtx.getJobId()); - - Map<String, String> attrs = new HashMap<>(10); - - for (int i = 0; i < 10; i++) { - String s = jobCtx.getJobId().toString() + i; - - attrs.put(s, s); - } - - jobCtx.setAttributes(attrs); - - assert jobCtx.getAttribute("nodeId").equals(locNodeId); - assert jobCtx.getAttributes().get("nodeId").equals(locNodeId); - assert jobCtx.getAttributes().keySet().containsAll(attrs.keySet()); - assert jobCtx.getAttributes().values().containsAll(attrs.values()); - - return null; - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - for (ComputeJobResult res : results) { - ComputeJobContext jobCtx = res.getJobContext(); - - assert jobCtx.getAttribute("nodeId").equals(res.getNode().id()); - assert jobCtx.getAttributes().get("nodeId").equals(res.getNode().id()); - - assert jobCtx.getAttribute("jobId").equals(jobCtx.getJobId()); - - for (int i = 0; i < 10; i++) { - String s = jobCtx.getJobId().toString() + i; - - assert jobCtx.getAttribute(s).equals(s); - assert jobCtx.getAttributes().get(s).equals(s); - } - } - - return null; - } - } -}