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
Branches
Tags
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 ...@@ -50,7 +50,7 @@ public final class SpScPipe extends AbstractInterThreadPipe implements IMonitora
try { try {
Thread.sleep(1); Thread.sleep(1);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // FIXME Handle it correctly
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -3,7 +3,6 @@ package teetime.framework.exceptionHandling; ...@@ -3,7 +3,6 @@ package teetime.framework.exceptionHandling;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import teetime.framework.Analysis; import teetime.framework.Analysis;
...@@ -12,12 +11,12 @@ public class ExceptionHandling { ...@@ -12,12 +11,12 @@ public class ExceptionHandling {
private Analysis analysis; private Analysis analysis;
@Before // @Before
public void newInstances() { public void newInstances() {
analysis = new Analysis(new ExceptionTestConfiguration(), new TestListenerFactory()); analysis = new Analysis(new ExceptionTestConfiguration(), new TestListenerFactory());
} }
@Test(timeout = 5000, expected = RuntimeException.class) // @Test(timeout = 5000, expected = RuntimeException.class)
public void exceptionPassingAndTermination() { public void exceptionPassingAndTermination() {
analysis.execute(); analysis.execute();
assertEquals(TestListener.exceptionInvoked, 2); // listener did not kill thread to early assertEquals(TestListener.exceptionInvoked, 2); // listener did not kill thread to early
...@@ -28,4 +27,22 @@ public class ExceptionHandling { ...@@ -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) // TODO: more than one stage and check, if all are terminated (at least 3, each of every terminationtype)
assertTrue(true); 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> { ...@@ -32,10 +32,9 @@ public class ExceptionTestProducerStage extends AbstractProducerStage<Object> {
@Override @Override
protected void execute() { protected void execute() {
getOutputPort().send(new Object()); getOutputPort().send(new Object());
if (numberOfExecutions >= 10000) { if (numberOfExecutions++ >= 10000 && strategy == TerminationStrategy.BY_SELF_DECISION) {
this.terminate(); this.terminate();
} }
numberOfExecutions++;
} }
@Override @Override
...@@ -43,4 +42,11 @@ public class ExceptionTestProducerStage extends AbstractProducerStage<Object> { ...@@ -43,4 +42,11 @@ public class ExceptionTestProducerStage extends AbstractProducerStage<Object> {
return strategy; 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 { ...@@ -6,6 +6,10 @@ public class TestListener extends AbstractExceptionListener {
public static int exceptionInvoked = 0; public static int exceptionInvoked = 0;
public TestListener() {
TestListener.exceptionInvoked = 0;
}
@Override @Override
public FurtherExecution onStageException(final Exception e, final Stage throwingStage) { public FurtherExecution onStageException(final Exception e, final Stage throwingStage) {
exceptionInvoked++; exceptionInvoked++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment