diff --git a/src/test/java/teetime/framework/exceptionHandling/ExceptionHandlingTest.java b/src/test/java/teetime/framework/exceptionHandling/ExceptionHandlingTest.java index 7c7edc739d1dc7ef947d09e2ef1950ba06593026..4806872bb20d1076a483d2139ffb8f46c9a259be 100644 --- a/src/test/java/teetime/framework/exceptionHandling/ExceptionHandlingTest.java +++ b/src/test/java/teetime/framework/exceptionHandling/ExceptionHandlingTest.java @@ -15,48 +15,46 @@ */ package teetime.framework.exceptionHandling; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThat; import org.junit.Test; import teetime.framework.Analysis; +import teetime.framework.StageState; public class ExceptionHandlingTest { private Analysis<ExceptionTestConfiguration> analysis; - // @Before - public void newInstances() { - analysis = new Analysis<ExceptionTestConfiguration>(new ExceptionTestConfiguration(), new TestListenerFactory()); + public ExceptionTestConfiguration newInstances() { + ExceptionTestConfiguration configuration = new ExceptionTestConfiguration(); + analysis = new Analysis<ExceptionTestConfiguration>(configuration, new TestListenerFactory()); + return configuration; } - @Test(expected = RuntimeException.class) + @Test public void exceptionPassingAndTermination() { + newInstances(); analysis.executeBlocking(); assertEquals(TestListener.exceptionInvoked, 2); // listener did not kill thread to early } @Test public void terminatesAllStages() { - // TODO: more than one stage and check, if all are terminated (at least 3, each of every terminationtype) - assertTrue(true); + ExceptionTestConfiguration config = newInstances(); + analysis.executeBlocking(); + assertThat(config.first.getCurrentState(), is(StageState.TERMINATED)); + assertThat(config.second.getCurrentState(), is(StageState.TERMINATED)); + assertThat(config.third.getCurrentState(), is(StageState.TERMINATED)); } - /** - * 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 public void forAFewTimes() { for (int i = 0; i < 100; i++) { newInstances(); - try { - exceptionPassingAndTermination(); - } catch (RuntimeException e) { - // TODO: handle exception - } + exceptionPassingAndTermination(); } } } diff --git a/src/test/java/teetime/framework/exceptionHandling/ExceptionTestConfiguration.java b/src/test/java/teetime/framework/exceptionHandling/ExceptionTestConfiguration.java index a30aee8b5a57635ab464b32f9249c9020594ee4e..95a6c8d33cec6e1e10aaa03e0d8e0e2666bb5747 100644 --- a/src/test/java/teetime/framework/exceptionHandling/ExceptionTestConfiguration.java +++ b/src/test/java/teetime/framework/exceptionHandling/ExceptionTestConfiguration.java @@ -21,10 +21,14 @@ import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; public class ExceptionTestConfiguration extends AnalysisConfiguration { + ExceptionTestProducerStage first; + ExceptionTestConsumerStage second; + ExceptionTestProducerStage third; + public ExceptionTestConfiguration() { - ExceptionTestProducerStage first = new ExceptionTestProducerStage(); - ExceptionTestConsumerStage second = new ExceptionTestConsumerStage(); - ExceptionTestProducerStage third = new ExceptionTestProducerStage(); + first = new ExceptionTestProducerStage(); + second = new ExceptionTestConsumerStage(); + third = new ExceptionTestProducerStage(); PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTER, PipeOrdering.QUEUE_BASED, false) .create(first.getOutputPort(), second.getInputPort());