use of teetime.stage.Counter in project TeeTime by teetime-framework.
the class ThreeStagesGlobalTaskPoolIT method shouldExecutePipelineCorrectlyManyElements.
private void shouldExecutePipelineCorrectlyManyElements(final int numElements, final int numThreads, final int numExecutions) {
List<Integer> processedElements = new ArrayList<>();
IntStream inputElements = IntStream.iterate(0, i -> i + 1).limit(numElements);
Configuration config = new Configuration().from(new StreamProducer<>(inputElements)).to(new Counter<>()).end(new CollectorSink<>(processedElements));
TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(numThreads, config, numExecutions);
Execution<Configuration> execution = new Execution<>(config, true, scheduling);
execution.executeBlocking();
for (int i = 0; i < numElements; i++) {
Integer actualElement = processedElements.get(i);
assertThat(actualElement, is(i));
}
assertThat(processedElements, hasSize(numElements));
}
use of teetime.stage.Counter in project TeeTime by teetime-framework.
the class DynamicTaskFarmStageTest method testDynamicTaskFarmStage.
@Test
@Ignore("declareActive at runtime is required, but not yet implemented/merged")
public void testDynamicTaskFarmStage() throws Exception {
final Integer[] elements = { 1, 2, 3 };
final ElementTrigger<Integer> producer = new ElementTrigger<Integer>(elements);
final DynamicTaskFarmStage<Integer, Integer, Counter<Integer>> dynamicTaskFarmStage = new DynamicTaskFarmStage<Integer, Integer, Counter<Integer>>(new Counter<Integer>(), 1);
final CollectorSink<Integer> collectorSink = new CollectorSink<Integer>();
Configuration configuration = new Configuration() {
{
connectPorts(producer.getOutputPort(), dynamicTaskFarmStage.getInputPort());
connectPorts(dynamicTaskFarmStage.getOutputPort(), collectorSink.getInputPort());
}
};
Execution<Configuration> execution = new Execution<Configuration>(configuration);
execution.executeNonBlocking();
producer.trigger();
assertThat(dynamicTaskFarmStage.getMerger().isActive(), is(false));
dynamicTaskFarmStage.addStageAtRuntime();
producer.trigger();
// assertThat(dynamicTaskFarmStage.getMerger().isActive(), is(true)); // TODO uncomment if "declareActive at runtime" is implemented
dynamicTaskFarmStage.removeStageAtRuntime();
producer.trigger();
// assertThat(dynamicTaskFarmStage.getMerger().isActive(), is(false)); // TODO uncomment if "declareActive at runtime" is implemented
execution.abortEventually();
}
use of teetime.stage.Counter 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));
}
}
use of teetime.stage.Counter in project TeeTime by teetime-framework.
the class StaticTaskFarmStageTest method testStaticTaskFarmStageWithSingleStage.
@Test
public void testStaticTaskFarmStageWithSingleStage() throws Exception {
ArrayCreator creator = new ArrayCreator(SEED);
List<Integer> randomNumbers = creator.createFilledList(1024);
TestTuple[] testInputTuples = { // tuple semantics: number of worker stages, input elements, and (expect) output elements
TestTuple.use(1, 1, 2).expect(1, 2), // expect in any order
TestTuple.use(1, randomNumbers).expect(randomNumbers) };
for (TestTuple testTuple : testInputTuples) {
StaticTaskFarmStage<Integer, Integer, Counter<Integer>> taskFarmStage = createTaskFarm(testTuple.numWorkerStages);
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));
}
}
use of teetime.stage.Counter in project TeeTime by teetime-framework.
the class ThreeStagesPushPullIT method shouldExecutePipelineCorrectlyManyElements.
private void shouldExecutePipelineCorrectlyManyElements(final int numElements, final int numThreads) {
List<Integer> processedElements = new ArrayList<>();
IntStream inputElements = IntStream.iterate(0, i -> i + 1).limit(numElements);
Configuration config = new Configuration().from(new StreamProducer<>(inputElements)).to(new Counter<>()).end(new CollectorSink<>(processedElements));
TeeTimeScheduler scheduling = new PushPullScheduling(config);
Execution<Configuration> execution = new Execution<>(config, true, scheduling);
execution.executeBlocking();
for (int i = 0; i < numElements; i++) {
Integer actualElement = processedElements.get(i);
assertThat(actualElement, is(i));
}
assertThat(processedElements, hasSize(numElements));
}
Aggregations