use of com.birbit.android.jobqueue.JobQueue in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirement3.
@Test
public void testDelayUntilWithNetworkRequirement3() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(2000).delayInMs(1000).requireNetwork());
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
}
use of com.birbit.android.jobqueue.JobQueue in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirement2.
@Test
public void testDelayUntilWithNetworkRequirement2() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(3000).delayInMs(2000).requireNetwork());
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(3000000000L));
}
use of com.birbit.android.jobqueue.JobQueue in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithPriority.
@Test
public void testDelayUntilWithPriority() throws Exception {
JobQueue jobQueue = createNewJobQueue();
JobHolder lowPriorityHolder = createNewJobHolderWithDelayUntil(new Params(5), 1);
JobHolder highPriorityHolder = createNewJobHolderWithDelayUntil(new Params(10), 2);
jobQueue.insert(lowPriorityHolder);
jobQueue.insert(highPriorityHolder);
assertThat("when asked, if lower priority job has less delay until, we should return it", jobQueue.getNextJobDelayUntilNs(new TestConstraint(mockTimer)), equalTo(lowPriorityHolder.getDelayUntilNs()));
}
use of com.birbit.android.jobqueue.JobQueue in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testPriorityWithDelayedJobs.
@Test
public void testPriorityWithDelayedJobs() throws Exception {
JobQueue jobQueue = createNewJobQueue();
JobHolder delayedPriority_5 = createNewJobHolder(new Params(5));
org.fest.reflect.field.Invoker<Long> delayUntilField = getDelayUntilNsField(delayedPriority_5);
delayUntilField.set(mockTimer.nanoTime() - 1000);
JobHolder delayedPriority_2 = createNewJobHolder(new Params(2));
delayUntilField = getDelayUntilNsField(delayedPriority_2);
delayUntilField.set(mockTimer.nanoTime() - 500);
JobHolder nonDelayedPriority_6 = createNewJobHolder(new Params(6));
JobHolder nonDelayedPriority_3 = createNewJobHolder(new Params(3));
JobHolder nonDelayedPriority_2 = createNewJobHolder(new Params(2));
jobQueue.insert(delayedPriority_5);
jobQueue.insert(delayedPriority_2);
jobQueue.insert(nonDelayedPriority_6);
jobQueue.insert(nonDelayedPriority_2);
jobQueue.insert(nonDelayedPriority_3);
TestConstraint constraint = new TestConstraint(mockTimer);
int lastPriority = Integer.MAX_VALUE;
for (int i = 0; i < 5; i++) {
JobHolder next = jobQueue.nextJobAndIncRunCount(constraint);
assertThat("next job should not be null", next, notNullValue());
assertThat("next job's priority should be lower then previous for job " + i, next.getPriority() <= lastPriority, is(true));
lastPriority = next.getPriority();
}
}
use of com.birbit.android.jobqueue.JobQueue in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirementAndRegularDelayedJob2.
@Test
public void testDelayUntilWithNetworkRequirementAndRegularDelayedJob2() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(1000).requireUnmeteredNetwork());
JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(500));
jobQueue.insert(holder2);
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.METERED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(500000000L));
}
Aggregations