From 894e7945461b257070451dd0884ca025c4f42ca4 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Thu, 30 Jul 2015 12:19:47 +0200 Subject: [PATCH] test now somewhat representative --- .../teetime/framework/TerminationTest.java | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/test/java/teetime/framework/TerminationTest.java b/src/test/java/teetime/framework/TerminationTest.java index 81a3c5a1..367636ec 100644 --- a/src/test/java/teetime/framework/TerminationTest.java +++ b/src/test/java/teetime/framework/TerminationTest.java @@ -1,17 +1,23 @@ package teetime.framework; -import org.junit.Test; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; -import teetime.stage.InitialElementProducer; +import org.junit.Test; public class TerminationTest { - @Test(timeout = 2000) + @Test(timeout = 3000) public void doesNotGetStuckInAdd() throws InterruptedException { - Execution<TerminationConfig> execution = new Execution<TerminationConfig>(new TerminationConfig(1)); + TerminationConfig configuration = new TerminationConfig(1); + Execution<TerminationConfig> execution = new Execution<TerminationConfig>(configuration); execution.executeNonBlocking(); - Thread.sleep(500); + Thread.sleep(100); execution.abortEventually(); + assertThat(configuration.sinkStage.time - 450, is(greaterThan(configuration.init.time))); } private class TerminationConfig extends Configuration { @@ -25,21 +31,50 @@ public class TerminationTest { } + private final class InitialElementProducer<T> extends AbstractProducerStage<T> { + + private final Iterable<T> elements; + public long time; + + public InitialElementProducer(final T... elements) { + this.elements = Arrays.asList(elements); + } + + @Override + protected void execute() { + for (final T element : this.elements) { + this.outputPort.send(element); + } + this.terminate(); + } + + @Override + protected void terminate() { + time = System.currentTimeMillis(); + super.terminate(); + } + + } + private class DoesNotRetrieveElements extends AbstractConsumerStage<Integer> { + public long time; + @Override protected void execute(final Integer element) { int i = 0; while (true) { i++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // First sleep will throw this + } if (i > 1) { Thread.currentThread().interrupt(); + time = System.currentTimeMillis(); break; } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } } } -- GitLab