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));
}
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));
}
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);
}
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);
}
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));
}
Aggregations