use of com.birbit.android.jobqueue.JobHolder 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));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testFindByMultipleTags.
@Test
public void testFindByMultipleTags() {
JobQueue jobQueue = createNewJobQueue();
final String tag1 = UUID.randomUUID().toString();
String tag2 = UUID.randomUUID().toString();
while (tag2.equals(tag1)) {
tag2 = UUID.randomUUID().toString();
}
JobHolder holder = createNewJobHolder(new Params(0).addTags(tag1, tag2));
jobQueue.insert(holder);
assertTags("job with two tags", jobQueue, holder);
jobQueue.insertOrReplace(holder);
assertTags("job with two tags, 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));
assertThat("when job is removed, it should return none", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag2)).size(), is(0));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testJobFields.
@Test
public void testJobFields() throws Exception {
long sessionId = (long) (Math.random() * 1000);
JobQueue jobQueue = createNewJobQueueWithSessionId(sessionId);
int priority = (int) (Math.random() * 1000);
JobHolder jobHolder = createNewJobHolder(new Params(priority));
int runCount = (int) (Math.random() * 10);
jobHolder.setRunCount(runCount);
jobQueue.insert(jobHolder);
for (int i = 0; i < 2; i++) {
JobHolder received = jobQueue.nextJobAndIncRunCount(new TestConstraint(mockTimer));
assertThat("job id should be preserved", received.getId(), equalTo(jobHolder.getId()));
assertThat("job priority should be preserved", received.getPriority(), equalTo(priority));
assertThat("job session id should be assigned", received.getRunningSessionId(), equalTo(sessionId));
assertThat("job run count should be incremented", received.getRunCount(), equalTo(runCount + i + 1));
jobQueue.insertOrReplace(received);
}
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirement.
@Test
public void testDelayUntilWithUnmeteredNetworkRequirement() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(1000).requireUnmeteredNetwork());
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
constraint.setMaxNetworkType(NetworkUtil.METERED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirement5.
@Test
public void testDelayUntilWithUnmeteredNetworkRequirement5() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(2000).requireUnmeteredNetwork().delayInMs(1000));
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
}
Aggregations