From 4e583dce42816c03ba47661cff2c375976abec56 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Wed, 29 Jul 2015 15:32:01 +0200 Subject: [PATCH] added first test --- pom.xml | 2 +- .../java/teetime/framework/Execution.java | 2 +- .../teetime/framework/TerminationTest.java | 48 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/test/java/teetime/framework/TerminationTest.java diff --git a/pom.xml b/pom.xml index d2e664f3..e40e11d5 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <javadocOutputDir>apidocs</javadocOutputDir> - + <java.version>1.6</java.version> <checkstyle.version>2.16</checkstyle.version> <findbugs.version>3.0.1</findbugs.version> diff --git a/src/main/java/teetime/framework/Execution.java b/src/main/java/teetime/framework/Execution.java index 5ba331da..2c0b7be7 100644 --- a/src/main/java/teetime/framework/Execution.java +++ b/src/main/java/teetime/framework/Execution.java @@ -118,7 +118,7 @@ public final class Execution<T extends Configuration> { } // TODO: implement - private void abortEventually() { + public void abortEventually() { configurationContext.abortConfigurationRun(); waitForTermination(); } diff --git a/src/test/java/teetime/framework/TerminationTest.java b/src/test/java/teetime/framework/TerminationTest.java new file mode 100644 index 00000000..ce339f90 --- /dev/null +++ b/src/test/java/teetime/framework/TerminationTest.java @@ -0,0 +1,48 @@ +package teetime.framework; + +import org.junit.Test; + +import teetime.stage.InitialElementProducer; + +public class TerminationTest { + + @Test(timeout = 2000) + public void doesNotGetStuckInAdd() throws InterruptedException { + Execution<TerminationConfig> execution = new Execution<TerminationConfig>(new TerminationConfig()); + execution.executeNonBlocking(); + Thread.sleep(1000); + execution.abortEventually(); + } + + private class TerminationConfig extends Configuration { + InitialElementProducer<Integer> init = new InitialElementProducer<Integer>(1, 2, 3, 4, 5, 6); + DoesNotRetrieveElements sinkStage = new DoesNotRetrieveElements(); + + public TerminationConfig() { + connectPorts(init.getOutputPort(), sinkStage.getInputPort(), 1); + addThreadableStage(sinkStage); + } + + } + + private class DoesNotRetrieveElements extends AbstractConsumerStage<Integer> { + + @Override + protected void execute(final Integer element) { + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + // Will happen in this test + } + + } + + @Override + protected void terminate() { + Thread.currentThread().interrupt(); + System.out.println("TADA " + this.shouldBeTerminated()); + } + + } + +} -- GitLab