Search in sources :

Example 11 with AbstractStage

use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.

the class PrioritizedTaskPoolTest method insertTwice.

@Test
public void insertTwice() throws Exception {
    boolean scheduled = threadPool.scheduleStage(producer);
    assertThat(scheduled, is(true));
    scheduled = threadPool.scheduleStage(producer);
    assertThat(scheduled, is(true));
    AbstractStage nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(producer));
    nextStage = threadPool.removeNextStage();
    // assertThat(nextStage, is(producer));
    assertThat(nextStage, is(nullValue()));
}
Also used : AbstractStage(teetime.framework.AbstractStage) Test(org.junit.Test)

Example 12 with AbstractStage

use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.

the class PrioritizedTaskPoolTest method removeInCorrectOrderWhileAddingInBetween.

@Test
public void removeInCorrectOrderWhileAddingInBetween() throws Exception {
    // add to pool in an arbitrary order
    threadPool.scheduleStage(counter3);
    threadPool.scheduleStage(producer);
    threadPool.scheduleStage(counter2);
    threadPool.scheduleStage(counter4);
    threadPool.scheduleStage(counter1);
    // remove from the pool in a sorted order
    AbstractStage nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(counter4));
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(counter3));
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(counter2));
    threadPool.scheduleStage(counter4);
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(counter4));
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(counter1));
    threadPool.scheduleStage(counter3);
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(counter3));
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(producer));
}
Also used : AbstractStage(teetime.framework.AbstractStage) Test(org.junit.Test)

Example 13 with AbstractStage

use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.

the class PrioritizedTaskPoolTest method nextStageIsShallowStageLevel.

@Test
public void nextStageIsShallowStageLevel() throws Exception {
    boolean scheduled = threadPool.scheduleStage(producer);
    assertThat(scheduled, is(true));
    AbstractStage nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(producer));
}
Also used : AbstractStage(teetime.framework.AbstractStage) Test(org.junit.Test)

Example 14 with AbstractStage

use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.

the class PrioritizedTaskPoolTest method removeTooOften.

@Test
public void removeTooOften() throws Exception {
    boolean scheduled = threadPool.scheduleStage(producer);
    assertThat(scheduled, is(true));
    AbstractStage nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(producer));
    nextStage = threadPool.removeNextStage();
    assertThat(nextStage, is(nullValue()));
}
Also used : AbstractStage(teetime.framework.AbstractStage) Test(org.junit.Test)

Example 15 with AbstractStage

use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.

the class PrioritizedTaskPool method removeNextStage.

public AbstractStage removeNextStage(final int deepestStartLevel) {
    // corresponding ticket: https://build.se.informatik.uni-kiel.de/teetime/teetime/issues/343
    for (int i = deepestStartLevel; i >= 0; i--) {
        Queue<AbstractStage> stages = levels.get(i);
        AbstractStage stage = stages.poll();
        // (only) read next stage with work
        if (null != stage) {
            // TODO possible alternative implementation: AbstractStage.getExecutingThread().compareAndSet()
            // ensure no other thread is executing the stage at this moment (this is our lock condition)
            // boolean notAlreadyContained = executingStages.add(stage);
            // if (/* stage.isStateless() || */ notAlreadyContained) {
            // return stages.poll(); // NOPMD (two returns in method)
            // }
            // AtomicInteger numSchedules = numSchedulesByStage.get(stage);
            // numSchedules.decrementAndGet();
            // the stage cannot be re-added to this pool until the following call 'remove' has finished
            addedStages.remove(stage);
            return stage;
        }
    }
    return null;
}
Also used : AbstractStage(teetime.framework.AbstractStage)

Aggregations

AbstractStage (teetime.framework.AbstractStage)23 Test (org.junit.Test)9 Traverser (teetime.framework.Traverser)3 StateChange (teetime.framework.performancelogging.StateChange)3 ObjectIntHashMap (com.carrotsearch.hppc.ObjectIntHashMap)1 Logger (org.slf4j.Logger)1 InstantiationPipe (teetime.framework.InstantiationPipe)1 TestConfiguration (teetime.framework.TestConfiguration)1 StageActivationState (teetime.framework.performancelogging.StateChange.StageActivationState)1 CollectorSink (teetime.stage.CollectorSink)1 InitialElementProducer (teetime.stage.InitialElementProducer)1 CreatePortActionDistributor (teetime.stage.basic.distributor.dynamic.CreatePortActionDistributor)1 CreatePortActionMerger (teetime.stage.basic.merger.dynamic.CreatePortActionMerger)1