use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class RetryHandlerTest method testRetryOnRecoverableError.
/**
* Test retry on recoverable error.
*/
@Test
public void testRetryOnRecoverableError() {
// arrange
RetryHandler subject = new RetryHandler(8, 0, 1, 1);
DataStoreException expectedException = new DataStoreException("PaginatedResult<ModelWithMetadata<BlogOwner>>", "");
AtomicInteger count = new AtomicInteger(0);
Single<Object> mockSingle = Single.error(expectedException).doOnError(e -> count.incrementAndGet());
// act and assert
subject.retry(mockSingle, new ArrayList<>()).test().awaitDone(10, TimeUnit.SECONDS).assertError(expectedException).isDisposed();
assertEquals(2, count.get());
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class RetryHandlerTest method testNoRetryOnIrrecoverableError.
/**
* Test no retry on Irrecoverable error.
*/
@Test
public void testNoRetryOnIrrecoverableError() {
// arrange
RetryHandler subject = new RetryHandler();
DataStoreException expectedException = new DataStoreException.GraphQLResponseException("PaginatedResult<ModelWithMetadata<BlogOwner>>", new ArrayList<>());
Single<String> mockSingle = Single.error(expectedException);
ArrayList<Class<? extends Throwable>> skipExceptionList = new ArrayList<>();
skipExceptionList.add(DataStoreException.GraphQLResponseException.class);
// act and assert
subject.retry(mockSingle, skipExceptionList).test().awaitDone(1, TimeUnit.SECONDS).assertError(expectedException).isDisposed();
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class SubscriptionProcessorTest method arrangeDataEmittingSubscription.
@SuppressWarnings("SameParameterValue")
private static <T extends Model> void arrangeDataEmittingSubscription(AppSync appSync, ModelSchema modelSchema, SubscriptionType subscriptionType, GraphQLResponse<ModelWithMetadata<T>> response) throws DataStoreException {
Answer<Cancelable> answer = invocation -> {
final int startConsumerIndex = 1;
Consumer<String> onStart = invocation.getArgument(startConsumerIndex);
onStart.accept(RandomString.string());
final int dataConsumerIndex = 2;
Consumer<GraphQLResponse<ModelWithMetadata<T>>> onData = invocation.getArgument(dataConsumerIndex);
onData.accept(response);
return new NoOpCancelable();
};
arrangeSubscription(appSync, answer, modelSchema, subscriptionType);
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class SyncProcessorTest method retryHandlesHydrateSubscriptionDispose.
/**
* Verify that retry is called on appsync failure and when dispose in called midway no exception is thrown.
*
* @throws AmplifyException On failure to build GraphQLRequest for sync query.
*/
@Test
public void retryHandlesHydrateSubscriptionDispose() throws AmplifyException {
// Arrange: mock failure when invoking hydrate
requestRetry = spy(RetryHandler.class);
initSyncProcessor(10_000);
AppSyncMocking.sync(appSync).mockFailure(new DataStoreException("Something timed out during sync.", ""));
// Act: call hydrate.
TestObserver<Void> testObserver = syncProcessor.hydrate().test(false);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
testObserver.dispose();
}
}, 10000);
verify(requestRetry, times(1)).retry(any(), any());
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class SyncProcessorTest method shouldNotRetryOnAppSyncFailureWhenSynRetryIsSetToFalse.
/**
* Verify that retry is called on appsync failure when syncRetry is set to true.
*
* @throws AmplifyException On failure to build GraphQLRequest for sync query.
*/
@Test
public void shouldNotRetryOnAppSyncFailureWhenSynRetryIsSetToFalse() throws AmplifyException {
// Arrange: mock failure when invoking hydrate on the mock object.
requestRetry = mock(RetryHandler.class);
isSyncRetryEnabled = false;
when(requestRetry.retry(any(), any())).thenReturn(Single.error(new DataStoreException("PaginatedResult<ModelWithMetadata<BlogOwner>>", "")));
initSyncProcessor(10_000);
AppSyncMocking.sync(appSync).mockFailure(new DataStoreException("Something timed out during sync.", ""));
// Act: call hydrate.
syncProcessor.hydrate().test(false).assertNotComplete();
verify(requestRetry, times(0)).retry(any(), any());
}
Aggregations