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 9907C200B71 for ; Tue, 19 Jul 2016 03:27:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 97F79160A6D; Tue, 19 Jul 2016 01:27:12 +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 73F3E160A93 for ; Tue, 19 Jul 2016 03:27:11 +0200 (CEST) Received: (qmail 93388 invoked by uid 500); 19 Jul 2016 01:27:10 -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 93030 invoked by uid 99); 19 Jul 2016 01:27:10 -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; Tue, 19 Jul 2016 01:27:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5645CE93E5; Tue, 19 Jul 2016 01:27:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vkulichenko@apache.org To: commits@ignite.apache.org Date: Tue, 19 Jul 2016 01:27:20 -0000 Message-Id: <25abd83cc63a4ccfa2998c5647036fa1@git.apache.org> In-Reply-To: <37c19c8217a54297b38a6fa0457bc0ed@git.apache.org> References: <37c19c8217a54297b38a6fa0457bc0ed@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/21] ignite git commit: ignite-3392 Added test. archived-at: Tue, 19 Jul 2016 01:27:12 -0000 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 Authored: Wed Jul 13 12:29:33 2016 +0300 Committer: sboikov 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 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. + } + } +}