From 619ab59d59a6ff4ddc141d461b2bbc757caa3999 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <ntd@informatik.uni-kiel.de> Date: Fri, 17 Apr 2015 14:27:46 +0200 Subject: [PATCH] enhanced test --- .../ExceptionHandlingTest.java | 32 +++++++++---------- .../ExceptionTestConfiguration.java | 10 ++++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/test/java/teetime/framework/exceptionHandling/ExceptionHandlingTest.java b/src/test/java/teetime/framework/exceptionHandling/ExceptionHandlingTest.java index 7c7edc73..4806872b 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 a30aee8b..95a6c8d3 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()); -- GitLab