Search in sources :

Example 21 with DummyJob

use of com.path.android.jobqueue.test.jobs.DummyJob 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)

Example 22 with DummyJob

use of com.path.android.jobqueue.test.jobs.DummyJob in project android-priority-jobqueue by path.

the class JobParamsTest method assertParamsUnderstood.

@Test
public void assertParamsUnderstood() {
    DummyJob j1 = new DummyJob(new Params(1).requireNetwork());
    assertThat("require network param should be understood properly", j1.requiresNetwork(), equalTo(true));
    DummyJob j2 = new DummyJob(new Params(1).groupBy("blah"));
    assertThat("group param should be understood properly", j2.getRunGroupId(), equalTo("blah"));
    DummyJob j3 = new DummyJob(new Params(1).persist());
    assertThat("group param should be understood properly", j3.isPersistent(), equalTo(true));
    DummyJob j4 = new DummyJob(new Params(1).setPersistent(false).setRequiresNetwork(false).setGroupId(null));
    assertThat("persist param should be understood properly", j4.isPersistent(), equalTo(false));
    assertThat("require network param should be understood properly", j4.requiresNetwork(), equalTo(false));
    assertThat("group param should be understood properly", j4.getRunGroupId(), nullValue());
}
Also used : DummyJob(com.path.android.jobqueue.test.jobs.DummyJob) Params(com.path.android.jobqueue.Params) Test(org.junit.Test)

Aggregations

Params (com.path.android.jobqueue.Params)22 DummyJob (com.path.android.jobqueue.test.jobs.DummyJob)22 Test (org.junit.Test)19 JobManager (com.path.android.jobqueue.JobManager)18 JobHolder (com.path.android.jobqueue.JobHolder)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 Configuration (com.path.android.jobqueue.config.Configuration)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BaseJob (com.path.android.jobqueue.BaseJob)3 Job (com.path.android.jobqueue.Job)3 ArrayList (java.util.ArrayList)3 JobQueue (com.path.android.jobqueue.JobQueue)2 DependencyInjector (com.path.android.jobqueue.di.DependencyInjector)2 CustomLogger (com.path.android.jobqueue.log.CustomLogger)2 Semaphore (java.util.concurrent.Semaphore)2 AsyncAddCallback (com.path.android.jobqueue.AsyncAddCallback)1 JobStatus (com.path.android.jobqueue.JobStatus)1 JobConsumerExecutor (com.path.android.jobqueue.executor.JobConsumerExecutor)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1