Skip to content

Commit

Permalink
fixed MergerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Wulf committed May 9, 2015
1 parent 454499b commit f07a323
Showing 1 changed file with 10 additions and 54 deletions.
64 changes: 10 additions & 54 deletions src/test/java/teetime/stage/basic/merger/MergerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,25 @@
package teetime.stage.basic.merger;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static teetime.framework.test.StageTester.test;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import teetime.framework.pipe.IPipeFactory;
import teetime.framework.pipe.SingleElementPipeFactory;
import teetime.stage.CollectorSink;
import teetime.stage.InitialElementProducer;

/**
* @author Nils Christian Ehmke
*
* @since 1.0
*/
public class MergerTest {

private Merger<Integer> mergerUnderTest;
private CollectorSink<Integer> collector;
private InitialElementProducer<Integer> fstProducer;
private InitialElementProducer<Integer> sndProducer;

@Before
public void initializeMerger() throws Exception {
this.mergerUnderTest = new Merger<Integer>();
this.collector = new CollectorSink<Integer>();
this.fstProducer = new InitialElementProducer<Integer>(1, 2, 3);
this.sndProducer = new InitialElementProducer<Integer>(4, 5, 6);

final IPipeFactory pipeFactory = new SingleElementPipeFactory();
pipeFactory.create(this.fstProducer.getOutputPort(), this.mergerUnderTest.getNewInputPort());
pipeFactory.create(this.sndProducer.getOutputPort(), this.mergerUnderTest.getNewInputPort());
pipeFactory.create(this.mergerUnderTest.getOutputPort(), this.collector.getInputPort());

// mergerUnderTest.onInitializing();
// mergerUnderTest.onStarting();
}

@Test
@Ignore
public void roundRobinShouldWork() {
Merger<Integer> mergerUnderTest = new Merger<Integer>();
mergerUnderTest.setStrategy(new RoundRobinStrategy());

List<Integer> mergedElements = new ArrayList<Integer>();
Expand All @@ -75,36 +45,22 @@ public void roundRobinShouldWork() {
.receive(mergedElements).from(mergerUnderTest.getOutputPort())
.start();

// this.fstProducer.executeStage();
// this.sndProducer.executeStage();

assertThat(this.collector.getElements(), contains(1, 2, 3, 4, 5, 6));
assertThat(mergedElements, containsInAnyOrder(1, 2, 3, 4, 5, 6));
}

@Test
@Ignore
public void roundRobinWithSingleProducerShouldWork() {
Merger<Integer> mergerUnderTest = new Merger<Integer>();
mergerUnderTest.setStrategy(new RoundRobinStrategy());

// this.fstProducer.executeStage();

assertThat(this.collector.getElements(), contains(1, 2, 3));
}

@Ignore
// Needs to be rewritten
@Test
public void roundRobinShouldWork2() {
mergerUnderTest = new Merger<Integer>(new RoundRobinStrategy());
List<Integer> mergedElements = new ArrayList<Integer>();

List<Integer> outputList = new ArrayList<Integer>();
test(mergerUnderTest)
.and().send(1, 2, 3).to(mergerUnderTest.getNewInputPort())
.and().send(4, 5, 6).to(mergerUnderTest.getNewInputPort())
.and().receive(outputList).from(mergerUnderTest.getOutputPort())
test(mergerUnderTest).and()
.send(1, 2, 3).to(mergerUnderTest.getNewInputPort()).and()
.receive(mergedElements).from(mergerUnderTest.getOutputPort())
.start();

assertThat(outputList, is(not(empty())));
assertThat(outputList, contains(1, 4, 2, 5, 3, 6));
assertThat(mergedElements, contains(1, 2, 3));
}

}

0 comments on commit f07a323

Please sign in to comment.