use of com.birbit.android.jobqueue.TestConstraint 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()));
}
use of com.birbit.android.jobqueue.TestConstraint in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDeadlineDoesNotAffectExcludeGroupQuery.
@Test
public void testDeadlineDoesNotAffectExcludeGroupQuery() {
JobQueue jobQueue = createNewJobQueue();
JobHolder jobHolder = createNewJobHolder(new Params(0).groupBy("g1").overrideDeadlineToRunInMs(10));
jobQueue.insert(jobHolder);
mockTimer.incrementMs(100);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setExcludeGroups(Arrays.asList("g1"));
assertThat(jobQueue.findJobs(constraint), is(Collections.EMPTY_SET));
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(nullValue()));
}
use of com.birbit.android.jobqueue.TestConstraint in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithRunningJobs.
@Test
public void testDelayUntilWithRunningJobs() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder = createNewJobHolder();
jobQueue.insert(holder);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.METERED);
constraint.setExcludeRunning(true);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(JobManager.NOT_DELAYED_JOB_DELAY));
JobHolder nextJob = jobQueue.nextJobAndIncRunCount(constraint);
assertThat(nextJob, is(notNullValue()));
assertThat(nextJob.getId(), is(holder.getId()));
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(nullValue()));
}
use of com.birbit.android.jobqueue.TestConstraint in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDeadline.
private void testDeadline(boolean cancel) throws Exception {
JobQueue jobQueue = createNewJobQueue();
Params params = new Params(0).requireNetwork();
if (cancel) {
params.overrideDeadlineToCancelInMs(100);
} else {
params.overrideDeadlineToRunInMs(100);
}
JobHolder requireNetwork = createNewJobHolder(params);
jobQueue.insert(requireNetwork);
TestConstraint testConstraint = new TestConstraint(mockTimer);
testConstraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat("when a job w/ a deadline is given, it should not be returned if not ready", jobQueue.nextJobAndIncRunCount(testConstraint), is(nullValue()));
assertThat("when a job w/ a deadline is given, it should show up in next job ready query", jobQueue.getNextJobDelayUntilNs(testConstraint), is(100 * JobManager.NS_PER_MS));
mockTimer.incrementMs(100);
JobHolder nextJob = jobQueue.nextJobAndIncRunCount(testConstraint);
assertThat("when a job reaches deadline, it should be returned", nextJob, is(notNullValue()));
assertThat("when a job reaches deadline, it should be returned", nextJob.getId(), is(requireNetwork.getId()));
assertThat(nextJob.shouldCancelOnDeadline(), is(cancel));
}
use of com.birbit.android.jobqueue.TestConstraint in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testNoDeadline.
@Test
public void testNoDeadline() throws Exception {
JobQueue jobQueue = createNewJobQueue();
JobHolder requireNetwork = createNewJobHolder(new Params(0).requireNetwork());
jobQueue.insert(requireNetwork);
TestConstraint testConstraint = new TestConstraint(mockTimer);
testConstraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat("when a job w/o a deadline is given, it should not be returned if not ready", jobQueue.nextJobAndIncRunCount(testConstraint), is(nullValue()));
assertThat("when a job w/o a deadline is given, it should not be returned in next ready", jobQueue.getNextJobDelayUntilNs(testConstraint), is(nullValue()));
}
Aggregations