Search in sources :

Example 1 with RetryConstraint

use of com.path.android.jobqueue.RetryConstraint in project dev-summit-architecture-demo by yigit.

the class FetchFeedJobTest method testFailure500.

@Test
public void testFailure500() throws Throwable {
    FetchFeedJob job = new FetchFeedJob(BaseJob.BACKGROUND, null);
    when(mApiService.feed(0L)).thenReturn(createCall(500, new FeedResponse()));
    job.inject(getTestComponent());
    Throwable exception = safeRun(job);
    assertThat(exception, notNullValue());
    assertThat(exception, instanceOf(NetworkException.class));
    RetryConstraint retryConstraint = job.shouldReRunOnThrowable(exception, 1, 10);
    assertThat(retryConstraint.shouldRetry(), is(true));
}
Also used : RetryConstraint(com.path.android.jobqueue.RetryConstraint) FeedResponse(com.android.example.devsummit.archdemo.api.FeedResponse) NetworkException(com.android.example.devsummit.archdemo.job.NetworkException) BaseTest(com.android.example.devsummit.archdemo.BaseTest) Test(org.junit.Test)

Example 2 with RetryConstraint

use of com.path.android.jobqueue.RetryConstraint in project dev-summit-architecture-demo by yigit.

the class SaveNewPostJob method shouldReRunOnThrowable.

@Override
protected RetryConstraint shouldReRunOnThrowable(Throwable throwable, int runCount, int maxRunCount) {
    if (shouldRetry(throwable)) {
        // For the purposes of the demo, just back off 250 ms.
        RetryConstraint constraint = RetryConstraint.createExponentialBackoff(runCount, 250);
        constraint.setApplyNewDelayToGroup(true);
        return constraint;
    }
    return RetryConstraint.CANCEL;
}
Also used : RetryConstraint(com.path.android.jobqueue.RetryConstraint)

Example 3 with RetryConstraint

use of com.path.android.jobqueue.RetryConstraint in project dev-summit-architecture-demo by yigit.

the class FetchFeedJobTest method testFailure404.

@Test
public void testFailure404() throws Throwable {
    FetchFeedJob job = new FetchFeedJob(BaseJob.BACKGROUND, null);
    when(mApiService.feed(0L)).thenReturn(createCall(404, new FeedResponse()));
    job.inject(getTestComponent());
    Throwable exception = safeRun(job);
    assertThat(exception, notNullValue());
    assertThat(exception, instanceOf(NetworkException.class));
    RetryConstraint retryConstraint = job.shouldReRunOnThrowable(exception, 1, 10);
    assertThat(retryConstraint.shouldRetry(), is(false));
}
Also used : RetryConstraint(com.path.android.jobqueue.RetryConstraint) FeedResponse(com.android.example.devsummit.archdemo.api.FeedResponse) NetworkException(com.android.example.devsummit.archdemo.job.NetworkException) BaseTest(com.android.example.devsummit.archdemo.BaseTest) Test(org.junit.Test)

Aggregations

RetryConstraint (com.path.android.jobqueue.RetryConstraint)3 BaseTest (com.android.example.devsummit.archdemo.BaseTest)2 FeedResponse (com.android.example.devsummit.archdemo.api.FeedResponse)2 NetworkException (com.android.example.devsummit.archdemo.job.NetworkException)2 Test (org.junit.Test)2