use of com.birbit.android.jobqueue.TestConstraint in project android-priority-jobqueue by yigit.
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(mockTimer.nanoTime() - 1000);
JobHolder delayedPriority_2 = createNewJobHolder(new Params(2));
delayUntilField = getDelayUntilNsField(delayedPriority_2);
delayUntilField.set(mockTimer.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);
TestConstraint constraint = new TestConstraint(mockTimer);
int lastPriority = Integer.MAX_VALUE;
for (int i = 0; i < 5; i++) {
JobHolder next = jobQueue.nextJobAndIncRunCount(constraint);
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.birbit.android.jobqueue.TestConstraint 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.TestConstraint 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.TestConstraint 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.TestConstraint 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