use of com.path.android.jobqueue.JobQueue in project android-priority-jobqueue by path.
the class JobQueueTestBase method testDelayUntilWithPriority.
@Test
public void testDelayUntilWithPriority() throws Exception {
JobQueue jobQueue = createNewJobQueue();
long now = System.nanoTime();
JobHolder lowPriorityHolder = createNewJobHolderWithDelayUntil(new Params(5), now + 10000 * JobManager.NS_PER_MS);
JobHolder highPriorityHolder = createNewJobHolderWithDelayUntil(new Params(10), now + 20000 * JobManager.NS_PER_MS);
jobQueue.insert(lowPriorityHolder);
jobQueue.insert(highPriorityHolder);
assertThat("when asked, if lower priority job has less delay until, we should return it", jobQueue.getNextJobDelayUntilNs(true), equalTo(lowPriorityHolder.getDelayUntilNs()));
}
use of com.path.android.jobqueue.JobQueue in project android-priority-jobqueue by path.
the class JobQueueTestBase method testRemove.
@Test
public void testRemove() throws Exception {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder = createNewJobHolder();
jobQueue.insert(holder);
Long jobId = holder.getId();
assertThat(jobQueue.nextJobAndIncRunCount(true, null).getId(), equalTo(jobId));
assertThat(jobQueue.nextJobAndIncRunCount(true, null), is(nullValue()));
jobQueue.remove(holder);
assertThat(jobQueue.nextJobAndIncRunCount(true, null), is(nullValue()));
}
use of com.path.android.jobqueue.JobQueue in project android-priority-jobqueue by path.
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(System.nanoTime() - 1000);
JobHolder delayedPriority_2 = createNewJobHolder(new Params(2));
delayUntilField = getDelayUntilNsField(delayedPriority_2);
delayUntilField.set(System.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);
int lastPriority = Integer.MAX_VALUE;
for (int i = 0; i < 5; i++) {
JobHolder next = jobQueue.nextJobAndIncRunCount(true, null);
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.path.android.jobqueue.JobQueue in project android-priority-jobqueue by path.
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(true, null);
assertThat("session id should be attached to next job", jobHolder.getRunningSessionId(), equalTo(sessionId));
}
use of com.path.android.jobqueue.JobQueue in project android-priority-jobqueue by path.
the class JobQueueTestBase method testDelayUntil.
@Test
public void testDelayUntil() throws Exception {
JobQueue jobQueue = createNewJobQueue();
long now = System.nanoTime();
JobHolder networkJobHolder = createNewJobHolderWithDelayUntil(new Params(0).requireNetwork(), now + 200000 * JobManager.NS_PER_MS);
JobHolder noNetworkJobHolder = createNewJobHolderWithDelayUntil(new Params(0), now + 500000 * JobManager.NS_PER_MS);
jobQueue.insert(networkJobHolder);
jobQueue.insert(noNetworkJobHolder);
assertThat("if there is no network, delay until should be provided for no network job", jobQueue.getNextJobDelayUntilNs(false), equalTo(noNetworkJobHolder.getDelayUntilNs()));
assertThat("if there is network, delay until should be provided for network job because it is " + "sooner", jobQueue.getNextJobDelayUntilNs(true), equalTo(networkJobHolder.getDelayUntilNs()));
JobHolder noNetworkJobHolder2 = createNewJobHolderWithDelayUntil(new Params(0), now + 100000 * JobManager.NS_PER_MS);
jobQueue.insert(noNetworkJobHolder2);
assertThat("if there is network, any job's delay until should be returned", jobQueue.getNextJobDelayUntilNs(true), equalTo(noNetworkJobHolder2.getDelayUntilNs()));
}
Aggregations