diff --git a/src/test/java/teetime/framework/ExceptionHandling.java b/src/test/java/teetime/framework/ExceptionHandling.java index 78589966543d5687b1fbacd9f5393c758861bfdf..b7398676d4a8b12c66d86a83daad865ffa13efac 100644 --- a/src/test/java/teetime/framework/ExceptionHandling.java +++ b/src/test/java/teetime/framework/ExceptionHandling.java @@ -1,14 +1,19 @@ package teetime.framework; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; +import teetime.framework.exceptionHandling.TestListener; + public class ExceptionHandling { @Test - public void test() { - fail("Not yet implemented"); + public void exceptionPassingAndTermination() { + TestListener listener = new TestListener(); + Analysis analysis = new Analysis(new ExceptionTestConfiguration(), listener); + analysis.init(); + analysis.start(); + assertEquals(TestListener.exceptionInvoked, 2); } - } diff --git a/src/test/java/teetime/framework/ExceptionTestConfiguration.java b/src/test/java/teetime/framework/ExceptionTestConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..5b6c4adee8f69bd6baeaf21d5798abf5f102162c --- /dev/null +++ b/src/test/java/teetime/framework/ExceptionTestConfiguration.java @@ -0,0 +1,8 @@ +package teetime.framework; + +public class ExceptionTestConfiguration extends AnalysisConfiguration { + + public ExceptionTestConfiguration() { + this.addThreadableStage(new ExceptionTestStage()); + } +} diff --git a/src/test/java/teetime/framework/ExceptionTestStage.java b/src/test/java/teetime/framework/ExceptionTestStage.java new file mode 100644 index 0000000000000000000000000000000000000000..c6aa4e64abfa6a69aa2f3f3da43e7a4653950e5d --- /dev/null +++ b/src/test/java/teetime/framework/ExceptionTestStage.java @@ -0,0 +1,14 @@ +package teetime.framework; + +public class ExceptionTestStage extends AbstractProducerStage { + + public int loops = 0; + + @Override + protected void execute() { + if (loops % 1000 == 0) { + throw new IllegalStateException("1000 loops"); + } + loops++; + } +} diff --git a/src/test/java/teetime/framework/exceptionHandling/TestListener.java b/src/test/java/teetime/framework/exceptionHandling/TestListener.java index d7f598bfd2a4877db0da42408c5449b2a7bca47d..34d040315418cb23c696527b9dc95cceb88e9ebd 100644 --- a/src/test/java/teetime/framework/exceptionHandling/TestListener.java +++ b/src/test/java/teetime/framework/exceptionHandling/TestListener.java @@ -4,10 +4,16 @@ import teetime.framework.Stage; public class TestListener extends StageExceptionListener { + public static int exceptionInvoked = 0; + @Override - public FurtherExecution onStageException(Exception e, Stage throwingStage) { - // TODO Auto-generated method stub - return null; + public FurtherExecution onStageException(final Exception e, final Stage throwingStage) { + exceptionInvoked++; + if (exceptionInvoked == 2) { + return FurtherExecution.TERMINATE; + } else { + return FurtherExecution.CONTINUE; + } } }