Search in sources :

Example 1 with JobManager

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

the class InjectorTest method testInjector.

@Test
public void testInjector() throws Exception {
    Configuration.Builder builder = new Configuration.Builder(Robolectric.application);
    final JobManagerTestBase.ObjectReference injectedJobReference = new JobManagerTestBase.ObjectReference();
    final AtomicInteger injectionCallCount = new AtomicInteger(0);
    DependencyInjector dependencyInjector = new DependencyInjector() {

        @Override
        public void inject(BaseJob job) {
            injectedJobReference.setObject(job);
            injectionCallCount.incrementAndGet();
        }
    };
    builder.injector(dependencyInjector);
    JobManager jobManager = createJobManager(builder);
    jobManager.stop();
    jobManager.addJob(new DummyJob(new Params(4)));
    MatcherAssert.assertThat("injection should be called after adding a non-persistent job", injectionCallCount.get(), equalTo(1));
    jobManager.addJob(new DummyJob(new Params(1).persist()));
    MatcherAssert.assertThat("injection should be called after adding a persistent job", injectionCallCount.get(), equalTo(2));
    JobHolder holder = getNextJobMethod(jobManager).invoke();
    MatcherAssert.assertThat("injection should NOT be called for non persistent job", holder.getBaseJob(), not(injectedJobReference.getObject()));
    MatcherAssert.assertThat("injection should be called once for non persistent job", injectionCallCount.get(), equalTo(2));
    holder = getNextJobMethod(jobManager).invoke();
    MatcherAssert.assertThat("injection should be called for persistent job", holder.getBaseJob(), equalTo(injectedJobReference.getObject()));
    MatcherAssert.assertThat("injection should be called two times for persistent job", injectionCallCount.get(), equalTo(3));
}
Also used : DependencyInjector(com.path.android.jobqueue.di.DependencyInjector) Configuration(com.path.android.jobqueue.config.Configuration) BaseJob(com.path.android.jobqueue.BaseJob) Params(com.path.android.jobqueue.Params) JobManager(com.path.android.jobqueue.JobManager) JobHolder(com.path.android.jobqueue.JobHolder) DummyJob(com.path.android.jobqueue.test.jobs.DummyJob) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with JobManager

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

the class PersistentJobTest method testPersistentJob.

@Test
public void testPersistentJob() throws Exception {
    JobManager jobManager = createJobManager();
    jobManager.addJob(0, new DummyPersistentLatchJob());
    persistentRunLatch.await(5, TimeUnit.SECONDS);
    MatcherAssert.assertThat((int) persistentRunLatch.getCount(), equalTo(0));
}
Also used : JobManager(com.path.android.jobqueue.JobManager) Test(org.junit.Test)

Example 3 with JobManager

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

the class PriorityTest method testPriority.

@Test
public void testPriority() throws Exception {
    JobManager jobManager = createJobManager(new Configuration.Builder(Robolectric.application).maxConsumerCount(1));
    testPriority(jobManager, false);
}
Also used : JobManager(com.path.android.jobqueue.JobManager) Test(org.junit.Test)

Example 4 with JobManager

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

the class ReRunWithLimitTest method testReRunWithLimit.

@Test
public void testReRunWithLimit() throws Exception {
    JobManager jobManager = createJobManager();
    testReRun(jobManager, false);
    testReRun(jobManager, true);
}
Also used : JobManager(com.path.android.jobqueue.JobManager) Test(org.junit.Test)

Example 5 with JobManager

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

the class RunFailingJobTest method runFailingJob.

@Test
public void runFailingJob() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    JobManager jobManager = createJobManager();
    jobManager.addJob(0, new BaseJob(true) {

        @Override
        public void onAdded() {
        }

        @Override
        public void onRun() throws Throwable {
            throw new RuntimeException();
        }

        @Override
        protected void onCancel() {
            latch.countDown();
        }

        @Override
        protected boolean shouldReRunOnThrowable(Throwable throwable) {
            return false;
        }
    });
    latch.await(10, TimeUnit.SECONDS);
    MatcherAssert.assertThat((int) latch.getCount(), equalTo(0));
}
Also used : BaseJob(com.path.android.jobqueue.BaseJob) JobManager(com.path.android.jobqueue.JobManager) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

JobManager (com.path.android.jobqueue.JobManager)27 Test (org.junit.Test)21 Params (com.path.android.jobqueue.Params)20 DummyJob (com.path.android.jobqueue.test.jobs.DummyJob)18 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobHolder (com.path.android.jobqueue.JobHolder)6 Configuration (com.path.android.jobqueue.config.Configuration)6 BaseJob (com.path.android.jobqueue.BaseJob)4 Job (com.path.android.jobqueue.Job)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DependencyInjector (com.path.android.jobqueue.di.DependencyInjector)2 CustomLogger (com.path.android.jobqueue.log.CustomLogger)2 ArrayList (java.util.ArrayList)2 DaggerTestComponent (com.android.example.devsummit.archdemo.di.component.DaggerTestComponent)1 TestComponent (com.android.example.devsummit.archdemo.di.component.TestComponent)1 ApplicationModule (com.android.example.devsummit.archdemo.di.module.ApplicationModule)1 TestApplicationModule (com.android.example.devsummit.archdemo.di.module.TestApplicationModule)1 LoggingBus (com.android.example.devsummit.archdemo.event.LoggingBus)1 AsyncAddCallback (com.path.android.jobqueue.AsyncAddCallback)1 JobQueue (com.path.android.jobqueue.JobQueue)1