From e4492868d34b6025883b4ca9290e6f3415014664 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <ntd@informatik.uni-kiel.de> Date: Wed, 15 Apr 2015 14:37:55 +0200 Subject: [PATCH] added tests for the new methods --- .../java/teetime/framework/AnalysisTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/test/java/teetime/framework/AnalysisTest.java diff --git a/src/test/java/teetime/framework/AnalysisTest.java b/src/test/java/teetime/framework/AnalysisTest.java new file mode 100644 index 00000000..cbe159dc --- /dev/null +++ b/src/test/java/teetime/framework/AnalysisTest.java @@ -0,0 +1,70 @@ +package teetime.framework; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import teetime.framework.pipe.IPipeFactory; +import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; +import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; +import teetime.stage.InitialElementProducer; +import teetime.util.StopWatch; + +public class AnalysisTest { + + private Analysis analysis; + private TestConfig configuration; + + @Test + public void testExecuteNonBlocking() throws Exception { + newInstances(); + analysis.executeNonBlocking(); + assertFalse(configuration.delay.finished); + analysis.waitForTermination(); + assertTrue(configuration.delay.finished); + } + + @Test + public void testExecuteBlocking() { + StopWatch watch = new StopWatch(); + newInstances(); + watch.start(); + analysis.executeBlocking(); + watch.end(); + assertTrue(watch.getDurationInNs() >= 500000000); + } + + private void newInstances() { + configuration = new TestConfig(); + analysis = new Analysis(configuration); + } + + private class TestConfig extends AnalysisConfiguration { + final IPipeFactory intraFact = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); + public final DelayAndTerminate delay; + + public TestConfig() { + final InitialElementProducer<String> init = new InitialElementProducer<String>("Hello"); + delay = new DelayAndTerminate(); + intraFact.create(init.getOutputPort(), delay.getInputPort()); + addThreadableStage(init); + } + } + + private class DelayAndTerminate extends AbstractConsumerStage<String> { + + public boolean finished; + + @Override + protected void execute(final String element) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + finished = true; + } + + } + +} -- GitLab