You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/06/27 09:37:52 UTC

[10/10] ignite git commit: ignite-3361 Fixed condition in GridServiceProcessor.reassign.

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 <sb...@gridgain.com>
Authored: Mon Jun 27 12:29:22 2016 +0300
Committer: sboikov <sb...@gridgain.com>
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<UUID, Integer> 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);