diff --git a/src/main/java/teetime/framework/Execution.java b/src/main/java/teetime/framework/Execution.java index e801ab6bdaa3570d8b19de73bb773dd74c65b834..441791eeef72d7cd7fe0df7ca19d02c12bf8e239 100644 --- a/src/main/java/teetime/framework/Execution.java +++ b/src/main/java/teetime/framework/Execution.java @@ -15,6 +15,8 @@ */ package teetime.framework; +import java.util.List; +import java.util.Map.Entry; import java.util.Set; import teetime.framework.signal.ValidatingSignal; @@ -104,7 +106,14 @@ public final class Execution<T extends Configuration> { * @since 2.0 */ public void waitForTermination() { + int numExceptions = 0; configurationContext.waitForConfigurationToTerminate(); + for (Entry<Thread, List<Exception>> entry : configuration.getFactory().getThreadExceptionsMap().entrySet()) { + numExceptions += entry.getValue().size(); + } + if (numExceptions != 0) { + throw new ExecutionException(configuration.getFactory().getThreadExceptionsMap()); + } } // TODO: implement diff --git a/src/main/java/teetime/framework/ExecutionException.java b/src/main/java/teetime/framework/ExecutionException.java index f33901b38239210b2aa5cf3df5563cd0cba1cc5c..bc6945bca79997767d294f70f7975bbd59b035ce 100644 --- a/src/main/java/teetime/framework/ExecutionException.java +++ b/src/main/java/teetime/framework/ExecutionException.java @@ -15,24 +15,23 @@ */ package teetime.framework; -import java.util.Collection; - -import teetime.util.ThreadThrowableContainer; +import java.util.List; +import java.util.Map; /** * Represents a exception, which is thrown by an analysis, if any problems occured within its execution. * A collection of thrown exceptions within the analysis can be retrieved with {@link #getThrownExceptions()}. * - * @since 1.1 + * @since 2.0 */ public class ExecutionException extends RuntimeException { private static final long serialVersionUID = 7486086437171884298L; - private final Collection<ThreadThrowableContainer> exceptions; + private final Map<Thread, List<Exception>> exceptions; - public ExecutionException(final Collection<ThreadThrowableContainer> exceptions) { - super((exceptions.size() == 1) ? exceptions.toString() : "Error(s) while execution. Check thrown exception(s)."); + public ExecutionException(final Map<Thread, List<Exception>> exceptions) { + super((exceptions.size() == 1) ? exceptions.toString() : exceptions.size() + " error(s) while execution. Check thrown exception(s)."); this.exceptions = exceptions; } @@ -40,9 +39,9 @@ public class ExecutionException extends RuntimeException { * Returns all exceptions thrown within the execution. * These are passed on as pairs of threads and throwables, to indicate a exception's context. * - * @return a collection of pairs + * @return a thread-exceptionlist-map */ - public Collection<ThreadThrowableContainer> getThrownExceptions() { + public Map<Thread, List<Exception>> getThrownExceptions() { return exceptions; } diff --git a/src/test/java/teetime/framework/RunnableConsumerStageTest.java b/src/test/java/teetime/framework/RunnableConsumerStageTest.java index 251a49610d2833610eded1320455997fb60842be..3984a2fe707b09b76d72a995fe0dd6cb406df161 100644 --- a/src/test/java/teetime/framework/RunnableConsumerStageTest.java +++ b/src/test/java/teetime/framework/RunnableConsumerStageTest.java @@ -18,16 +18,13 @@ package teetime.framework; import static org.junit.Assert.assertEquals; import java.lang.Thread.State; -import java.util.ArrayList; -import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.junit.Ignore; import org.junit.Test; -import teetime.util.ThreadThrowableContainer; - -import com.google.common.base.Joiner; - public class RunnableConsumerStageTest { @Test @@ -118,17 +115,17 @@ public class RunnableConsumerStageTest { } private void start(final Execution<?> execution) { - Collection<ThreadThrowableContainer> exceptions = new ArrayList<ThreadThrowableContainer>(); + Map<Thread, List<Exception>> exceptions = new HashMap<Thread, List<Exception>>(); try { execution.executeBlocking(); } catch (ExecutionException e) { exceptions = e.getThrownExceptions(); } - for (ThreadThrowableContainer pair : exceptions) { - System.err.println(pair.getThrowable()); - System.err.println(Joiner.on("\n").join(pair.getThrowable().getStackTrace())); - throw new AssertionError(pair.getThrowable()); - } + // for (ThreadThrowableContainer pair : exceptions) { + // System.err.println(pair.getThrowable()); + // System.err.println(Joiner.on("\n").join(pair.getThrowable().getStackTrace())); + // throw new AssertionError(pair.getThrowable()); + // } assertEquals(0, exceptions.size()); } } diff --git a/src/test/java/teetime/stage/InstanceOfFilterTest.java b/src/test/java/teetime/stage/InstanceOfFilterTest.java index 03c796a7fb1f0a11e66070a140e6fb273288ebbc..8389a8ba92d73c33f8349e0d51ba46b3a71c8ec7 100644 --- a/src/test/java/teetime/stage/InstanceOfFilterTest.java +++ b/src/test/java/teetime/stage/InstanceOfFilterTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertThat; import static teetime.framework.test.StageTester.test; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import org.junit.Before; @@ -32,7 +31,6 @@ import org.junit.Test; import teetime.framework.Configuration; import teetime.framework.Execution; import teetime.framework.ExecutionException; -import teetime.util.ThreadThrowableContainer; /** * @author Nils Christian Ehmke @@ -117,7 +115,7 @@ public class InstanceOfFilterTest { try { execution.executeBlocking(); } catch (ExecutionException e) { - Collection<ThreadThrowableContainer> thrownExceptions = e.getThrownExceptions(); + // Collection<ThreadThrowableContainer> thrownExceptions = e.getThrownExceptions(); // TODO: handle exception } }