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()));
}
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));
}
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));
}
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()));
}
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;
}
Aggregations