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 0DF55200B26 for ; Mon, 27 Jun 2016 11:37:46 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0C90C160A3C; Mon, 27 Jun 2016 09:37:46 +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 A3131160A73 for ; Mon, 27 Jun 2016 11:37:44 +0200 (CEST) Received: (qmail 16253 invoked by uid 500); 27 Jun 2016 09:37:43 -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 16021 invoked by uid 99); 27 Jun 2016 09:37:43 -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, 27 Jun 2016 09:37:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8DA8EE9423; Mon, 27 Jun 2016 09:37:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Mon, 27 Jun 2016 09:37:52 -0000 Message-Id: <91d27f78dc5a44cea12bc1d357800fb2@git.apache.org> In-Reply-To: <6a024dfd4dda431d84a13cc7941ea716@git.apache.org> References: <6a024dfd4dda431d84a13cc7941ea716@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/10] ignite git commit: ignite-3361 Fixed condition in GridServiceProcessor.reassign. archived-at: Mon, 27 Jun 2016 09:37:46 -0000 ignite-3361 Fixed condition in GridServiceProcessor.reassign. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2ac91a8f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2ac91a8f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2ac91a8f Branch: refs/heads/ignite-3361 Commit: 2ac91a8f353677b38ccd505d7c253a451f5c9d54 Parents: 46ba701 Author: sboikov Authored: Mon Jun 27 12:29:22 2016 +0300 Committer: sboikov Committed: Mon Jun 27 12:29:22 2016 +0300 ---------------------------------------------------------------------- .../service/GridServiceProcessor.java | 2 +- .../service/IgniteServiceReassignmentTest.java | 250 +++++++++++++++++++ .../testsuites/IgniteKernalSelfTestSuite.java | 2 + 3 files changed, 253 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/2ac91a8f/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java index add90e2..53eaeb5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java @@ -942,7 +942,7 @@ public class GridServiceProcessor extends GridProcessorAdapter { for (Map.Entry e : entries) { // Assign only the ones that have not been reused from previous assignments. if (!used.contains(e.getKey())) { - if (e.getValue() < maxPerNodeCnt) { + if (e.getValue() < maxPerNodeCnt || maxPerNodeCnt == 0) { e.setValue(e.getValue() + 1); if (--remainder == 0) http://git-wip-us.apache.org/repos/asf/ignite/blob/2ac91a8f/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceReassignmentTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceReassignmentTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceReassignmentTest.java new file mode 100644 index 0000000..d7937ec --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceReassignmentTest.java @@ -0,0 +1,250 @@ +/* + * 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.service; + +import java.util.concurrent.ThreadLocalRandom; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteException; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.PA; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.services.Service; +import org.apache.ignite.services.ServiceConfiguration; +import org.apache.ignite.services.ServiceContext; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteServiceReassignmentTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private ServiceConfiguration srvcCfg; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); + + if (srvcCfg != null) + cfg.setServiceConfiguration(srvcCfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + public void testNodeRestart1() throws Exception { + srvcCfg = serviceConfiguration(); + + Ignite node1 = startGrid(1); + + assertEquals(42, serviceProxy(node1).foo()); + + srvcCfg = serviceConfiguration(); + + Ignite node2 = startGrid(2); + + node1.close(); + + waitForService(node2); + + assertEquals(42, serviceProxy(node2).foo()); + + srvcCfg = serviceConfiguration(); + + Ignite node3 = startGrid(3); + + assertEquals(42, serviceProxy(node3).foo()); + + srvcCfg = serviceConfiguration(); + + node1 = startGrid(1); + + assertEquals(42, serviceProxy(node1).foo()); + assertEquals(42, serviceProxy(node2).foo()); + assertEquals(42, serviceProxy(node3).foo()); + + node2.close(); + + waitForService(node1); + + assertEquals(42, serviceProxy(node1).foo()); + assertEquals(42, serviceProxy(node3).foo()); + } + + /** + * @throws Exception If failed. + */ + public void testNodeRestart2() throws Exception { + startGrids(3); + + ServiceConfiguration svcCfg = new ServiceConfiguration(); + + svcCfg.setName("DummyService"); + svcCfg.setTotalCount(10); + svcCfg.setMaxPerNodeCount(1); + svcCfg.setService(new DummyService()); + + ignite(0).services().deploy(svcCfg); + + for (int i = 0; i < 3; i++) + assertEquals(42, serviceProxy(ignite(i)).foo()); + + for (int i = 0; i < 3; i++) + startGrid(i + 3); + + for (int i = 0; i < 3; i++) + stopGrid(i); + + for (int i = 0; i < 3; i++) + assertEquals(42, serviceProxy(ignite(i + 3)).foo()); + } + + /** + * @throws Exception If failed. + */ + public void testNodeRestartRandom() throws Exception { + final int NODES = 5; + + Ignite ignite = startGridsMultiThreaded(NODES); + + ignite.services().deploy(serviceConfiguration()); + + for (int i = 0; i < 30; i++) { + log.info("Iteration: " + i); + + int stopIdx = ThreadLocalRandom.current().nextInt(NODES); + + stopGrid(stopIdx); + + for (int nodeIdx = 0; nodeIdx < NODES; nodeIdx++) { + if (nodeIdx == stopIdx) + continue; + + waitForService(ignite(nodeIdx)); + + assertEquals(42, serviceProxy(ignite(nodeIdx)).foo()); + } + + startGrid(stopIdx); + + for (int nodeIdx = 0; nodeIdx < NODES; nodeIdx++) + assertEquals(42, serviceProxy(ignite(nodeIdx)).foo()); + } + } + + /** + * @param node Node. + * @throws Exception If failed. + */ + private void waitForService(final Ignite node) throws Exception { + assertTrue(GridTestUtils.waitForCondition(new PA() { + @Override public boolean apply() { + try { + serviceProxy(node).foo(); + + return true; + } + catch (IgniteException e) { + return false; + } + } + }, 5000)); + } + + /** + * @param node Node. + * @return Service proxy. + */ + private static MyService serviceProxy(Ignite node) { + return node.services().serviceProxy("DummyService", MyService.class, true); + } + + /** + * @return Service configuration. + */ + private ServiceConfiguration serviceConfiguration() { + ServiceConfiguration svc = new ServiceConfiguration(); + + svc.setName("DummyService"); + svc.setTotalCount(1); + svc.setService(new DummyService()); + + return svc; + } + + /** + * + */ + public interface MyService { + /** + * @return Dummy result. + */ + int foo(); + } + + /** + * + */ + static class DummyService implements MyService, Service { + /** */ + @IgniteInstanceResource + private Ignite locNode; + + /** {@inheritDoc} */ + @Override public void cancel(ServiceContext ctx) { + locNode.log().info("Service cancelled [execId=" + ctx.executionId() + + ", node=" + locNode.cluster().localNode() + ']'); + } + + /** {@inheritDoc} */ + @Override public void init(ServiceContext ctx) { + locNode.log().info("Service initialized [execId=" + ctx.executionId() + + ", node=" + locNode.cluster().localNode() + ']'); + } + + /** {@inheritDoc} */ + @Override public void execute(ServiceContext ctx) { + locNode.log().info("Service started [execId=" + ctx.executionId() + + ", node=" + locNode.cluster().localNode() + ']'); + } + + /** {@inheritDoc} */ + @Override public int foo() { + locNode.log().info("Service called."); + + return 42; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2ac91a8f/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java index d990b32..471bea7 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java @@ -65,6 +65,7 @@ import org.apache.ignite.internal.processors.service.IgniteServiceDeployment2Cla import org.apache.ignite.internal.processors.service.IgniteServiceDeploymentClassLoadingDefaultMarshallerTest; import org.apache.ignite.internal.processors.service.IgniteServiceDeploymentClassLoadingJdkMarshallerTest; import org.apache.ignite.internal.processors.service.IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest; +import org.apache.ignite.internal.processors.service.IgniteServiceReassignmentTest; import org.apache.ignite.internal.processors.service.ServicePredicateAccessCacheTest; import org.apache.ignite.internal.util.GridStartupWithSpecifiedWorkDirectorySelfTest; import org.apache.ignite.internal.util.GridStartupWithUndefinedIgniteHomeSelfTest; @@ -139,6 +140,7 @@ public class IgniteKernalSelfTestSuite extends TestSuite { suite.addTestSuite(GridServicePackagePrivateSelfTest.class); suite.addTestSuite(GridServiceSerializationSelfTest.class); suite.addTestSuite(GridServiceProxyNodeStopSelfTest.class); + suite.addTestSuite(IgniteServiceReassignmentTest.class); suite.addTestSuite(IgniteServiceDeploymentClassLoadingDefaultMarshallerTest.class); suite.addTestSuite(IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.class);