Search in sources :

Example 26 with JobHolder

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

the class JobQueueTestBase method createNewJobHolderWithDelayUntil.

private JobHolder createNewJobHolderWithDelayUntil(Params params, long delayUntil) {
    JobHolder jobHolder = createNewJobHolder(params);
    getDelayUntilNsField(jobHolder).set(delayUntil);
    return jobHolder;
}
Also used : JobHolder(com.path.android.jobqueue.JobHolder)

Example 27 with JobHolder

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

the class GroupingTest method testGrouping.

@Test
public void testGrouping() throws Exception {
    JobManager jobManager = createJobManager();
    jobManager.stop();
    Invoker<JobHolder> nextJobMethod = getNextJobMethod(jobManager);
    Invoker<Void> removeJobMethod = getRemoveJobMethod(jobManager);
    long jobId1 = jobManager.addJob(new DummyJob(new Params(0).groupBy("group1")));
    long jobId2 = jobManager.addJob(new DummyJob(new Params(0).groupBy("group1")));
    long jobId3 = jobManager.addJob(new DummyJob(new Params(0).persist().groupBy("group2")));
    long jobId4 = jobManager.addJob(new DummyJob(new Params(0).persist().groupBy("group1")));
    JobHolder nextJob = nextJobMethod.invoke();
    MatcherAssert.assertThat("next job should be the first job from group1", nextJob.getId(), equalTo(jobId1));
    JobHolder group2Job = nextJobMethod.invoke();
    MatcherAssert.assertThat("since group 1 is running now, next job should be from group 2", group2Job.getId(), equalTo(jobId3));
    removeJobMethod.invoke(nextJob);
    JobHolder group1NextJob = nextJobMethod.invoke();
    MatcherAssert.assertThat("after removing job from group 1, another job from group1 should be returned", group1NextJob.getId(), equalTo(jobId2));
    MatcherAssert.assertThat("when jobs from both groups are running, no job should be returned from next job", nextJobMethod.invoke(), is(nullValue()));
    removeJobMethod.invoke(group2Job);
    MatcherAssert.assertThat("even after group2 job is complete, no jobs should be returned since we only have group1 jobs left", nextJobMethod.invoke(), is(nullValue()));
}
Also used : JobHolder(com.path.android.jobqueue.JobHolder) DummyJob(com.path.android.jobqueue.test.jobs.DummyJob) Params(com.path.android.jobqueue.Params) JobManager(com.path.android.jobqueue.JobManager) Test(org.junit.Test)

Aggregations

JobHolder (com.path.android.jobqueue.JobHolder)27 Test (org.junit.Test)18 Params (com.path.android.jobqueue.Params)17 JobQueue (com.path.android.jobqueue.JobQueue)15 DummyJob (com.path.android.jobqueue.test.jobs.DummyJob)7 JobManager (com.path.android.jobqueue.JobManager)6 BaseJob (com.path.android.jobqueue.BaseJob)2 Job (com.path.android.jobqueue.Job)2 Cursor (android.database.Cursor)1 AsyncAddCallback (com.path.android.jobqueue.AsyncAddCallback)1 Configuration (com.path.android.jobqueue.config.Configuration)1 DependencyInjector (com.path.android.jobqueue.di.DependencyInjector)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1