diff --git a/src/main/java/teetime/framework/Traversor.java b/src/main/java/teetime/framework/Traversor.java index 725ca3148eadd8196cbe90836850f5dabc47714c..bcc36c080330188bf3f855e14356916c6f2838eb 100644 --- a/src/main/java/teetime/framework/Traversor.java +++ b/src/main/java/teetime/framework/Traversor.java @@ -31,17 +31,18 @@ public class Traversor { } public void traverse(final Stage stage, final IPipe inputPipe) { - if (!visitedStage.contains(stage)) { - visitedStage.add(stage); - } else { - return; - } VisitorBehavior visitorBehavior = stageVisitor.visit(stage, inputPipe); if (visitorBehavior == VisitorBehavior.STOP) { return; } + if (!visitedStage.contains(stage)) { + visitedStage.add(stage); + } else { + return; + } + OutputPort<?>[] outputPorts = stage.getOutputPorts(); for (OutputPort<?> outputPort : outputPorts) { IPipe pipe = outputPort.getPipe(); diff --git a/src/test/java/teetime/framework/TraversorTest.java b/src/test/java/teetime/framework/TraversorTest.java index 19ac88ca121365481f6ac1cb4b181da9f2f01178..60db1db2cf7af46a053b206b85ac6f465a9b5a65 100644 --- a/src/test/java/teetime/framework/TraversorTest.java +++ b/src/test/java/teetime/framework/TraversorTest.java @@ -1,6 +1,10 @@ package teetime.framework; +import static org.junit.Assert.assertTrue; + import java.io.File; +import java.util.HashSet; +import java.util.Set; import org.junit.Test; @@ -24,21 +28,28 @@ public class TraversorTest { @Test public void traverse() { TestConfiguration tc = new TestConfiguration(); + new Analysis(tc).execute(); traversor.traverse(tc.init, tc.init.getOutputPort().getPipe()); - System.out.println(traversor.getVisitedStage()); + Set<Stage> comparingSet = new HashSet<Stage>(); + comparingSet.add(tc.init); + comparingSet.add(tc.f2b); + comparingSet.add(tc.distributor); + assertTrue(comparingSet.equals(traversor.getVisitedStage())); } private class TestConfiguration extends AnalysisConfiguration { public final CountingMapMerger<String> result = new CountingMapMerger<String>(); public final InitialElementProducer<File> init; + public final File2SeqOfWords f2b; + public Distributor<String> distributor; public TestConfiguration() { - int threads = 1; + int threads = 2; init = new InitialElementProducer<File>(new File("")); // final File2Lines f2b = new File2Lines(); - final File2SeqOfWords f2b = new File2SeqOfWords("UTF-8", 512); - Distributor<String> distributor = new Distributor<String>(new RoundRobinStrategy2()); + f2b = new File2SeqOfWords("UTF-8", 512); + distributor = new Distributor<String>(new RoundRobinStrategy2()); // last part final Merger<CountingMap<String>> merger = new Merger<CountingMap<String>>();