Search in sources :

Example 1 with CancelReason

use of com.birbit.android.jobqueue.CancelReason in project android-priority-jobqueue by yigit.

the class HitDeadlineAfterException method failAndHitDeadline.

@Test
public void failAndHitDeadline() throws InterruptedException {
    final JobManager jobManager = createJobManager();
    final AtomicBoolean calledShouldReRun = new AtomicBoolean(false);
    final AtomicInteger reason = new AtomicInteger();
    final DummyJob job = new DummyJob(new Params(0).overrideDeadlineToCancelInMs(100)) {

        @Override
        public void onRun() throws Throwable {
            super.onRun();
            mockTimer.incrementMs(150);
            throw new RuntimeException("why not fail");
        }

        @Override
        protected void onCancel(@CancelReason int cancelReason, @Nullable Throwable throwable) {
            reason.set(cancelReason);
            super.onCancel(cancelReason, throwable);
        }

        @Override
        protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, int maxRunCount) {
            calledShouldReRun.set(true);
            return RetryConstraint.RETRY;
        }
    };
    waitUntilAJobIsDone(jobManager, new WaitUntilCallback() {

        @Override
        public void run() {
            jobManager.addJob(job);
        }

        @Override
        public void assertJob(Job job) {
        }
    });
    MatcherAssert.assertThat(reason.get(), CoreMatchers.is(CancelReason.REACHED_DEADLINE));
    MatcherAssert.assertThat(calledShouldReRun.get(), CoreMatchers.is(false));
}
Also used : Params(com.birbit.android.jobqueue.Params) JobManager(com.birbit.android.jobqueue.JobManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CancelReason(com.birbit.android.jobqueue.CancelReason) DummyJob(com.birbit.android.jobqueue.test.jobs.DummyJob) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NonNull(android.support.annotation.NonNull) DummyJob(com.birbit.android.jobqueue.test.jobs.DummyJob) Job(com.birbit.android.jobqueue.Job) Nullable(android.support.annotation.Nullable) Test(org.junit.Test)

Aggregations

NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 CancelReason (com.birbit.android.jobqueue.CancelReason)1 Job (com.birbit.android.jobqueue.Job)1 JobManager (com.birbit.android.jobqueue.JobManager)1 Params (com.birbit.android.jobqueue.Params)1 DummyJob (com.birbit.android.jobqueue.test.jobs.DummyJob)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1