ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [11/21] ignite git commit: ignite-3392 Added test.
Date Tue, 19 Jul 2016 01:27:20 GMT
ignite-3392 Added test.


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

Branch: refs/heads/ignite-3470
Commit: a056954bbb179300716961c116b51492889db356
Parents: 762c43d
Author: sboikov <sboikov@gridgain.com>
Authored: Wed Jul 13 12:29:33 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Wed Jul 13 12:29:33 2016 +0300

----------------------------------------------------------------------
 .../processors/service/GridServiceProxy.java    | 54 ++++++-------
 ...rviceDeploymentExceptionPropagationTest.java | 80 ++++++++++++++++++++
 2 files changed, 107 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a056954b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
index 25b2915..ba140f2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProxy.java
@@ -169,38 +169,38 @@ class GridServiceProxy<T> implements Serializable {
 
                         // If service is deployed locally, then execute locally.
                         if (node.isLocal()) {
-                            ServiceContextImpl svcCtx = ctx.service().serviceContext(name);
+                                ServiceContextImpl svcCtx = ctx.service().serviceContext(name);
 
-                        if (svcCtx != null) {
-                            Service svc = svcCtx.service();
+                            if (svcCtx != null) {
+                                Service svc = svcCtx.service();
 
-                            if (svc != null)
-                                return mtd.invoke(svc, args);
+                                if (svc != null)
+                                    return mtd.invoke(svc, args);
+                            }
+                        }
+                        else {
+                            // Execute service remotely.
+                            return ctx.closure().callAsyncNoFailover(
+                                BALANCE,
+                                new ServiceProxyCallable(mtd.getName(), name, mtd.getParameterTypes(),
args),
+                                Collections.singleton(node),
+                                false
+                            ).get();
                         }
                     }
-                    else {
-                        // Execute service remotely.
-                        return ctx.closure().callAsyncNoFailover(
-                            BALANCE,
-                            new ServiceProxyCallable(mtd.getName(), name, mtd.getParameterTypes(),
args),
-                            Collections.singleton(node),
-                            false
-                        ).get();
+                    catch (GridServiceNotFoundException | ClusterTopologyCheckedException
e) {
+                        if (log.isDebugEnabled())
+                            log.debug("Service was not found or topology changed (will retry):
" + e.getMessage());
+                    }
+                    catch (RuntimeException | Error e) {
+                        throw e;
+                    }
+                    catch (IgniteCheckedException e) {
+                        throw U.convertException(e);
+                    }
+                    catch (Exception e) {
+                        throw new IgniteException(e);
                     }
-                }
-                catch (GridServiceNotFoundException | ClusterTopologyCheckedException e)
{
-                    if (log.isDebugEnabled())
-                        log.debug("Service was not found or topology changed (will retry):
" + e.getMessage());
-                }
-                catch (RuntimeException | Error e) {
-                    throw e;
-                }
-                catch (IgniteCheckedException e) {
-                    throw U.convertException(e);
-                }
-                catch (Exception e) {
-                    throw new IgniteException(e);
-                }
 
                     // If we are here, that means that service was not found
                     // or topology was changed. In this case, we erase the

http://git-wip-us.apache.org/repos/asf/ignite/blob/a056954b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
new file mode 100644
index 0000000..811594f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeploymentExceptionPropagationTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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 org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceContext;
+import org.apache.ignite.testframework.GridStringLogger;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/** */
+public class GridServiceDeploymentExceptionPropagationTest extends GridCommonAbstractTest
{
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /** */
+    @SuppressWarnings("unused")
+    public void testExceptionPropagation() throws Exception {
+        try (Ignite srv = startGrid("server")) {
+
+            GridStringLogger log = new GridStringLogger();
+
+            try (Ignite client = startGrid("client", getConfiguration("client").setGridLogger(log).setClientMode(true)))
{
+
+                try {
+                    client.services().deployClusterSingleton("my-service", new ServiceImpl());
+                }
+                catch (IgniteException e) {
+                    assertTrue(log.toString().contains("ServiceImpl init exception"));
+
+                    return; // Exception is what we expect.
+                }
+
+                // Fail explicitly if we've managed to get here though we shouldn't have.
+                fail("https://issues.apache.org/jira/browse/IGNITE-3392");
+            }
+        }
+    }
+
+    /**
+     * Simple service implementation throwing an exception on init.
+     * Doesn't even try to do anything useful because what we're testing here is failure.
+     */
+    private static class ServiceImpl implements Service {
+        /** {@inheritDoc} */
+        @Override public void cancel(ServiceContext ctx) {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void init(ServiceContext ctx) throws Exception {
+            throw new RuntimeException("ServiceImpl init exception");
+        }
+
+        /** {@inheritDoc} */
+        @Override public void execute(ServiceContext ctx) throws Exception {
+            // No-op.
+        }
+    }
+}


Mime
View raw message