use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirementAndRegularDelayedJob.
@Test
public void testDelayUntilWithNetworkRequirementAndRegularDelayedJob() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(1000).requireNetwork());
JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(500));
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.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirement4.
@Test
public void testDelayUntilWithNetworkRequirement4() {
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.UNMETERED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(2000000000L));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testFindByTags.
@Test
public void testFindByTags() {
JobQueue jobQueue = createNewJobQueue();
assertThat("empty queue should return 0", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), "abc")).size(), is(0));
jobQueue.insert(createNewJobHolder());
Set<JobHolder> result = jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), "blah"));
assertThat("if job does not have a tag, it should return 0", result.size(), is(0));
final String tag1 = UUID.randomUUID().toString();
JobHolder holder = createNewJobHolder(new Params(0).addTags(tag1));
jobQueue.insert(holder);
assertTags("holder with 1 tag", jobQueue, holder);
jobQueue.insertOrReplace(holder);
assertTags("holder with 1 tag reinserted", jobQueue, holder);
jobQueue.remove(holder);
assertThat("when job is removed, it should return none", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag1)).size(), is(0));
JobHolder holder2 = createNewJobHolder(new Params(0).addTags(tag1));
jobQueue.insert(holder2);
assertThat("it should return the job", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag1)).size(), is(1));
jobQueue.onJobCancelled(holder2);
assertThat("when queried w/ exclude cancelled, it should not return the job", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag1)).size(), is(0));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testSessionId.
@Test
public void testSessionId() throws Exception {
long sessionId = (long) (Math.random() * 100000);
JobQueue jobQueue = createNewJobQueueWithSessionId(sessionId);
JobHolder jobHolder = createNewJobHolder();
jobQueue.insert(jobHolder);
jobHolder = jobQueue.nextJobAndIncRunCount(new TestConstraint(mockTimer));
assertThat("session id should be attached to next job", jobHolder.getRunningSessionId(), equalTo(sessionId));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirementAndRegularDelayedJob4.
@Test
public void testDelayUntilWithNetworkRequirementAndRegularDelayedJob4() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(500).requireNetwork());
JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(1000));
jobQueue.insert(holder2);
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(500000000L));
}
Aggregations