use of com.birbit.android.jobqueue.Params in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirementAndRegularDelayedJob4.
@Test
public void testDelayUntilWithUnmeteredNetworkRequirementAndRegularDelayedJob4() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(500).requireUnmeteredNetwork());
JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(1000));
jobQueue.insert(holder2);
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.METERED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(500000000L));
}
use of com.birbit.android.jobqueue.Params in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntil.
@Test
public void testDelayUntil() throws Exception {
JobQueue jobQueue = createNewJobQueue();
long now = mockTimer.nanoTime();
JobHolder networkJobHolder = createNewJobHolderWithDelayUntil(new Params(0).requireNetwork(), now + 2);
JobHolder noNetworkJobHolder = createNewJobHolderWithDelayUntil(new Params(0), now + 5);
jobQueue.insert(networkJobHolder);
jobQueue.insert(noNetworkJobHolder);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat("if there is no network, delay until should be provided for no network job", jobQueue.getNextJobDelayUntilNs(constraint), equalTo(noNetworkJobHolder.getDelayUntilNs()));
constraint.clear();
constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
assertThat("if there is network, delay until should be provided for network job because it is " + "sooner", jobQueue.getNextJobDelayUntilNs(constraint), equalTo(networkJobHolder.getDelayUntilNs()));
JobHolder noNetworkJobHolder2 = createNewJobHolderWithDelayUntil(new Params(0), now + 1);
jobQueue.insert(noNetworkJobHolder2);
assertThat("if there is network, any job's delay until should be returned", jobQueue.getNextJobDelayUntilNs(constraint), equalTo(noNetworkJobHolder2.getDelayUntilNs()));
}
use of com.birbit.android.jobqueue.Params in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirementAndRegularDelayedJob3.
@Test
public void testDelayUntilWithNetworkRequirementAndRegularDelayedJob3() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(500).requireNetwork());
JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(1000));
jobQueue.insert(holder1);
jobQueue.insert(holder2);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(500000000L));
}
use of com.birbit.android.jobqueue.Params in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirement.
@Test
public void testDelayUntilWithNetworkRequirement() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).requireNetwork().overrideDeadlineToRunInMs(1000));
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
}
use of com.birbit.android.jobqueue.Params in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDeadlineDoesNotAffectExcludeRunning.
@Test
public void testDeadlineDoesNotAffectExcludeRunning() {
JobQueue jobQueue = createNewJobQueue();
JobHolder jobHolder = createNewJobHolder(new Params(0).overrideDeadlineToRunInMs(10));
jobQueue.insert(jobHolder);
TestConstraint testConstraint = new TestConstraint(mockTimer);
assertThat(jobQueue.nextJobAndIncRunCount(testConstraint).getId(), is(jobHolder.getId()));
mockTimer.incrementMs(100);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setExcludeRunning(true);
assertThat(jobQueue.findJobs(constraint), is(Collections.EMPTY_SET));
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(nullValue()));
}
Aggregations