diff --git a/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java b/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java index 5e754856ca8e27b36d99be8ff27c233661988f0f..5d00b8f672b5debf1f1422a6aaa999a8aac254a5 100644 --- a/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java +++ b/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java @@ -47,20 +47,13 @@ public class TokenizerConfiguration extends AnalysisConfiguration { final Tokenizer tokenizer = new Tokenizer(" "); this.counter = new Counter<String>(); - INTRA_PIPE_FACTORY.create( - init.getOutputPort(), f2b.getInputPort()); - INTRA_PIPE_FACTORY.create( - f2b.getOutputPort(), decomp.getInputPort()); - INTRA_PIPE_FACTORY.create( - decomp.getOutputPort(), decrypt.getInputPort()); - INTRA_PIPE_FACTORY.create( - decrypt.getOutputPort(), b2s.getInputPort()); - INTRA_PIPE_FACTORY.create( - b2s.getOutputPort(), tokenizer.getInputPort()); - INTRA_PIPE_FACTORY.create( - tokenizer.getOutputPort(), this.counter.getInputPort()); + INTRA_PIPE_FACTORY.create(init.getOutputPort(), f2b.getInputPort()); + INTRA_PIPE_FACTORY.create(f2b.getOutputPort(), decomp.getInputPort()); + INTRA_PIPE_FACTORY.create(decomp.getOutputPort(), decrypt.getInputPort()); + INTRA_PIPE_FACTORY.create(decrypt.getOutputPort(), b2s.getInputPort()); + INTRA_PIPE_FACTORY.create(b2s.getOutputPort(), tokenizer.getInputPort()); + INTRA_PIPE_FACTORY.create(tokenizer.getOutputPort(), this.counter.getInputPort()); - // this.getFiniteProducerStages().add(init); this.addThreadableStage(init); } diff --git a/src/test/java/teetime/stage/InstanceOfFilterTest.java b/src/test/java/teetime/stage/InstanceOfFilterTest.java index 23ed21e0c980817221c443984ba24769ed265e84..cfdd85c508e6f81f4d9daaf8d2ea0e706fcc442a 100644 --- a/src/test/java/teetime/stage/InstanceOfFilterTest.java +++ b/src/test/java/teetime/stage/InstanceOfFilterTest.java @@ -23,11 +23,20 @@ import static org.junit.Assert.assertThat; import static teetime.framework.test.StageTester.test; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.junit.Before; import org.junit.Test; +import teetime.framework.Analysis; +import teetime.framework.AnalysisConfiguration; +import teetime.framework.AnalysisException; +import teetime.framework.pipe.IPipeFactory; +import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; +import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; +import teetime.util.Pair; + /** * @author Nils Christian Ehmke */ @@ -45,7 +54,10 @@ public class InstanceOfFilterTest { final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>(); final Object clazz = new Clazz(); - test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start(); + test(filter) + .and().send(clazz).to(filter.getInputPort()) + .and().receive(results).from(filter.getMatchedOutputPort()) + .start(); assertThat(results, contains(clazz)); } @@ -55,7 +67,10 @@ public class InstanceOfFilterTest { final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>(); final Object clazz = new SubClazz(); - test(filter).and().send(clazz).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start(); + test(filter) + .and().send(clazz).to(filter.getInputPort()) + .and().receive(results).from(filter.getMatchedOutputPort()) + .start(); assertThat(results, contains(clazz)); } @@ -65,7 +80,10 @@ public class InstanceOfFilterTest { final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>(); final Object object = new Object(); - test(filter).and().send(object).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start(); + test(filter) + .and().send(object).to(filter.getInputPort()) + .and().receive(results).from(filter.getMatchedOutputPort()) + .start(); assertThat(results, is(empty())); } @@ -81,7 +99,10 @@ public class InstanceOfFilterTest { input.add(new SubClazz()); input.add(new Object()); - test(filter).and().send(input).to(filter.getInputPort()).and().receive(results).from(filter.getMatchedOutputPort()).start(); + test(filter) + .and().send(input).to(filter.getInputPort()) + .and().receive(results).from(filter.getMatchedOutputPort()) + .start(); assertThat(results, hasSize(2)); } @@ -92,4 +113,34 @@ public class InstanceOfFilterTest { private static class SubClazz extends Clazz { } + @Test + public void filterShouldSendToBothOutputPorts() throws Exception { + InstanceOfFilterTestConfig config = new InstanceOfFilterTestConfig(); + Analysis analysis = new Analysis(config); + try { + analysis.execute(); + } catch (AnalysisException e) { + Collection<Pair<Thread, Throwable>> thrownExceptions = e.getThrownExceptions(); + // TODO: handle exception + } + } + + private static class InstanceOfFilterTestConfig extends AnalysisConfiguration { + + private final IPipeFactory pipeFactory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); + + public InstanceOfFilterTestConfig() { + InitialElementProducer<Object> elementProducer = new InitialElementProducer<Object>(); + InstanceOfFilter<Object, Clazz> instanceOfFilter = new InstanceOfFilter<Object, Clazz>(Clazz.class); + CollectorSink<Clazz> clazzCollector = new CollectorSink<Clazz>(); + CollectorSink<Object> mismatchedCollector = new CollectorSink<Object>(); + + pipeFactory.create(elementProducer.getOutputPort(), instanceOfFilter.getInputPort()); + pipeFactory.create(instanceOfFilter.getMatchedOutputPort(), clazzCollector.getInputPort()); + pipeFactory.create(instanceOfFilter.getMismatchedOutputPort(), mismatchedCollector.getInputPort()); + + addThreadableStage(elementProducer); + } + } + }