Search in sources :

Example 36 with JobHolder

use of com.birbit.android.jobqueue.JobHolder 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()));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Test(org.junit.Test)

Example 37 with JobHolder

use of com.birbit.android.jobqueue.JobHolder 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));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params)

Example 38 with JobHolder

use of com.birbit.android.jobqueue.JobHolder 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()));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 39 with JobHolder

use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.

the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirement4.

@Test
public void testDelayUntilWithUnmeteredNetworkRequirement4() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(3000).requireUnmeteredNetwork().delayInMs(2000));
    jobQueue.insert(holder1);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(2000000000L));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 40 with JobHolder

use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.

the class JobQueueTestBase method testRemove.

@Test
public void testRemove() throws Exception {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder = createNewJobHolder();
    jobQueue.insert(holder);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setExcludeRunning(true);
    assertThat(jobQueue.nextJobAndIncRunCount(constraint).getId(), equalTo(holder.getId()));
    assertThat(jobQueue.nextJobAndIncRunCount(constraint), is(nullValue()));
    jobQueue.remove(holder);
    assertThat(jobQueue.nextJobAndIncRunCount(constraint), is(nullValue()));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Test(org.junit.Test)

Aggregations

JobHolder (com.birbit.android.jobqueue.JobHolder)62 Test (org.junit.Test)50 Params (com.birbit.android.jobqueue.Params)46 JobQueue (com.birbit.android.jobqueue.JobQueue)42 TestConstraint (com.birbit.android.jobqueue.TestConstraint)39 Constraint (com.birbit.android.jobqueue.Constraint)8 TagConstraint (com.birbit.android.jobqueue.TagConstraint)7 DummyJob (com.birbit.android.jobqueue.test.jobs.DummyJob)7 JobManager (com.birbit.android.jobqueue.JobManager)6 Job (com.birbit.android.jobqueue.Job)4 Cursor (android.database.Cursor)2 Consumer (com.birbit.android.jobqueue.ConsumerManager.Consumer)2 Configuration (com.birbit.android.jobqueue.config.Configuration)2 MessageFactory (com.birbit.android.jobqueue.messaging.MessageFactory)2 MessageQueueConsumer (com.birbit.android.jobqueue.messaging.MessageQueueConsumer)2 PriorityMessageQueue (com.birbit.android.jobqueue.messaging.PriorityMessageQueue)2 SafeMessageQueue (com.birbit.android.jobqueue.messaging.SafeMessageQueue)2 RunJobMessage (com.birbit.android.jobqueue.messaging.message.RunJobMessage)2 MockTimer (com.birbit.android.jobqueue.test.timer.MockTimer)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2