Search in sources :

Example 1 with CollectorSink

use of teetime.stage.CollectorSink in project TeeTime by teetime-framework.

the class ProducerConsumerGlobalTaskPoolIT method shouldExecuteProducerConsumer.

private void shouldExecuteProducerConsumer(final int numThreads, final int numExecutions) {
    int numElements = 10_000;
    List<Integer> processedElements = new ArrayList<>();
    IntStream inputElements = IntStream.iterate(0, i -> i + 1).limit(numElements);
    Configuration config = new Configuration().from(new StreamProducer<>(inputElements)).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++) {
        assertThat(processedElements.get(i), is(i));
    }
    assertThat(processedElements, hasSize(numElements));
}
Also used : IntStream(java.util.stream.IntStream) Configuration(teetime.framework.Configuration) StreamProducer(teetime.stage.StreamProducer) List(java.util.List) CollectorSink(teetime.stage.CollectorSink) Execution(teetime.framework.Execution) GlobalTaskPoolScheduling(teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) Assert(org.junit.Assert) ArrayList(java.util.ArrayList) Configuration(teetime.framework.Configuration) ArrayList(java.util.ArrayList) StreamProducer(teetime.stage.StreamProducer) Execution(teetime.framework.Execution) GlobalTaskPoolScheduling(teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) IntStream(java.util.stream.IntStream)

Example 2 with CollectorSink

use of teetime.stage.CollectorSink 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));
}
Also used : IntStream(java.util.stream.IntStream) MethodSorters(org.junit.runners.MethodSorters) StreamProducer(teetime.stage.StreamProducer) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) ArrayList(java.util.ArrayList) Configuration(teetime.framework.Configuration) List(java.util.List) CollectorSink(teetime.stage.CollectorSink) Execution(teetime.framework.Execution) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Counter(teetime.stage.Counter) Configuration(teetime.framework.Configuration) ArrayList(java.util.ArrayList) Counter(teetime.stage.Counter) Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) IntStream(java.util.stream.IntStream)

Example 3 with CollectorSink

use of teetime.stage.CollectorSink in project TeeTime by teetime-framework.

the class StageFactory method getSinkFromOutputPort.

@SuppressWarnings("unchecked")
static <T> CollectorSink<T> getSinkFromOutputPort(final OutputPort<T> outputPort) {
    InputPort<?> targetPort = outputPort.getPipe().getTargetPort();
    AbstractStage owningStage = targetPort.getOwningStage();
    if (owningStage instanceof CollectorSink) {
        return (CollectorSink<T>) owningStage;
    }
    String message = String.format("%s", owningStage);
    throw new IllegalArgumentException(message);
}
Also used : CollectorSink(teetime.stage.CollectorSink) AbstractStage(teetime.framework.AbstractStage)

Example 4 with CollectorSink

use of teetime.stage.CollectorSink 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));
}
Also used : IntStream(java.util.stream.IntStream) MethodSorters(org.junit.runners.MethodSorters) StreamProducer(teetime.stage.StreamProducer) PushPullScheduling(teetime.framework.scheduling.pushpullmodel.PushPullScheduling) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) ArrayList(java.util.ArrayList) Configuration(teetime.framework.Configuration) List(java.util.List) CollectorSink(teetime.stage.CollectorSink) Execution(teetime.framework.Execution) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Counter(teetime.stage.Counter) Configuration(teetime.framework.Configuration) ArrayList(java.util.ArrayList) PushPullScheduling(teetime.framework.scheduling.pushpullmodel.PushPullScheduling) Counter(teetime.stage.Counter) Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) IntStream(java.util.stream.IntStream)

Example 5 with CollectorSink

use of teetime.stage.CollectorSink 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();
}
Also used : Configuration(teetime.framework.Configuration) CollectorSink(teetime.stage.CollectorSink) Counter(teetime.stage.Counter) Execution(teetime.framework.Execution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CollectorSink (teetime.stage.CollectorSink)5 Test (org.junit.Test)4 Configuration (teetime.framework.Configuration)4 Execution (teetime.framework.Execution)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IntStream (java.util.stream.IntStream)3 Matchers (org.hamcrest.Matchers)3 Assert (org.junit.Assert)3 TeeTimeScheduler (teetime.framework.TeeTimeScheduler)3 Counter (teetime.stage.Counter)3 StreamProducer (teetime.stage.StreamProducer)3 FixMethodOrder (org.junit.FixMethodOrder)2 MethodSorters (org.junit.runners.MethodSorters)2 Ignore (org.junit.Ignore)1 AbstractStage (teetime.framework.AbstractStage)1 GlobalTaskPoolScheduling (teetime.framework.scheduling.globaltaskpool.GlobalTaskPoolScheduling)1 PushPullScheduling (teetime.framework.scheduling.pushpullmodel.PushPullScheduling)1