http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridManagementJobSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridManagementJobSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridManagementJobSelfTest.java deleted file mode 100644 index e8d2e9a..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridManagementJobSelfTest.java +++ /dev/null @@ -1,167 +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.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.internal.processors.task.*; -import org.apache.ignite.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * Test whether internal and visor tasks are routed to management pool. - */ -@GridCommonTest(group = "Kernal Self") -public class GridManagementJobSelfTest extends GridCommonAbstractTest { - /** Amount of nodes in the grid. */ - private static final int GRID_CNT = 3; - - /** Management pool threads name prefix. */ - private static final String MGMT_THREAD_PREFIX = "mgmt_thread_"; - - /** Name of a regular task. */ - private static final String TASK_NAME = "task"; - - /** IP finder. */ - private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - /** - * Do not start grid initially. - */ - public GridManagementJobSelfTest() { - super(false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(ipFinder); - - cfg.setDiscoverySpi(discoSpi); - - ExecutorService mgmtExecutor = Executors.newFixedThreadPool(10, new ThreadFactory() { - /** Counter for unique thread names. */ - private AtomicLong ctr = new AtomicLong(); - - /** {@inheritDoc} */ - @SuppressWarnings("NullableProblems") - @Override public Thread newThread(Runnable r) { - Thread t = new Thread(r); - - t.setName(MGMT_THREAD_PREFIX + ctr.getAndIncrement()); - - return t; - } - }); - - cfg.setManagementExecutorService(mgmtExecutor); - - cfg.setManagementExecutorServiceShutdown(true); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGridsMultiThreaded(GRID_CNT); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** - * Ensure that regular tasks are executed within public pool while Visor and internal - * taskss are executed in management pool on remote nodes. - * - * @throws Exception If failed. - */ - public void testNamedTasks() throws Exception { - runJob(TASK_NAME, new TestJob()); - } - - /** - * Ensure that jobs annotated with {@link GridInternal} are always executed in - * management pool irrespective of task name. - * - * @throws Exception If failed. - */ - public void testAnnotatedTasks() throws Exception { - runJob(TASK_NAME, new TestJobInternal()); - } - - /** - * Execute the TestJob on remote nodes. - * - * @param taskName Name of the task in which context this job will be executed. - * @param job Job. - * @throws Exception If failed. - */ - private void runJob(String taskName, Callable<Object> job) throws Exception { - // We run a task on remote nodes because on local node jobs will be executed in system pool anyway. - compute(grid(0).forRemotes()).withName(taskName).call(job); - } - - /** - * Test job which ensures that its executor thread is from management pool in case - * task name corresponds to either internal or Visor task. - */ - private static class TestJob implements Callable<Object>, Serializable { - /** Task session. */ - @IgniteTaskSessionResource - protected ComputeTaskSession ses; - - /** {@inheritDoc} */ - @Nullable @Override public Object call() throws IgniteCheckedException { - String threadName = Thread.currentThread().getName(); - - assertFalse(threadName.startsWith(MGMT_THREAD_PREFIX)); - - return null; - } - } - - /** - * Test job which ensures that it is always executed in management pool irrespectively - * of task name due to presence of {@link GridInternal} annotation. - */ - @GridInternal - private static class TestJobInternal implements Callable<Object>, Serializable { - /** {@inheritDoc} */ - @Nullable @Override public Object call() throws IgniteCheckedException { - String threadName = Thread.currentThread().getName(); - - assertTrue(threadName.startsWith(MGMT_THREAD_PREFIX)); - - return null; - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleJobsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleJobsSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleJobsSelfTest.java deleted file mode 100644 index de68091..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleJobsSelfTest.java +++ /dev/null @@ -1,231 +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.cache.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.cache.GridCacheMode.*; - -/** - * Tests multiple parallel jobs execution. - */ -@GridCommonTest(group = "Kernal Self") -public class GridMultipleJobsSelfTest extends GridCommonAbstractTest { - /** */ - private static final int LOG_MOD = 100; - - /** */ - private static final int TEST_TIMEOUT = 60 * 1000; - - /** IP finder. */ - private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGrid(1); - startGrid(2); - - assertEquals(2, grid(1).nodes().size()); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopGrid(1); - stopGrid(2); - - assertEquals(0, G.allGrids().size()); - } - - /** {@inheritDoc} */ - @Override protected long getTestTimeout() { - return TEST_TIMEOUT; - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration c = super.getConfiguration(gridName); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(ipFinder); - - c.setDiscoverySpi(disco); - - if (getTestGridName(1).equals(gridName)) - c.setCacheConfiguration(/* no configured caches */); - else { - CacheConfiguration cc = defaultCacheConfiguration(); - - cc.setCacheMode(PARTITIONED); - cc.setBackups(1); - - c.setCacheConfiguration(cc); - } - - return c; - } - - /** - * @throws Exception If test failed. - */ - public void testNotAffinityJobs() throws Exception { - /* =========== Test properties =========== */ - int jobsNum = 5000; - int threadNum = 10; - - runTest(jobsNum, threadNum, NotAffinityJob.class); - } - - /** - * @throws Exception If test failed. - */ - public void testAffinityJobs() throws Exception { - /* =========== Test properties =========== */ - int jobsNum = 5000; - int threadNum = 10; - - runTest(jobsNum, threadNum, AffinityJob.class); - } - - /** - * @param jobsNum Number of jobs. - * @param threadNum Number of threads. - * @param jobCls Job class. - * @throws Exception If failed. - */ - private void runTest(final int jobsNum, int threadNum, final Class<? extends IgniteCallable<Boolean>> jobCls) - throws Exception { - final Ignite ignite1 = grid(1); - - final CountDownLatch latch = new CountDownLatch(jobsNum); - - final AtomicInteger jobsCnt = new AtomicInteger(); - - final AtomicInteger resCnt = new AtomicInteger(); - - GridTestUtils.runMultiThreaded(new CAX() { - @Override public void applyx() throws IgniteCheckedException { - while (true) { - int cnt = jobsCnt.incrementAndGet(); - - if (cnt > jobsNum) - break; - - IgniteCallable<Boolean> job; - - try { - job = jobCls.newInstance(); - } - catch (Exception e) { - throw new IgniteCheckedException("Could not instantiate a job.", e); - } - - IgniteCompute comp = ignite1.compute().enableAsync(); - - comp.call(job); - - IgniteFuture<Boolean> fut = comp.future(); - - if (cnt % LOG_MOD == 0) - X.println("Submitted jobs: " + cnt); - - fut.listenAsync(new CIX1<IgniteFuture<Boolean>>() { - @Override public void applyx(IgniteFuture<Boolean> f) throws IgniteCheckedException { - try { - assert f.get(); - } - finally { - latch.countDown(); - - long cnt = resCnt.incrementAndGet(); - - if (cnt % LOG_MOD == 0) - X.println("Results count: " + cnt); - } - } - }); - } - } - }, threadNum, "TEST-THREAD"); - - latch.await(); - } - - /** - * Test not affinity job. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static class NotAffinityJob implements IgniteCallable<Boolean> { - /** */ - private static AtomicInteger cnt = new AtomicInteger(); - - /** {@inheritDoc} */ - @Override public Boolean call() throws Exception { - int c = cnt.incrementAndGet(); - - if (c % LOG_MOD == 0) - X.println("Executed jobs: " + c); - - Thread.sleep(10); - - return true; - } - } - - /** - * Test affinity routed job. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static class AffinityJob implements IgniteCallable<Boolean> { - /** */ - private static AtomicInteger cnt = new AtomicInteger(); - - /** {@inheritDoc} */ - @Override public Boolean call() throws Exception { - int c = cnt.incrementAndGet(); - - if (c % LOG_MOD == 0) - X.println("Executed affinity jobs: " + c); - - Thread.sleep(10); - - return true; - } - - /** - * @return Affinity key. - */ - @GridCacheAffinityKeyMapped - public String affinityKey() { - return "key"; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleSpisSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleSpisSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleSpisSelfTest.java deleted file mode 100644 index b1daada..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleSpisSelfTest.java +++ /dev/null @@ -1,302 +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.sharedfs.*; -import org.apache.ignite.spi.failover.*; -import org.apache.ignite.spi.failover.always.*; -import org.apache.ignite.spi.loadbalancing.roundrobin.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; - -/** - * Multiple SPIs test. - */ -@GridCommonTest(group = "Kernal Self") -public class GridMultipleSpisSelfTest extends GridCommonAbstractTest { - /** */ - private boolean isTaskFailoverCalled; - - /** */ - private boolean isWrongTaskFailoverCalled; - - /** */ - private boolean isTaskLoadBalancingCalled; - - /** */ - private boolean isWrongTaskLoadBalancingCalled; - - /** */ - private boolean isTaskCheckPntCalled; - - /** */ - private boolean isWrongTaskCheckPntCalled; - - /** */ - private boolean isJobCheckPntCalled; - - /** */ - private boolean isWrongJobCheckPntCalled; - - /** */ - public GridMultipleSpisSelfTest() { - super(false); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - GridTestFailoverSpi fail1 = new GridTestFailoverSpi("fail2"); - GridTestFailoverSpi fail2 = new GridTestFailoverSpi("fail2"); - - fail1.setName("fail1"); - fail2.setName("fail2"); - - GridTestLoadBalancingSpi load1 = new GridTestLoadBalancingSpi("load2"); - GridTestLoadBalancingSpi load2 = new GridTestLoadBalancingSpi("load2"); - - load1.setName("load1"); - load2.setName("load2"); - - GridTestCheckpointSpi cp1 = new GridTestCheckpointSpi("cp2"); - GridTestCheckpointSpi cp2 = new GridTestCheckpointSpi("cp2"); - - cp1.setName("cp1"); - cp2.setName("cp2"); - - cfg.setFailoverSpi(fail1, fail2); - cfg.setLoadBalancingSpi(load1, load2); - cfg.setCheckpointSpi(cp1, cp2); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"UnusedCatchParameter"}) - public void testFailoverTask() throws Exception { - // Start local and remote grids. - Ignite ignite1 = startGrid(1); - startGrid(2); - - try { - // Say grid1 is a local one. Deploy task and execute it. - ignite1.compute().localDeployTask(GridTestMultipleSpisTask.class, - GridTestMultipleSpisTask.class.getClassLoader()); - - try { - ignite1.compute().execute(GridTestMultipleSpisTask.class.getName(), ignite1.cluster().localNode().id()); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - - assert false : "Unexpected exception."; - } - } - finally { - stopGrid(2); - stopGrid(1); - } - - assert isTaskFailoverCalled : "Expected Failover SPI has not been called."; - assert isTaskLoadBalancingCalled : "Expected Load balancing SPI has not been called."; - assert isTaskCheckPntCalled : "Expected Checkpoint SPI has not been called on task side."; - assert isJobCheckPntCalled : "Expected Checkpoint SPI has not been called on job side."; - - // All of them should remain false. - assert !isWrongTaskFailoverCalled : "Unexpected Failover SPI has been called."; - assert !isWrongTaskLoadBalancingCalled : "Unexpected Load balancing SPI has been called."; - assert !isWrongTaskCheckPntCalled : "Unexpected Checkpoint SPI has been called on task side."; - assert !isWrongJobCheckPntCalled : "Unexpected Checkpoint SPI has been called on job side."; - } - - /** */ - private class GridTestFailoverSpi extends AlwaysFailoverSpi { - /** */ - private String expName; - - /** - * Creates new failover SPI. - * - * @param expName Name of the SPI expected to be called. - */ - GridTestFailoverSpi(String expName) { - this.expName = expName; - } - - /** {@inheritDoc} */ - @Override public ClusterNode failover(FailoverContext ctx, List<ClusterNode> grid) { - if (getName().equals(expName)) - isTaskFailoverCalled = true; - else - isWrongTaskFailoverCalled = true; - - return super.failover(ctx, grid); - } - } - - /** */ - private class GridTestLoadBalancingSpi extends RoundRobinLoadBalancingSpi { - /** */ - private String expName; - - /** - * Creates new load balancing SPI. - * - * @param expName Name of the SPI expected to be called. - */ - GridTestLoadBalancingSpi(String expName) { - this.expName = expName; - } - - /** {@inheritDoc} */ - @Override public ClusterNode getBalancedNode(ComputeTaskSession ses, List<ClusterNode> top, - ComputeJob job) throws IgniteCheckedException { - if (getName().equals(expName)) - isTaskLoadBalancingCalled = true; - else - isWrongTaskLoadBalancingCalled = true; - - return super.getBalancedNode(ses, top, job); - } - } - - /** */ - private class GridTestCheckpointSpi extends SharedFsCheckpointSpi { - /** */ - private String expName; - - /** - * Creates new checkpoint SPI. - * - * @param expName Name of the SPI expected to be called. - */ - GridTestCheckpointSpi(String expName) { - this.expName = expName; - } - - /** {@inheritDoc} */ - @Override public boolean saveCheckpoint(String key, byte[] state, long timeout, - boolean overwrite) throws IgniteSpiException { - if (getName().equals(expName)) - isTaskCheckPntCalled = true; - else - isWrongTaskCheckPntCalled = true; - - return super.saveCheckpoint(key, state, timeout, overwrite); - } - - /** {@inheritDoc} */ - @Override public byte[] loadCheckpoint(String key) throws IgniteSpiException { - if (getName().equals(expName)) - isJobCheckPntCalled = true; - else - isWrongJobCheckPntCalled = true; - - return super.loadCheckpoint(key); - } - } - - /** - * Task which splits to the jobs that uses SPIs from annotation. - */ - @SuppressWarnings({"PublicInnerClass"}) - @ComputeTaskSpis(loadBalancingSpi = "load2", failoverSpi = "fail2", checkpointSpi = "cp2") - @ComputeTaskSessionFullSupport - public static final class GridTestMultipleSpisTask extends ComputeTaskAdapter<UUID, Integer> { - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession taskSes; - - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, UUID arg) throws IgniteCheckedException { - assert subgrid.size() == 2; - assert taskSes != null; - assert ignite != null; - assert ignite.cluster().localNode().id().equals(arg); - - taskSes.saveCheckpoint("test", arg); - - // Always map job to the local node where it will fail. - return Collections.singletonMap(new GridTestMultipleSpisJob(arg), ignite.cluster().localNode()); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, - List<ComputeJobResult> received) throws IgniteCheckedException { - if (res.getException() != null) - return ComputeJobResultPolicy.FAILOVER; - - return super.result(res, received); - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) { - return null; - } - } - - /** - * Job that always throws exception. - */ - private static class GridTestMultipleSpisJob extends ComputeJobAdapter { - /** Ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - @IgniteTaskSessionResource - private ComputeTaskSession jobSes; - - /** - * @param arg Job argument. - */ - GridTestMultipleSpisJob(UUID arg) { - super(arg); - } - - /** {@inheritDoc} */ - @Override public UUID execute() throws IgniteCheckedException { - assert ignite != null; - assert jobSes != null; - assert argument(0) != null; - - // Should always fail on task originating node and work on another one. - if (ignite.configuration().getNodeId().equals(argument(0))) - throw new IgniteCheckedException("Expected exception to failover job."); - - // Use checkpoint on job side. This will happen on remote node. - jobSes.loadCheckpoint("test"); - - return argument(0); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleVersionsDeploymentSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleVersionsDeploymentSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleVersionsDeploymentSelfTest.java deleted file mode 100644 index 4dc3f0c..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultipleVersionsDeploymentSelfTest.java +++ /dev/null @@ -1,306 +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.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import static java.util.concurrent.TimeUnit.*; -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * - */ -@GridCommonTest(group = "Kernal Self") -public class GridMultipleVersionsDeploymentSelfTest extends GridCommonAbstractTest { - /** Excluded classes. */ - private static final String[] EXCLUDE_CLASSES = new String[] { - GridDeploymentTestTask.class.getName(), - GridDeploymentTestJob.class.getName() - }; - - /** */ - public GridMultipleVersionsDeploymentSelfTest() { - 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(GridDeploymentTestJob.class.getName(), - GridDeploymentTestTask.class.getName()); - - // Following tests makes sense in ISOLATED modes (they redeploy tasks - // and don't change task version. The different tasks with the same version from the same node - // executed in parallel - this does not work in share mode.) - cfg.setDeploymentMode(IgniteDeploymentMode.ISOLATED); - - cfg.setPeerClassLoadingLocalClassPathExclude( - "org.gridgain.grid.kernal.GridMultipleVersionsDeploymentSelfTest*"); - - return cfg; - } - - /** - * @param ignite Grid. - * @param taskName Task name. - * @return {@code true} if task has been deployed on passed grid. - */ - private boolean checkDeployed(Ignite ignite, String taskName) { - Map<String, Class<? extends ComputeTask<?, ?>>> locTasks = ignite.compute().localTasks(); - - if (log().isInfoEnabled()) - log().info("Local tasks found: " + locTasks); - - return locTasks.get(taskName) != null; - } - - /** - * @throws Exception If test failed. - */ - @SuppressWarnings("unchecked") - public void testMultipleVersionsLocalDeploy() throws Exception { - try { - Ignite ignite = startGrid(1); - - ClassLoader ldr1 = new GridTestClassLoader( - Collections.singletonMap("testResource", "1"), - getClass().getClassLoader(), - EXCLUDE_CLASSES); - - ClassLoader ldr2 = new GridTestClassLoader( - Collections.singletonMap("testResource", "2"), - getClass().getClassLoader(), - EXCLUDE_CLASSES - ); - - Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>)ldr1. - loadClass(GridDeploymentTestTask.class.getName()); - - Class<? extends ComputeTask<?, ?>> taskCls2 = (Class<? extends ComputeTask<?, ?>>)ldr2. - loadClass(GridDeploymentTestTask.class.getName()); - - ignite.compute().localDeployTask(taskCls1, ldr1); - - // Task will wait for the signal. - ComputeTaskFuture fut = executeAsync(ignite.compute(), "GridDeploymentTestTask", null); - - // We should wait here when to be sure that job has been started. - // Since we loader task/job classes with different class loaders we cannot - // use any kind of mutex because of the illegal state exception. - // We have to use timer here. DO NOT CHANGE 2 seconds. This should be enough - // on Bamboo. - Thread.sleep(2000); - - assert checkDeployed(ignite, "GridDeploymentTestTask"); - - // Deploy new one - this should move first task to the obsolete list. - ignite.compute().localDeployTask(taskCls2, ldr2); - - boolean deployed = checkDeployed(ignite, "GridDeploymentTestTask"); - - Object res = fut.get(); - - ignite.compute().undeployTask("GridDeploymentTestTask"); - - // New one should be deployed. - assert deployed; - - // Wait for the execution. - assert res.equals(1); - } - finally { - stopGrid(1); - } - } - - /** - * @throws Exception If test failed. - */ - @SuppressWarnings("unchecked") - public void testMultipleVersionsP2PDeploy() throws Exception { - try { - Ignite g1 = startGrid(1); - Ignite g2 = startGrid(2); - - final CountDownLatch latch = new CountDownLatch(2); - - g2.events().localListen( - new IgnitePredicate<IgniteEvent>() { - @Override public boolean apply(IgniteEvent evt) { - info("Received event: " + evt); - - latch.countDown(); - - return true; - } - }, EVT_TASK_UNDEPLOYED - ); - - ClassLoader ldr1 = new GridTestClassLoader( - Collections.singletonMap("testResource", "1"), - getClass().getClassLoader(), - EXCLUDE_CLASSES); - - ClassLoader ldr2 = new GridTestClassLoader( - Collections.singletonMap("testResource", "2"), - getClass().getClassLoader(), - EXCLUDE_CLASSES); - - Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>)ldr1. - loadClass(GridDeploymentTestTask.class.getName()); - - Class<? extends ComputeTask<?, ?>> taskCls2 = (Class<? extends ComputeTask<?, ?>>)ldr2. - loadClass(GridDeploymentTestTask.class.getName()); - - g1.compute().localDeployTask(taskCls1, ldr1); - - // Task will wait for the signal. - ComputeTaskFuture fut1 = executeAsync(g1.compute(), "GridDeploymentTestTask", null); - - assert checkDeployed(g1, "GridDeploymentTestTask"); - - // We should wait here when to be sure that job has been started. - // Since we loader task/job classes with different class loaders we cannot - // use any kind of mutex because of the illegal state exception. - // We have to use timer here. DO NOT CHANGE 2 seconds here. - Thread.sleep(2000); - - // Deploy new one - this should move first task to the obsolete list. - g1.compute().localDeployTask(taskCls2, ldr2); - - // Task will wait for the signal. - ComputeTaskFuture fut2 = executeAsync(g1.compute(), "GridDeploymentTestTask", null); - - boolean deployed = checkDeployed(g1, "GridDeploymentTestTask"); - - Object res1 = fut1.get(); - Object res2 = fut2.get(); - - g1.compute().undeployTask("GridDeploymentTestTask"); - - // New one should be deployed. - assert deployed; - - // Wait for the execution. - assert res1.equals(1); - assert res2.equals(2); - - stopGrid(1); - - assert latch.await(3000, MILLISECONDS); - - assert !checkDeployed(g2, "GridDeploymentTestTask"); - } - finally { - stopGrid(2); - stopGrid(1); - } - } - - /** - * Task that maps {@link GridDeploymentTestJob} either on local node - * or on remote nodes if there are any. Never on both. - */ - @SuppressWarnings({"PublicInnerClass"}) - @ComputeTaskName(value="GridDeploymentTestTask") - public static class GridDeploymentTestTask extends ComputeTaskAdapter<Object, Object> { - /** Ignite instance. */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Object arg) throws IgniteCheckedException { - Map<ComputeJobAdapter, ClusterNode> map = new HashMap<>(subgrid.size()); - - boolean ignoreLocNode = false; - - assert ignite != null; - - UUID locNodeId = ignite.configuration().getNodeId(); - - assert locNodeId != null; - - if (subgrid.size() == 1) - assert subgrid.get(0).id().equals(locNodeId) : "Wrong node id."; - else - ignoreLocNode = true; - - for (ClusterNode node : subgrid) { - // Ignore local node. - if (ignoreLocNode && node.id().equals(locNodeId)) - continue; - - map.put(new GridDeploymentTestJob(), node); - } - - return map; - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return results.get(0).getData(); - } - } - - /** - * Simple job class that requests resource with name "testResource" - * and expects "0" value. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static class GridDeploymentTestJob extends ComputeJobAdapter { - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override public Integer execute() throws IgniteCheckedException { - try { - if (log.isInfoEnabled()) - log.info("GridDeploymentTestJob job started"); - - // Again there is no way to get access to any - // mutex of the test class because of the different class loaders. - // we have to wait. - Thread.sleep(3000); - - // Here we should request some resources. New task - // has already been deployed and old one should be still available. - int res = getClass().getClassLoader().getResourceAsStream("testResource").read(); - - return res - 48; - } - catch (IOException | InterruptedException 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/GridMultithreadedJobStealingSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultithreadedJobStealingSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultithreadedJobStealingSelfTest.java deleted file mode 100644 index ba9cb70..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridMultithreadedJobStealingSelfTest.java +++ /dev/null @@ -1,240 +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.collision.jobstealing.*; -import org.apache.ignite.spi.failover.jobstealing.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Multithreaded job stealing test. - */ -@GridCommonTest(group = "Kernal Self") -public class GridMultithreadedJobStealingSelfTest extends GridCommonAbstractTest { - /** */ - private Ignite ignite; - - /** */ - public GridMultithreadedJobStealingSelfTest() { - super(false /* don't start grid*/); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - ignite = startGridsMultiThreaded(2); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - ignite = null; - - stopAllGrids(); - } - - /** - * Test 2 jobs on 2 nodes. - * - * @throws Exception If test failed. - */ - public void testTwoJobsMultithreaded() throws Exception { - final AtomicReference<Exception> fail = new AtomicReference<>(null); - - final AtomicInteger stolen = new AtomicInteger(0); - final AtomicInteger noneStolen = new AtomicInteger(0); - - int threadsNum = 10; - - GridTestUtils.runMultiThreaded(new Runnable() { - /** */ - @Override public void run() { - try { - JobStealingResult res = ignite.compute().execute(JobStealingTask.class, null); - - info("Task result: " + res); - - switch(res) { - case NONE_STOLEN : { - noneStolen.addAndGet(2); - break; - } - case ONE_STOLEN : { - noneStolen.addAndGet(1); - stolen.addAndGet(1); - break; - } - case BOTH_STOLEN: { - stolen.addAndGet(2); - break; - } - default: { - assert false : "Result is: " + res; - } - } - } - catch (IgniteCheckedException e) { - log.error("Failed to execute task.", e); - - fail.getAndSet(e); - } - } - }, threadsNum, "JobStealingThread"); - - for (Ignite g : G.allGrids()) - info("Metrics [nodeId=" + g.cluster().localNode().id() + - ", metrics=" + g.cluster().localNode().metrics() + ']'); - - assert fail.get() == null : "Test failed with exception: " + fail.get(); - - // Total jobs number is threadsNum * 2 - assert stolen.get() + noneStolen.get() == threadsNum * 2 : "Incorrect processed jobs number"; - - assert stolen.get() != 0 : "No jobs were stolen."; - - // Under these circumstances we should not have more than 2 jobs - // difference. - assert Math.abs(stolen.get() - noneStolen.get()) <= 2 : "Stats [stolen=" + stolen + - ", noneStolen=" + noneStolen + ']'; - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - JobStealingCollisionSpi colSpi = new JobStealingCollisionSpi(); - - // One job at a time. - colSpi.setActiveJobsThreshold(1); - colSpi.setWaitJobsThreshold(0); - - JobStealingFailoverSpi failSpi = new JobStealingFailoverSpi(); - - // Verify defaults. - assert failSpi.getMaximumFailoverAttempts() == JobStealingFailoverSpi.DFLT_MAX_FAILOVER_ATTEMPTS; - - cfg.setCollisionSpi(colSpi); - cfg.setFailoverSpi(failSpi); - - return cfg; - } - - /** - * Job stealing task. - */ - private static class JobStealingTask extends ComputeTaskAdapter<Object, JobStealingResult> { - /** Grid. */ - @IgniteInstanceResource - private Ignite ignite; - - /** Logger. */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @SuppressWarnings("ForLoopReplaceableByForEach") - @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, - @Nullable Object arg) throws IgniteCheckedException { - assert subgrid.size() == 2 : "Invalid subgrid size: " + subgrid.size(); - - Map<ComputeJobAdapter, ClusterNode> map = new HashMap<>(subgrid.size()); - - // Put all jobs onto local node. - for (int i = 0; i < subgrid.size(); i++) - map.put(new GridJobStealingJob(2000L), ignite.cluster().localNode()); - - return map; - } - - /** {@inheritDoc} */ - @Override public JobStealingResult reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 2; - - for (ComputeJobResult res : results) { - log.info("Job result: " + res.getData()); - } - - Object obj0 = results.get(0).getData(); - - if (obj0.equals(results.get(1).getData())) { - if (obj0.equals(ignite.name())) - return JobStealingResult.NONE_STOLEN; - - return JobStealingResult.BOTH_STOLEN; - } - - return JobStealingResult.ONE_STOLEN; - } - } - - /** - * Job stealing job. - */ - private static final class GridJobStealingJob extends ComputeJobAdapter { - /** Injected grid. */ - @IgniteInstanceResource - private Ignite ignite; - - /** - * @param arg Job argument. - */ - GridJobStealingJob(Long arg) { - super(arg); - } - - /** {@inheritDoc} */ - @Override public Serializable execute() throws IgniteCheckedException { - try { - Long sleep = argument(0); - - assert sleep != null; - - Thread.sleep(sleep); - } - catch (InterruptedException e) { - throw new IgniteCheckedException("Job got interrupted.", e); - } - - return ignite.name(); - } - } - - /** - * Job stealing result. - */ - private enum JobStealingResult { - /** */ - BOTH_STOLEN, - - /** */ - ONE_STOLEN, - - /** */ - NONE_STOLEN - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeFilterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeFilterSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeFilterSelfTest.java deleted file mode 100644 index f6a84f0..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeFilterSelfTest.java +++ /dev/null @@ -1,78 +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.testframework.junits.common.*; - -import java.util.*; - -/** - * Node filter test. - */ -@GridCommonTest(group = "Kernal Self") -public class GridNodeFilterSelfTest extends GridCommonAbstractTest { - /** Grid instance. */ - private Ignite ignite; - - /** Remote instance. */ - private Ignite rmtIgnite; - - /** */ - public GridNodeFilterSelfTest() { - super(false); - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - ignite = startGrid(1); - - rmtIgnite = startGrid(2); - startGrid(3); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopGrid(1); - stopGrid(2); - stopGrid(3); - - ignite = null; - rmtIgnite = null; - } - - /** - * @throws Exception If failed. - */ - public void testSynchronousExecute() throws Exception { - UUID nodeId = ignite.cluster().localNode().id(); - - UUID rmtNodeId = rmtIgnite.cluster().localNode().id(); - - Collection<ClusterNode> locNodes = ignite.cluster().forNodeId(nodeId).nodes(); - - assert locNodes.size() == 1; - assert locNodes.iterator().next().id().equals(nodeId); - - Collection<ClusterNode> rmtNodes = ignite.cluster().forNodeId(rmtNodeId).nodes(); - - assert rmtNodes.size() == 1; - assert rmtNodes.iterator().next().id().equals(rmtNodeId); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeLocalSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeLocalSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeLocalSelfTest.java deleted file mode 100644 index 888f45f..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeLocalSelfTest.java +++ /dev/null @@ -1,65 +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.internal.util.typedef.*; -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; - -/** - * This test will test node local storage. - */ -@GridCommonTest(group = "Kernal Self") -public class GridNodeLocalSelfTest extends GridCommonAbstractTest { - /** Create test. */ - public GridNodeLocalSelfTest() { - super(/* Start grid. */true); - } - - /** - * Test node-local values operations. - * - * @throws Exception If test failed. - */ - public void testNodeLocal() throws Exception { - Ignite g = G.ignite(getTestGridName()); - - String keyStr = "key"; - int keyNum = 1; - Date keyDate = new Date(); - - GridTuple3 key = F.t(keyNum, keyStr, keyDate); - - ClusterNodeLocalMap<Object, Object> nl = g.cluster().nodeLocalMap(); - - nl.put(keyStr, "Hello world!"); - nl.put(key, 12); - - assert nl.containsKey(keyStr); - assert nl.containsKey(key); - assert !nl.containsKey(keyNum); - assert !nl.containsKey(F.t(keyNum, keyStr)); - - assert "Hello world!".equals(nl.get(keyStr)); - assert (Integer)nl.get(key) == 12; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeVisorAttributesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeVisorAttributesSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeVisorAttributesSelfTest.java deleted file mode 100644 index 8794925..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNodeVisorAttributesSelfTest.java +++ /dev/null @@ -1,114 +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.testframework.junits.common.*; - -import java.util.*; - -/** - * Ensures that system properties required by Visor are always passed to node attributes. - */ -public class GridNodeVisorAttributesSelfTest extends GridCommonAbstractTest { - /** System properties required by Visor. */ - private static final String[] SYSTEM_PROPS = new String[] { - "java.version", - "java.vm.name", - "os.arch", - "os.name", - "os.version" - }; - - /** GridGain-specific properties required by Visor. */ - private static final String[] GG_PROPS = new String[] { - "org.gridgain.jvm.pid" - }; - - /** System and environment properties to include. */ - private String[] inclProps; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setIncludeProperties(inclProps); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - stopAllGrids(); - } - - /** - * Start grid node and ensure that Visor-related node attributes are set properly. - * - * @throws Exception If grid start failed. - */ - private void startGridAndCheck() throws Exception { - Ignite g = startGrid(); - - Map<String, Object> attrs = g.cluster().localNode().attributes(); - - for (String prop : SYSTEM_PROPS) { - assert attrs.containsKey(prop); - - assertEquals(System.getProperty(prop), attrs.get(prop)); - } - - for (String prop : GG_PROPS) - assert attrs.containsKey(prop); - } - - /** - * Test with 'includeProperties' configuration parameter set to {@code null}. - * - * @throws Exception If failed. - */ - public void testIncludeNull() throws Exception { - inclProps = null; - - startGridAndCheck(); - } - - /** - * Test with 'includeProperties' configuration parameter set to empty array. - * - * @throws Exception If failed. - */ - @SuppressWarnings("ZeroLengthArrayAllocation") - public void testIncludeEmpty() throws Exception { - inclProps = new String[] {}; - - startGridAndCheck(); - } - - /** - * Test with 'includeProperties' configuration parameter set to array with some values. - * - * @throws Exception If failed. - */ - public void testIncludeNonEmpty() throws Exception { - inclProps = new String[] {"prop1", "prop2"}; - - startGridAndCheck(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNonHistoryMetricsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNonHistoryMetricsSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridNonHistoryMetricsSelfTest.java deleted file mode 100644 index 87cb12a..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridNonHistoryMetricsSelfTest.java +++ /dev/null @@ -1,124 +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.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; -import java.util.concurrent.*; - -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * - */ -public class GridNonHistoryMetricsSelfTest extends GridCommonAbstractTest { - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setMetricsHistorySize(5); - - cfg.setCacheConfiguration(); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - public void testSingleTaskMetrics() throws Exception { - final Ignite ignite = grid(); - - ignite.compute().execute(new TestTask(), "testArg"); - - // Let metrics update twice. - final CountDownLatch latch = new CountDownLatch(2); - - ignite.events().localListen(new IgnitePredicate<IgniteEvent>() { - @Override public boolean apply(IgniteEvent evt) { - assert evt.type() == EVT_NODE_METRICS_UPDATED; - - latch.countDown(); - - return true; - } - }, EVT_NODE_METRICS_UPDATED); - - latch.await(); - - GridTestUtils.waitForCondition(new GridAbsPredicate() { - @Override public boolean apply() { - ClusterNodeMetrics metrics = ignite.cluster().localNode().metrics(); - - return metrics.getTotalExecutedJobs() == 5; - } - }, 5000); - - ClusterNodeMetrics metrics = ignite.cluster().localNode().metrics(); - - info("Node metrics: " + metrics); - - assertEquals(5, metrics.getTotalExecutedJobs()); - assertEquals(0, metrics.getTotalCancelledJobs()); - assertEquals(0, metrics.getTotalRejectedJobs()); - } - - /** - * Test task. - */ - private static class TestTask extends ComputeTaskSplitAdapter<Object, Object> { - /** Logger. */ - @IgniteLoggerResource - private IgniteLogger log; - - /** {@inheritDoc} */ - @Override public Collection<? extends ComputeJob> split(int gridSize, Object arg) { - Collection<ComputeJob> refs = new ArrayList<>(gridSize*5); - - for (int i = 0; i < gridSize * 5; i++) - refs.add(new GridTestJob(arg.toString() + i + 1)); - - return refs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return results; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionAbstractTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionAbstractTest.java deleted file mode 100644 index 9821b02..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionAbstractTest.java +++ /dev/null @@ -1,768 +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.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * Abstract test for {@link org.apache.ignite.cluster.ClusterGroup} - */ -@SuppressWarnings("deprecation") -public abstract class GridProjectionAbstractTest extends GridCommonAbstractTest implements Externalizable { - /** Waiting timeout. */ - private static final int WAIT_TIMEOUT = 30000; - - /** Utility static variable. */ - private static final AtomicInteger cnt = new AtomicInteger(0); - - /** Mutex. */ - private static final Object mux = new Object(); - - /** Projection. */ - private ClusterGroup prj; - - /** Runnable job. */ - private Runnable runJob = new TestRunnable(); - - /** Callable job. */ - private Callable<String> calJob = new TestCallable<>(); - - /** Closure job. */ - private IgniteClosure<String, String> clrJob = new IgniteClosure<String, String>() { - @Override public String apply(String s) { - return s; - } - - @Override public String toString() { - return "clrJob"; - } - }; - - /** Reducer. */ - private IgniteReducer<String, Object> rdc = new IgniteReducer<String, Object>() { - @Override public boolean collect(String e) { - return true; - } - - @Nullable @Override public Object reduce() { - return null; - } - - @Override public String toString() { - return "rdc"; - } - }; - - /** */ - protected GridProjectionAbstractTest() { - // No-op. - } - - /** - * @param startGrid Start grid flag. - */ - protected GridProjectionAbstractTest(boolean startGrid) { - super(startGrid); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - prj = projection(); - - cnt.set(0); - } - - /** - * @return Projection. - */ - protected abstract ClusterGroup projection(); - - /** - * @return Local node ID. - */ - @Nullable protected abstract UUID localNodeId(); - - /** - * @return Remote nodes IDs. - */ - protected Collection<UUID> remoteNodeIds() { - return F.nodeIds(projection().forRemotes().nodes()); - } - - /** - * @return Projection size. - */ - private int projectionSize() { - int size = localNodeId() != null ? 1 : 0; - - size += remoteNodeIds().size(); - - assert size > 0; - - return size; - } - - /** - * @return Collection of projection node IDs. - */ - private Collection<UUID> projectionNodeIds() { - Collection<UUID> ids = new LinkedList<>(); - - UUID id = localNodeId(); - - if (id != null) - ids.add(id); - - ids.addAll(remoteNodeIds()); - - assert !ids.isEmpty(); - - return ids; - } - - /** - * Test for projection on not existing node IDs. - */ - public void testInvalidProjection() { - Collection<UUID> ids = new HashSet<>(); - - ids.add(UUID.randomUUID()); - ids.add(UUID.randomUUID()); - - ClusterGroup invalidPrj = prj.forNodeIds(ids); - - assertEquals(0, invalidPrj.nodes().size()); - } - - /** - * @throws Exception If test failed. - */ - public void testProjection() throws Exception { - assert prj != null; - - assert prj.ignite() != null; - assert prj.predicate() != null; - - int size = projectionSize(); - - assert prj.nodes().size() == size; - - Collection<UUID> nodeIds = projectionNodeIds(); - - for (ClusterNode node : prj.nodes()) - assert nodeIds.contains(node.id()); - } - - /** - * @throws Exception If test failed. - */ - public void testRemoteNodes() throws Exception { - Collection<UUID> remoteNodeIds = remoteNodeIds(); - - UUID locNodeId = localNodeId(); - - int size = remoteNodeIds.size(); - - String name = "oneMoreGrid"; - - try { - Ignite g = startGrid(name); - - UUID excludedId = g.cluster().localNode().id(); - - assertEquals(size, prj.forRemotes().nodes().size()); - - for (ClusterNode node : prj.forRemotes().nodes()) { - UUID id = node.id(); - - assert !id.equals(locNodeId) && remoteNodeIds.contains(id) && !excludedId.equals(id); - } - } - finally { - stopGrid(name); - } - } - - /** - * @throws Exception If test failed. - */ - public void testRemoteProjection() throws Exception { - Collection<UUID> remoteNodeIds = remoteNodeIds(); - - ClusterGroup remotePrj = projection().forRemotes(); - - Collection<UUID> prjNodeIds = F.nodeIds(remotePrj.nodes()); - - assert prjNodeIds.size() == remoteNodeIds.size(); - - assert prjNodeIds.containsAll(remoteNodeIds()); - - assert !prjNodeIds.contains(localNodeId()); - - String name = "oneMoreGrid"; - - try { - Ignite g = startGrid(name); - - UUID excludedId = g.cluster().localNode().id(); - - assert !F.nodeIds(remotePrj.nodes()).contains(excludedId); - } - finally { - stopGrid(name); - } - } - - /** - * @throws Exception If test failed. - */ - public void testExecution() throws Exception { - String name = "oneMoreGrid"; - - Collection<IgniteBiTuple<Ignite, IgnitePredicate<IgniteEvent>>> lsnrs = new LinkedList<>(); - - try { - final AtomicInteger cnt = new AtomicInteger(); - - Ignite g = startGrid(name); - - IgnitePredicate<IgniteEvent> lsnr; - - if (!Ignite.class.isAssignableFrom(projection().getClass())) { - g.events().localListen(lsnr = new IgnitePredicate<IgniteEvent>() { - @Override public boolean apply(IgniteEvent evt) { - assert evt.type() == EVT_JOB_STARTED; - - assert false; - - return true; - } - }, EVT_JOB_STARTED); - - lsnrs.add(F.t(g, lsnr)); - } - - for (ClusterNode node : prj.nodes()) { - g = G.ignite(node.id()); - - g.events().localListen(lsnr = new IgnitePredicate<IgniteEvent>() { - @Override public boolean apply(IgniteEvent evt) { - assert evt.type() == EVT_JOB_STARTED; - - synchronized (mux) { - cnt.incrementAndGet(); - - mux.notifyAll(); - } - - return true; - } - }, EVT_JOB_STARTED); - - lsnrs.add(F.t(g, lsnr)); - } - - run1(cnt); - run2(cnt); - - call1(cnt); - call2(cnt); - call3(cnt); - call4(cnt); - call5(cnt); - - forkjoin1(cnt); - forkjoin2(cnt); - - exec1(cnt); - exec2(cnt); - - executorService(cnt); - - checkActiveFutures(); - } - finally { - for (IgniteBiTuple<Ignite, IgnitePredicate<IgniteEvent>> t : lsnrs) - t.get1().events().stopLocalListen(t.get2(), EVT_JOB_STARTED); - - stopGrid(name); - } - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void run1(AtomicInteger cnt) throws Exception { - IgniteCompute comp = compute(prj).enableAsync(); - - comp.broadcast(runJob); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).broadcast(runJob); - - waitForValue(cnt, projectionSize()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void run2(AtomicInteger cnt) throws Exception { - Collection<Runnable> jobs = F.asList(runJob); - - IgniteCompute comp = compute(prj).enableAsync(); - - comp.run(jobs); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).run(jobs); - - waitForValue(cnt, jobs.size()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void call1(AtomicInteger cnt) throws Exception { - IgniteCompute comp = compute(prj).enableAsync(); - - comp.broadcast(calJob); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).broadcast(calJob); - - waitForValue(cnt, projectionSize()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void call2(AtomicInteger cnt) throws Exception { - IgniteCompute comp = compute(prj).enableAsync(); - - Collection<Callable<String>> jobs = F.asList(calJob); - - comp.call(jobs); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).call(jobs); - - waitForValue(cnt, jobs.size()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void call3(AtomicInteger cnt) throws Exception { - IgniteCompute comp = compute(prj).enableAsync(); - - comp.apply(clrJob, (String) null); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).apply(clrJob, (String) null); - - waitForValue(cnt, 1); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void call4(AtomicInteger cnt) throws Exception { - Collection<String> args = F.asList("a", "b", "c"); - - IgniteCompute comp = compute(prj).enableAsync(); - - comp.apply(clrJob, args); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).apply(clrJob, args); - - waitForValue(cnt, args.size()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void call5(AtomicInteger cnt) throws Exception { - IgniteCompute comp = compute(prj).enableAsync(); - - comp.broadcast(new TestClosure(), "arg"); - - IgniteFuture<Collection<String>> fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - Collection<String> res = compute(prj).broadcast(new TestClosure(), "arg"); - - assertEquals(projectionSize(), res.size()); - - waitForValue(cnt, projectionSize()); - - for (String resStr : res) - assertEquals("arg", resStr); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void forkjoin1(AtomicInteger cnt) throws Exception { - Collection<String> args = F.asList("a", "b", "c"); - - IgniteCompute comp = compute(prj).enableAsync(); - - comp.apply(clrJob, args, rdc); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).apply(clrJob, args, rdc); - - waitForValue(cnt, args.size()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void forkjoin2(AtomicInteger cnt) throws Exception { - Collection<Callable<String>> jobs = F.asList(calJob); - - IgniteCompute comp = compute(prj).enableAsync(); - - comp.call(jobs, rdc); - - IgniteFuture fut = comp.future(); - - waitForExecution(fut); - - cnt.set(0); - - compute(prj).call(jobs, rdc); - - waitForValue(cnt, jobs.size()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void exec1(AtomicInteger cnt) throws Exception { - cnt.set(0); - - compute(prj).execute(TestTask.class.getName(), null); - - waitForValue(cnt, projectionSize()); - - cnt.set(0); - - compute(prj).execute(new TestTask(), null); - - waitForValue(cnt, projectionSize()); - - cnt.set(0); - - compute(prj).execute(TestTask.class, null); - - waitForValue(cnt, projectionSize()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void exec2(AtomicInteger cnt) throws Exception { - cnt.set(0); - - compute(prj).withTimeout(WAIT_TIMEOUT).execute(TestTask.class.getName(), null); - - waitForValue(cnt, projectionSize()); - - cnt.set(0); - - compute(prj).withTimeout(WAIT_TIMEOUT).execute(new TestTask(), null); - - waitForValue(cnt, projectionSize()); - - cnt.set(0); - - compute(prj).withTimeout(WAIT_TIMEOUT).execute(TestTask.class, null); - - waitForValue(cnt, projectionSize()); - } - - /** - * @param cnt Counter. - * @throws Exception If failed. - */ - private void executorService(AtomicInteger cnt) throws Exception { - cnt.set(0); - - ExecutorService execSrvc = prj.ignite().executorService(prj); - - Future<String> fut = execSrvc.submit(new TestCallable<String>() { - @Override public String call() throws Exception { - return "submit1"; - } - }); - - waitForValue(cnt, 1); - - assertEquals("submit1", fut.get()); - - cnt.set(0); - - fut = execSrvc.submit(new TestRunnable(), "submit2"); - - waitForValue(cnt, 1); - - assertEquals("submit2", fut.get()); - - cnt.set(0); - - Future<?> runFut = execSrvc.submit(new TestRunnable()); - - waitForValue(cnt, 1); - - runFut.get(); - } - - /** - * @param fut Execution future. - * @throws InterruptedException Thrown if wait was interrupted. - */ - @SuppressWarnings({"UnconditionalWait"}) - private void waitForExecution(IgniteFuture fut) throws InterruptedException { - long sleep = 250; - - long threshold = System.currentTimeMillis() + WAIT_TIMEOUT; - - do synchronized (mux) { - mux.wait(sleep); - } - while (fut != null && !fut.isDone() && !fut.isCancelled() && threshold > System.currentTimeMillis()); - - assert fut == null || fut.isDone(); - } - - /** - * @param cnt Counter to check. - * @param val Value to check. - * @throws InterruptedException Thrown if wait was interrupted. - */ - private void waitForValue(AtomicInteger cnt, int val) throws InterruptedException { - assert cnt != null; - assert val > 0; - - long threshold = System.currentTimeMillis() + WAIT_TIMEOUT; - - long time; - - while (threshold > (time = System.currentTimeMillis())) - synchronized (mux) { - if (cnt.get() == val) - break; - - mux.wait(threshold - time); - } - - assert cnt.get() == val; - } - - /** - * @throws Exception If test failed. - */ - private void checkActiveFutures() throws Exception { - IgniteCompute comp = compute(prj).enableAsync(); - - assertEquals(0, comp.activeTaskFutures().size()); - - cnt.set(0); - - Collection<ComputeTaskFuture<Object>> futsList = new ArrayList<>(); - - for (int i = 0; i < 10; i++) { - comp.call(new TestWaitCallable<Object>()); - - ComputeTaskFuture<Object> fut = comp.future(); - - assertFalse(fut.isDone()); - - Map<IgniteUuid, ComputeTaskFuture<Object>> futs = comp.activeTaskFutures(); - - assertEquals(i + 1, futs.size()); - - assertTrue(futs.containsKey(fut.getTaskSession().getId())); - - futsList.add(fut); - } - - synchronized (mux) { - cnt.incrementAndGet(); - - mux.notifyAll(); - } - - for (ComputeTaskFuture<Object> fut : futsList) - fut.get(); - - assertEquals(0, comp.activeTaskFutures().size()); - } - - /** - * Test closure. - */ - private static class TestClosure implements IgniteClosure<String, String> { - /** {@inheritDoc} */ - @Override public String apply(String s) { - return s; - } - } - - /** - * Test runnable. - */ - private static class TestRunnable implements Runnable, Serializable { - /** {@inheritDoc} */ - @Override public void run() { - // No-op. - } - } - - /** - * Test callable. - */ - private static class TestCallable<T> implements Callable<T>, Serializable { - /** {@inheritDoc} */ - @Nullable @Override public T call() throws Exception { - return null; - } - } - - /** - * Test callable. - */ - private static class TestWaitCallable<T> implements Callable<T>, Serializable { - /** {@inheritDoc} */ - @Nullable @Override public T call() throws Exception { - synchronized (mux) { - while (cnt.get() == 0) - mux.wait(); - } - - return null; - } - } - - /** - * Test task. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static class TestTask extends ComputeTaskSplitAdapter<String, Void> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException { - Collection<ComputeJob> jobs = new HashSet<>(); - - for (int i = 0; i < gridSize; i++) - jobs.add(new TestJob()); - - return jobs; - } - - /** {@inheritDoc} */ - @Nullable @Override public Void reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } - - /** - * Test job. - */ - @SuppressWarnings({"PublicInnerClass"}) - public static class TestJob extends ComputeJobAdapter { - /** {@inheritDoc} */ - @Nullable @Override public Object execute() throws IgniteCheckedException { - return null; - } - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // No-op. - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/537f631a/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionForCachesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionForCachesSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionForCachesSelfTest.java deleted file mode 100644 index 6defa2b..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/GridProjectionForCachesSelfTest.java +++ /dev/null @@ -1,256 +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.cache.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.spi.discovery.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -import static org.apache.ignite.cache.GridCacheMode.*; - -/** - * Tests for {@link org.apache.ignite.cluster.ClusterGroup#forCache(String, String...)} method. - */ -public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** */ - private static final String CACHE_NAME = "cache"; - - /** */ - private Ignite ignite; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setDiscoverySpi(discoverySpi()); - - if (gridName.equals(getTestGridName(0))) - cfg.setCacheConfiguration(cacheConfiguration(null)); - else if (gridName.equals(getTestGridName(1))) - cfg.setCacheConfiguration(cacheConfiguration(CACHE_NAME)); - else if (gridName.equals(getTestGridName(2)) || gridName.equals(getTestGridName(3))) - cfg.setCacheConfiguration(cacheConfiguration(null), cacheConfiguration(CACHE_NAME)); - else - cfg.setCacheConfiguration(); - - return cfg; - } - - /** - * @return Discovery SPI; - */ - private DiscoverySpi discoverySpi() { - TcpDiscoverySpi spi = new TcpDiscoverySpi(); - - spi.setIpFinder(IP_FINDER); - - return spi; - } - - /** - * @param cacheName Cache name. - * @return Cache configuration. - */ - private CacheConfiguration cacheConfiguration(@Nullable String cacheName) { - CacheConfiguration cfg = defaultCacheConfiguration(); - - cfg.setName(cacheName); - cfg.setCacheMode(PARTITIONED); - cfg.setBackups(1); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - for (int i = 0; i < 5; i++) - startGrid(i); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - ignite = grid(0); - } - - /** - * @throws Exception If failed. - */ - public void testProjectionForDefaultCache() throws Exception { - ClusterGroup prj = ignite.cluster().forCache(null); - - assert prj != null; - assert prj.nodes().size() == 3; - assert prj.nodes().contains(grid(0).localNode()); - assert !prj.nodes().contains(grid(1).localNode()); - assert prj.nodes().contains(grid(2).localNode()); - assert prj.nodes().contains(grid(3).localNode()); - assert !prj.nodes().contains(grid(4).localNode()); - } - - /** - * @throws Exception If failed. - */ - public void testProjectionForNamedCache() throws Exception { - ClusterGroup prj = ignite.cluster().forCache(CACHE_NAME); - - assert prj != null; - assert prj.nodes().size() == 3; - assert !prj.nodes().contains(grid(0).localNode()); - assert prj.nodes().contains(grid(1).localNode()); - assert prj.nodes().contains(grid(2).localNode()); - assert prj.nodes().contains(grid(3).localNode()); - assert !prj.nodes().contains(grid(4).localNode()); - } - - /** - * @throws Exception If failed. - */ - public void testProjectionForBothCaches() throws Exception { - ClusterGroup prj = ignite.cluster().forCache(null, CACHE_NAME); - - assert prj != null; - assert prj.nodes().size() == 2; - assert !prj.nodes().contains(grid(0).localNode()); - assert !prj.nodes().contains(grid(1).localNode()); - assert prj.nodes().contains(grid(2).localNode()); - assert prj.nodes().contains(grid(3).localNode()); - assert !prj.nodes().contains(grid(4).localNode()); - } - - /** - * @throws Exception If failed. - */ - public void testProjectionForWrongCacheName() throws Exception { - ClusterGroup prj = ignite.cluster().forCache("wrong"); - - assert prj != null; - assert prj.nodes().isEmpty(); - } - - /** - * @throws Exception If failed. - */ - public void testProjections() throws Exception { - ClusterNode locNode = ignite.cluster().localNode(); - UUID locId = locNode.id(); - - assertNotNull(locId); - - assertEquals(5, ignite.cluster().nodes().size()); - - ClusterGroup prj = ignite.cluster().forLocal(); - - assertEquals(1, prj.nodes().size()); - assertEquals(locNode, F.first(prj.nodes())); - - prj = ignite.cluster().forHost(locNode); - assertEquals(ignite.cluster().nodes().size(), prj.nodes().size()); - assertTrue(ignite.cluster().nodes().containsAll(prj.nodes())); - try { - ignite.cluster().forHost(null); - } - catch (NullPointerException ignored) { - // No-op. - } - - prj = ignite.cluster().forNode(locNode); - assertEquals(1, prj.nodes().size()); - - prj = ignite.cluster().forNode(locNode, locNode); - assertEquals(1, prj.nodes().size()); - - try { - ignite.cluster().forNode(null); - } - catch (NullPointerException ignored) { - // No-op. - } - - prj = ignite.cluster().forNodes(F.asList(locNode)); - assertEquals(1, prj.nodes().size()); - - prj = ignite.cluster().forNodes(F.asList(locNode, locNode)); - assertEquals(1, prj.nodes().size()); - - try { - ignite.cluster().forNodes(null); - } - catch (NullPointerException ignored) { - // No-op. - } - - prj = ignite.cluster().forNodeId(locId); - assertEquals(1, prj.nodes().size()); - - prj = ignite.cluster().forNodeId(locId, locId); - assertEquals(1, prj.nodes().size()); - - try { - ignite.cluster().forNodeId(null); - } - catch (NullPointerException ignored) { - // No-op. - } - - prj = ignite.cluster().forNodeIds(F.asList(locId)); - assertEquals(1, prj.nodes().size()); - - prj = ignite.cluster().forNodeIds(F.asList(locId, locId)); - assertEquals(1, prj.nodes().size()); - - try { - ignite.cluster().forNodeIds(null); - } - catch (NullPointerException ignored) { - // No-op. - } - - prj = ignite.cluster().forOthers(locNode); - - assertEquals(4, prj.nodes().size()); - assertFalse(prj.nodes().contains(locNode)); - - assertEquals(4, ignite.cluster().forRemotes().nodes().size()); - assertTrue(prj.nodes().containsAll(ignite.cluster().forRemotes().nodes())); - - try { - ignite.cluster().forOthers((ClusterNode)null); - } - catch (NullPointerException ignored) { - // No-op. - } - } -}