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

added IntraStageVisitor as draft; added explanation why the exception

test fails
parent 67cbd440
No related branches found
No related tags found
No related merge requests found
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;
}
}
......@@ -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();
}
}
......
......@@ -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);
}
}
}
......@@ -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();
}
}
......@@ -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++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment