Skip to content
Snippets Groups Projects
Commit 6dbf89d8 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

added a check for exceptions in waitForTermination #221

parent 899853cf
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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;
}
......
......@@ -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());
}
}
......@@ -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
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment