use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class ThreadFactoryTest method testThreadFactory.
@Test
public void testThreadFactory() throws Throwable {
final JobManager jobManager = createJobManager(new Configuration.Builder(RuntimeEnvironment.application).timer(mockTimer).threadFactory(new ThreadFactory() {
@Override
public Thread newThread(@NonNull Runnable r) {
return new DummyThread(r);
}
}));
final Job job = new CheckWorkerJob();
waitUntilAJobIsDone(jobManager, new WaitUntilCallback() {
@Override
public void run() {
jobManager.addJob(job);
}
@Override
public void assertJob(Job job) {
}
});
if (error != null) {
throw error;
}
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class PersistentJobTest method testPersistentJob.
@Test
public void testPersistentJob() throws Exception {
JobManager jobManager = createJobManager();
jobManager.addJob(new DummyPersistentLatchJob());
persistentRunLatch.await(5, TimeUnit.SECONDS);
MatcherAssert.assertThat((int) persistentRunLatch.getCount(), equalTo(0));
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class ReRunWithLimitTest method testReRunWithLimitPersist.
@Test
public void testReRunWithLimitPersist() throws Exception {
JobManager jobManager = createJobManager();
testReRun(jobManager, true);
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class ReRunWithLimitTest method testReRunWithLimit.
@Test
public void testReRunWithLimit() throws Exception {
JobManager jobManager = createJobManager();
testReRun(jobManager, false);
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class RetryLogicTest method testChangeDelay.
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public void testChangeDelay(boolean persistent) throws InterruptedException {
canRun = true;
RetryJob job = new RetryJob(new Params(1).setPersistent(persistent));
job.retryLimit = 2;
retryProvider = new RetryProvider() {
@Override
public RetryConstraint build(Job job, Throwable throwable, int runCount, int maxRunCount) {
RetryConstraint constraint = new RetryConstraint(true);
constraint.setNewDelayInMs(2000L);
return constraint;
}
};
final List<Long> runTimes = new ArrayList<>();
onRunCallback = new Callback() {
@Override
public void on(Job job) {
runTimes.add(mockTimer.nanoTime());
}
};
final Throwable[] callbackError = new Throwable[1];
final CountDownLatch runLatch = new CountDownLatch(2);
final JobManager jobManager = createJobManager();
jobManager.addCallback(new JobManagerCallbackAdapter() {
@Override
public void onAfterJobRun(@NonNull Job job, int resultCode) {
try {
mockTimer.incrementMs(1999);
assertThat("no jobs should be ready", jobManager.countReadyJobs(), is(0));
mockTimer.incrementMs(2);
} catch (Throwable t) {
callbackError[0] = t;
} finally {
runLatch.countDown();
}
}
});
jobManager.addJob(job);
assertThat("on run callbacks should arrive", runLatch.await(100, TimeUnit.MINUTES), is(true));
assertThat("run callback should not have any errors", callbackError[0], nullValue());
assertThat("job should be canceled", cancelLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("should run 2 times", runCount, is(2));
long timeInBetween = TimeUnit.NANOSECONDS.toSeconds(runTimes.get(1) - runTimes.get(0));
assertThat("time between two runs should be at least 2 seconds. " + timeInBetween, 2 <= timeInBetween, is(true));
}
Aggregations