diff --git a/src/main/java/teetime/framework/IntraStageVisitor.java b/src/main/java/teetime/framework/IntraStageVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..45543924eb0212688c8e95e2f11847c5888039ef --- /dev/null +++ b/src/main/java/teetime/framework/IntraStageVisitor.java @@ -0,0 +1,29 @@ +package teetime.framework; + +import java.util.ArrayList; +import java.util.List; + +import teetime.framework.pipe.IPipe; + +public class IntraStageVisitor implements IStageVisitor { + + private final List<Stage> visitedStages; + + public IntraStageVisitor() { + this.visitedStages = new ArrayList<Stage>(); + } + + @Override + public VisitorBehavior visit(final Stage stage, final IPipe inputPipe) { + if (inputPipe instanceof AbstractIntraThreadPipe) { + visitedStages.add(stage); + return VisitorBehavior.CONTINUE; + } + return VisitorBehavior.STOP; + } + + public List<Stage> getVisitedStages() { + return visitedStages; + } + +} diff --git a/src/main/java/teetime/framework/pipe/SpScPipe.java b/src/main/java/teetime/framework/pipe/SpScPipe.java index cf714c4d6d959af3893196cf6bda7f55f987f148..3a2087bf7d6c4541231821cdc67308d61658acef 100644 --- a/src/main/java/teetime/framework/pipe/SpScPipe.java +++ b/src/main/java/teetime/framework/pipe/SpScPipe.java @@ -50,7 +50,7 @@ public final class SpScPipe extends AbstractInterThreadPipe implements IMonitora try { Thread.sleep(1); } catch (InterruptedException e) { - // TODO Auto-generated catch block + // FIXME Handle it correctly e.printStackTrace(); } } diff --git a/src/test/java/teetime/framework/exceptionHandling/ExceptionHandling.java b/src/test/java/teetime/framework/exceptionHandling/ExceptionHandling.java index a13865c804155cf9e5631e66ce7a912a0a4b9af8..a126e4ec5fd452bca051b7656a9c293973f03d74 100644 --- a/src/test/java/teetime/framework/exceptionHandling/ExceptionHandling.java +++ b/src/test/java/teetime/framework/exceptionHandling/ExceptionHandling.java @@ -3,7 +3,6 @@ package teetime.framework.exceptionHandling; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Before; import org.junit.Test; import teetime.framework.Analysis; @@ -12,12 +11,12 @@ public class ExceptionHandling { private Analysis analysis; - @Before + // @Before public void newInstances() { analysis = new Analysis(new ExceptionTestConfiguration(), new TestListenerFactory()); } - @Test(timeout = 5000, expected = RuntimeException.class) + // @Test(timeout = 5000, expected = RuntimeException.class) public void exceptionPassingAndTermination() { analysis.execute(); assertEquals(TestListener.exceptionInvoked, 2); // listener did not kill thread to early @@ -28,4 +27,22 @@ public class ExceptionHandling { // TODO: more than one stage and check, if all are terminated (at least 3, each of every terminationtype) assertTrue(true); } + + /** + * If the consumer is terminated first while the pipe is full, the finite producer will be locked in + * SpScPipe.add and cycle through the sleep method. As a result, the thread will never return to the point + * where it checks if it should be terminated. + */ + @Test(timeout = 30000) + public void forAFewTimes() { + for (int i = 0; i < 1000; i++) { + newInstances(); + try { + exceptionPassingAndTermination(); + } catch (RuntimeException e) { + // TODO: handle exception + } + System.out.println(i); + } + } } diff --git a/src/test/java/teetime/framework/exceptionHandling/ExceptionTestProducerStage.java b/src/test/java/teetime/framework/exceptionHandling/ExceptionTestProducerStage.java index 637143ed57e3762f258524d922b15f896ac5b823..bd4729c4d4c4af5ff1fddb5a0c844320845331ef 100644 --- a/src/test/java/teetime/framework/exceptionHandling/ExceptionTestProducerStage.java +++ b/src/test/java/teetime/framework/exceptionHandling/ExceptionTestProducerStage.java @@ -32,10 +32,9 @@ public class ExceptionTestProducerStage extends AbstractProducerStage<Object> { @Override protected void execute() { getOutputPort().send(new Object()); - if (numberOfExecutions >= 10000) { + if (numberOfExecutions++ >= 10000 && strategy == TerminationStrategy.BY_SELF_DECISION) { this.terminate(); } - numberOfExecutions++; } @Override @@ -43,4 +42,11 @@ public class ExceptionTestProducerStage extends AbstractProducerStage<Object> { return strategy; } + @Override + public String getId() { + if (strategy == TerminationStrategy.BY_INTERRUPT) { + return "Infinite" + super.getId(); + } + return "Finite" + super.getId(); + } } diff --git a/src/test/java/teetime/framework/exceptionHandling/TestListener.java b/src/test/java/teetime/framework/exceptionHandling/TestListener.java index 9638e84d8d914488ef82a9dde95ffd51a4d96f72..638634e32dfdb779187e74aa115bbfdc156a6d5e 100644 --- a/src/test/java/teetime/framework/exceptionHandling/TestListener.java +++ b/src/test/java/teetime/framework/exceptionHandling/TestListener.java @@ -6,6 +6,10 @@ public class TestListener extends AbstractExceptionListener { public static int exceptionInvoked = 0; + public TestListener() { + TestListener.exceptionInvoked = 0; + } + @Override public FurtherExecution onStageException(final Exception e, final Stage throwingStage) { exceptionInvoked++;