Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3C155200C6F for ; Mon, 24 Apr 2017 10:21:28 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3ADFD160BB5; Mon, 24 Apr 2017 08:21:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DF594160BCA for ; Mon, 24 Apr 2017 10:21:25 +0200 (CEST) Received: (qmail 70297 invoked by uid 500); 24 Apr 2017 08:21:25 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 68226 invoked by uid 99); 24 Apr 2017 08:21:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Apr 2017 08:21:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D2E5BF4A42; Mon, 24 Apr 2017 08:21:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Mon, 24 Apr 2017 08:22:00 -0000 Message-Id: <5c93e42c6b934a148be2811734bfcac8@git.apache.org> In-Reply-To: <889ab3b6bf844b3c9e5398b780c2a69d@git.apache.org> References: <889ab3b6bf844b3c9e5398b780c2a69d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [42/65] [abbrv] ignite git commit: IGNITE-4699: Added custom executors for compute tasls. This closes #1718. archived-at: Mon, 24 Apr 2017 08:21:28 -0000 http://git-wip-us.apache.org/repos/asf/ignite/blob/f871b0d7/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeCustomExecutorSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeCustomExecutorSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeCustomExecutorSelfTest.java new file mode 100644 index 0000000..18c52c0 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeCustomExecutorSelfTest.java @@ -0,0 +1,245 @@ +/* + * 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.apache.ignite.internal.processors.compute; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.apache.ignite.IgniteCompute; +import org.apache.ignite.IgniteException; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobAdapter; +import org.apache.ignite.compute.ComputeJobResult; +import org.apache.ignite.compute.ComputeTaskSplitAdapter; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.ExecutorConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.lang.IgniteCallable; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgniteReducer; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.jetbrains.annotations.Nullable; + +/** + * Tests custom executor named pools. + * + * https://issues.apache.org/jira/browse/IGNITE-4699 + */ +public class IgniteComputeCustomExecutorSelfTest extends GridCommonAbstractTest { + /** */ + private static final int GRID_CNT = 2; + + /** */ + private static final String EXEC_NAME0 = "executor_0"; + + /** */ + private static final String EXEC_NAME1 = "executor_1"; + + /** */ + private static final String CACHE_NAME = "testcache"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setExecutorConfiguration(createExecConfiguration(EXEC_NAME0), createExecConfiguration(EXEC_NAME1)); + cfg.setPublicThreadPoolSize(1); + + CacheConfiguration ccfg = new CacheConfiguration(); + ccfg.setName(CACHE_NAME); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** + * @param name Custom executor name. + * @return Executor configuration. + */ + private ExecutorConfiguration createExecConfiguration(String name) { + ExecutorConfiguration exec = new ExecutorConfiguration(); + + exec.setName(name); + exec.setSize(1); + + return exec; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + startGrids(GRID_CNT); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * @throws Exception If fails. + */ + public void testInvalidCustomExecutor() throws Exception { + grid(0).compute().withExecutor("invalid").broadcast(new IgniteRunnable() { + @Override public void run() { + assertTrue(Thread.currentThread().getName().contains("pub")); + } + }); + } + + /** + * @throws Exception If fails. + */ + public void testAllComputeApiByCustomExecutor() throws Exception { + IgniteCompute comp = grid(0).compute().withExecutor(EXEC_NAME0); + + comp.affinityRun(CACHE_NAME, primaryKey(grid(1).cache(CACHE_NAME)), new IgniteRunnable() { + @Override public void run() { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + } + }); + + comp.affinityCall(CACHE_NAME, 0, new IgniteCallable() { + @Override public Object call() throws Exception { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }); + + comp.broadcast(new IgniteRunnable() { + @Override public void run() { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + } + }); + + comp.broadcast(new IgniteCallable() { + @Override public Object call() throws Exception { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }); + + comp.broadcast(new IgniteClosure() { + @Override public Object apply(Object o) { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }, 0); + + comp.apply(new IgniteClosure() { + @Override public Object apply(Object o) { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }, 0); + + comp.apply(new IgniteClosure() { + @Override public Object apply(Integer o) { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }, Collections.singletonList(0)); + + comp.apply(new IgniteClosure() { + @Override public Object apply(Integer o) { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }, Collections.singletonList(0), + new IgniteReducer() { + @Override public boolean collect(@Nullable Object o) { + return true; + } + + @Override public Object reduce() { + return null; + } + }); + + List> calls = new ArrayList<>(); + + for (int i = 0; i < GRID_CNT * 2; ++i) { + calls.add(new IgniteCallable() { + @Override public Object call() throws Exception { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + return null; + } + }); + } + + comp.call(calls.get(0)); + + comp.call(calls); + + comp.call(calls, + new IgniteReducer() { + @Override public boolean collect(@Nullable Object o) { + return true; + } + + @Override public Object reduce() { + return null; + } + }); + + List runs = new ArrayList<>(); + + for (int i = 0; i < GRID_CNT * 2; ++i) { + runs.add(new IgniteRunnable() { + @Override public void run() { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + } + }); + } + + comp.run(runs.get(0)); + + comp.run(runs); + + comp.execute(TestTask.class, null); + } + + /** + * Test task + */ + static class TestTask extends ComputeTaskSplitAdapter { + /** {@inheritDoc} */ + @Override protected Collection split(int gridSize, Object arg) throws IgniteException { + List jobs = new ArrayList<>(gridSize * 2); + + for (int i = 0; i < gridSize * 2; ++i) { + jobs.add(new ComputeJobAdapter() { + @Override public Object execute() throws IgniteException { + assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); + + return null; + } + }); + } + + return jobs; + } + + /** {@inheritDoc} */ + @Nullable @Override public Object reduce(List results) throws IgniteException { + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f871b0d7/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java index ff67b77..b8d1ce9 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java @@ -39,7 +39,7 @@ public class GridTestKernalContext extends GridKernalContextImpl { /** * @param log Logger to use in context config. */ - public GridTestKernalContext(IgniteLogger log) throws IgniteCheckedException { + public GridTestKernalContext(IgniteLogger log) { this(log, new IgniteConfiguration()); } @@ -47,7 +47,7 @@ public class GridTestKernalContext extends GridKernalContextImpl { * @param log Logger to use in context config. * @param cfg Configuration to use in Test */ - public GridTestKernalContext(IgniteLogger log, IgniteConfiguration cfg) throws IgniteCheckedException { + public GridTestKernalContext(IgniteLogger log, IgniteConfiguration cfg) { super(new GridLoggerProxy(log, null, null, null), new IgniteKernal(null), cfg, @@ -67,6 +67,7 @@ public class GridTestKernalContext extends GridKernalContextImpl { null, null, null, + null, U.allPluginProviders() ); http://git-wip-us.apache.org/repos/asf/ignite/blob/f871b0d7/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java index abd74b3..3f3bc53 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeGridTestSuite.java @@ -73,6 +73,8 @@ import org.apache.ignite.internal.TaskNodeRestartTest; import org.apache.ignite.internal.managers.checkpoint.GridCheckpointManagerSelfTest; import org.apache.ignite.internal.managers.checkpoint.GridCheckpointTaskSelfTest; import org.apache.ignite.internal.managers.communication.GridCommunicationManagerListenersSelfTest; +import org.apache.ignite.internal.processors.compute.IgniteComputeCustomExecutorConfigurationSelfTest; +import org.apache.ignite.internal.processors.compute.IgniteComputeCustomExecutorSelfTest; import org.apache.ignite.internal.processors.compute.PublicThreadpoolStarvationTest; import org.apache.ignite.internal.util.StripedExecutorTest; import org.apache.ignite.p2p.GridMultinodeRedeployContinuousModeSelfTest; @@ -158,6 +160,9 @@ public class IgniteComputeGridTestSuite { suite.addTestSuite(PublicThreadpoolStarvationTest.class); suite.addTestSuite(StripedExecutorTest.class); + suite.addTestSuite(IgniteComputeCustomExecutorConfigurationSelfTest.class); + suite.addTestSuite(IgniteComputeCustomExecutorSelfTest.class); + return suite; } }