ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [05/21] ignite git commit: ignite-3361 Fixed condition in GridServiceProcessor.reassign. (cherry picked from commit 76c76f8)
Date Tue, 05 Jul 2016 10:26:53 GMT
ignite-3361 Fixed condition in GridServiceProcessor.reassign.
(cherry picked from commit 76c76f8)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/55e616f7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/55e616f7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/55e616f7

Branch: refs/heads/master
Commit: 55e616f781a653071b7992aba85ced9af895176d
Parents: a70ff4c
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Jun 27 15:53:03 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Wed Jun 29 10:19:38 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/55e616f7/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 0bc1141..fd895ea 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
@@ -963,7 +963,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/55e616f7/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/55e616f7/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 c9cb531..b91fff4 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
@@ -66,6 +66,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;
@@ -141,6 +142,7 @@ public class IgniteKernalSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridServiceSerializationSelfTest.class);
         suite.addTestSuite(GridServiceProxyNodeStopSelfTest.class);
         suite.addTestSuite(GridServiceProxyClientReconnectSelfTest.class);
+        suite.addTestSuite(IgniteServiceReassignmentTest.class);
 
         suite.addTestSuite(IgniteServiceDeploymentClassLoadingDefaultMarshallerTest.class);
         suite.addTestSuite(IgniteServiceDeploymentClassLoadingOptimizedMarshallerTest.class);


Mime
View raw message