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 4391A200B81 for ; Tue, 13 Sep 2016 22:38:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 42302160AD2; Tue, 13 Sep 2016 20:38:11 +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 64BAE160AAA for ; Tue, 13 Sep 2016 22:38:10 +0200 (CEST) Received: (qmail 73129 invoked by uid 500); 13 Sep 2016 20:38:09 -0000 Mailing-List: contact commits-help@fluo.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fluo.incubator.apache.org Delivered-To: mailing list commits@fluo.incubator.apache.org Received: (qmail 73116 invoked by uid 99); 13 Sep 2016 20:38:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2016 20:38:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2FE4D1A1364 for ; Tue, 13 Sep 2016 20:38:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id N1hUoFaxFzNh for ; Tue, 13 Sep 2016 20:38:08 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 562915FB50 for ; Tue, 13 Sep 2016 20:38:07 +0000 (UTC) Received: (qmail 73086 invoked by uid 99); 13 Sep 2016 20:38:06 -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, 13 Sep 2016 20:38:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 73572DFC7E; Tue, 13 Sep 2016 20:38:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kturner@apache.org To: commits@fluo.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-fluo git commit: fixes #764 fixed LoaderExecutor exception handling Date: Tue, 13 Sep 2016 20:38:06 +0000 (UTC) archived-at: Tue, 13 Sep 2016 20:38:11 -0000 Repository: incubator-fluo Updated Branches: refs/heads/master 2b1b2a2b0 -> cb78079bf fixes #764 fixed LoaderExecutor exception handling Project: http://git-wip-us.apache.org/repos/asf/incubator-fluo/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-fluo/commit/cb78079b Tree: http://git-wip-us.apache.org/repos/asf/incubator-fluo/tree/cb78079b Diff: http://git-wip-us.apache.org/repos/asf/incubator-fluo/diff/cb78079b Branch: refs/heads/master Commit: cb78079bf805d30c0292b74278561556da177f82 Parents: 2b1b2a2 Author: Keith Turner Authored: Fri Sep 9 12:17:02 2016 -0400 Committer: Keith Turner Committed: Fri Sep 9 12:17:02 2016 -0400 ---------------------------------------------------------------------- .../core/client/LoaderExecutorAsyncImpl.java | 18 +++++-- .../integration/client/LoaderExecutorIT.java | 52 ++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/cb78079b/modules/core/src/main/java/org/apache/fluo/core/client/LoaderExecutorAsyncImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/fluo/core/client/LoaderExecutorAsyncImpl.java b/modules/core/src/main/java/org/apache/fluo/core/client/LoaderExecutorAsyncImpl.java index d6f5187..b05467a 100644 --- a/modules/core/src/main/java/org/apache/fluo/core/client/LoaderExecutorAsyncImpl.java +++ b/modules/core/src/main/java/org/apache/fluo/core/client/LoaderExecutorAsyncImpl.java @@ -48,17 +48,23 @@ public class LoaderExecutorAsyncImpl implements LoaderExecutor { private final Counter commiting = new Counter(); + private void setException(Throwable t) { + if (!exceptionRef.compareAndSet(null, t)) { + LoggerFactory.getLogger(LoaderExecutorAsyncImpl.class).debug( + "Multiple exceptions occured, not reporting subsequent ones", t); + } + } + class LoaderCommitObserver implements AsyncCommitObserver, Runnable { AsyncTransaction txi; Loader loader; - private boolean done = false; + private AtomicBoolean done = new AtomicBoolean(false); private void close() { txi = null; - if (!done) { + if (done.compareAndSet(false, true)) { commiting.decrement(); - done = true; } else { // its only expected that this should be called once.. if its called multiple times in // indicates an error in asyn code @@ -81,7 +87,7 @@ public class LoaderExecutorAsyncImpl implements LoaderExecutor { @Override public void failed(Throwable t) { close(); - exceptionRef.compareAndSet(null, t); + setException(t); } @Override @@ -113,12 +119,14 @@ public class LoaderExecutorAsyncImpl implements LoaderExecutor { return env.getAppConfiguration(); } }; + try { loader.load(txi, context); env.getSharedResources().getCommitManager().beginCommit(txi, loader.getClass(), this); } catch (Exception e) { + setException(e); + close(); LoggerFactory.getLogger(LoaderCommitObserver.class).debug(e.getMessage(), e); - exceptionRef.compareAndSet(null, e); } } } http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/cb78079b/modules/integration/src/test/java/org/apache/fluo/integration/client/LoaderExecutorIT.java ---------------------------------------------------------------------- diff --git a/modules/integration/src/test/java/org/apache/fluo/integration/client/LoaderExecutorIT.java b/modules/integration/src/test/java/org/apache/fluo/integration/client/LoaderExecutorIT.java new file mode 100644 index 0000000..6fdb5c1 --- /dev/null +++ b/modules/integration/src/test/java/org/apache/fluo/integration/client/LoaderExecutorIT.java @@ -0,0 +1,52 @@ +/* + * 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.fluo.integration.client; + +import org.apache.fluo.api.client.Loader; +import org.apache.fluo.api.client.LoaderExecutor; +import org.apache.fluo.api.client.TransactionBase; +import org.apache.fluo.api.data.Column; +import org.apache.fluo.api.exceptions.AlreadySetException; +import org.apache.fluo.integration.ITBaseMini; +import org.junit.Assert; +import org.junit.Test; + +public class LoaderExecutorIT extends ITBaseMini { + + public static class BadLoader implements Loader { + + @Override + public void load(TransactionBase tx, Context context) throws Exception { + tx.set("r", new Column("f", "q"), "v"); + // setting same thing should cause exception + tx.set("r", new Column("f", "q"), "v2"); + } + + } + + @Test + public void testLoaderFailure() { + LoaderExecutor le = client.newLoaderExecutor(); + le.execute(new BadLoader()); + + try { + le.close(); + Assert.fail(); + } catch (RuntimeException e) { + Assert.assertEquals(AlreadySetException.class, e.getCause().getClass()); + } + } +}