use of com.birbit.android.jobqueue.inMemoryQueue.SimpleInMemoryPriorityQueue in project android-priority-jobqueue by yigit.
the class LoadFactorTest method testGoIdleIfNextJobCannotBeRunNow.
@SuppressLint("SLEEP_IN_CODE")
@Test
public void testGoIdleIfNextJobCannotBeRunNow() throws InterruptedException {
// see: https://github.com/yigit/android-priority-jobqueue/issues/262
final AtomicInteger nextJobDelayCall = new AtomicInteger(1);
JobManager jobManager = createJobManager(new Configuration.Builder(RuntimeEnvironment.application).maxConsumerCount(3).minConsumerCount(1).loadFactor(3).queueFactory(new QueueFactory() {
@Override
public JobQueue createPersistentQueue(Configuration configuration, long sessionId) {
return new SqliteJobQueue(configuration, sessionId, new SqliteJobQueue.JavaSerializer());
}
@Override
public JobQueue createNonPersistent(Configuration configuration, long sessionId) {
return new SimpleInMemoryPriorityQueue(configuration, sessionId) {
@Override
public Long getNextJobDelayUntilNs(@NonNull Constraint constraint) {
nextJobDelayCall.incrementAndGet();
return super.getNextJobDelayUntilNs(constraint);
}
};
}
}).timer(mockTimer));
final DummyJobWithStartEndLatch job1 = new DummyJobWithStartEndLatch(new Params(1));
final DummyJobWithStartEndLatch job2 = new DummyJobWithStartEndLatch(new Params(1));
jobManager.addJob(job1);
jobManager.addJob(job2);
assertThat(startLatch.await(5, TimeUnit.MINUTES), is(true));
// give it some time to cool down, ugly but nothing to do
Thread.sleep(2000);
int startCount = nextJobDelayCall.get();
Thread.sleep(5000);
assertThat("JobManager should not query any more next jobs", nextJobDelayCall.get(), is(startCount));
waitUntilAJobIsDone(jobManager, new WaitUntilCallback() {
@Override
public void run() {
canEndLatch.countDown();
}
@Override
public void assertJob(Job job) {
}
});
}
Aggregations