Search in sources :

Example 1 with BlockingBusyWaitingRoundRobinDistributorStrategy

use of teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy in project TeeTime by teetime-framework.

the class StaticTaskFarmStageTest method testOrderedStaticTaskFarmStageWithMultipleStage.

@Test
public void testOrderedStaticTaskFarmStageWithMultipleStage() throws Exception {
    ArrayCreator creator = new ArrayCreator(SEED);
    List<Integer> randomNumbers = creator.createFilledList(1024);
    TestTuple[] testInputTuples = { // expect in correct order
    TestTuple.use(2, randomNumbers).expect(randomNumbers), // expect in correct order
    TestTuple.use(3, randomNumbers).expect(randomNumbers) };
    for (TestTuple testTuple : testInputTuples) {
        StaticTaskFarmStage<Integer, Integer, Counter<Integer>> taskFarmStage = createTaskFarm(testTuple.numWorkerStages);
        // ordered element passing
        taskFarmStage.getDistributor().setStrategy(new BlockingBusyWaitingRoundRobinDistributorStrategy());
        taskFarmStage.getMerger().setStrategy(new BlockingBusyWaitingRoundRobinMergerStrategy());
        List<Integer> outputElements = new ArrayList<Integer>();
        test(taskFarmStage).and().send(testTuple.inputElements).to(taskFarmStage.getInputPort()).and().receive(outputElements).from(taskFarmStage.getOutputPort()).start();
        assertThat(outputElements, contains(testTuple.expectedOutputElements));
    }
}
Also used : Counter(teetime.stage.Counter) BlockingBusyWaitingRoundRobinMergerStrategy(teetime.stage.basic.merger.strategy.BlockingBusyWaitingRoundRobinMergerStrategy) ArrayList(java.util.ArrayList) ArrayCreator(teetime.testutil.ArrayCreator) BlockingBusyWaitingRoundRobinDistributorStrategy(teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy) Test(org.junit.Test)

Example 2 with BlockingBusyWaitingRoundRobinDistributorStrategy

use of teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy in project TeeTime by teetime-framework.

the class DistributorTest method roundRobinShouldWork.

@Test
public void roundRobinShouldWork() {
    distributor.setStrategy(new BlockingBusyWaitingRoundRobinDistributorStrategy());
    test(distributor).and().send(1, 2, 3, 4, 5).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and().receive(secondIntegers).from(distributor.getNewOutputPort()).start();
    assertThat(this.firstIntegers, contains(1, 3, 5));
    assertThat(this.secondIntegers, contains(2, 4));
}
Also used : BlockingBusyWaitingRoundRobinDistributorStrategy(teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy) Test(org.junit.Test)

Example 3 with BlockingBusyWaitingRoundRobinDistributorStrategy

use of teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy in project TeeTime by teetime-framework.

the class DistributorTest method singleElementRoundRobinShouldWork.

@Test
public void singleElementRoundRobinShouldWork() {
    distributor.setStrategy(new BlockingBusyWaitingRoundRobinDistributorStrategy());
    test(distributor).and().send(1).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and().receive(secondIntegers).from(distributor.getNewOutputPort()).start();
    assertThat(this.firstIntegers, contains(1));
    assertThat(this.secondIntegers, is(empty()));
}
Also used : BlockingBusyWaitingRoundRobinDistributorStrategy(teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 BlockingBusyWaitingRoundRobinDistributorStrategy (teetime.stage.basic.distributor.strategy.BlockingBusyWaitingRoundRobinDistributorStrategy)3 ArrayList (java.util.ArrayList)1 Counter (teetime.stage.Counter)1 BlockingBusyWaitingRoundRobinMergerStrategy (teetime.stage.basic.merger.strategy.BlockingBusyWaitingRoundRobinMergerStrategy)1 ArrayCreator (teetime.testutil.ArrayCreator)1