use of com.amazonaws.mobileconnectors.appsync.demo.type.CreatePostInput in project aws-mobile-appsync-sdk-android by awslabs.
the class QueryInstrumentationTest method testCancelMutationWithinCallback.
/**
* TODO: not clear why this (unusual) edge-case is worth testing.
*/
@Test
public void testCancelMutationWithinCallback() {
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withIAMFromAWSConfiguration();
final CountDownLatch add2CountDownLatch = new CountDownLatch(1);
AddPostMutation.Data expected = new AddPostMutation.Data(new AddPostMutation.CreatePost("Post", "", "", "", "", "", null, null, 0));
CreatePostInput createPostInput1 = CreatePostInput.builder().title("L.A. Woman").author("Doors" + System.currentTimeMillis()).url("Doors.com").content("City at night").ups(1).downs(0).build();
AddPostMutation addPostMutation1 = AddPostMutation.builder().input(createPostInput1).build();
final AppSyncMutationCall<AddPostMutation.Data> call1 = awsAppSyncClient.mutate(addPostMutation1, expected);
CreatePostInput createPostInput2 = CreatePostInput.builder().title("Break On Through").author("Doors" + System.currentTimeMillis()).url("Doors.com").content("To the other side").ups(1).downs(0).build();
AddPostMutation addPostMutation2 = AddPostMutation.builder().input(createPostInput2).build();
final AppSyncMutationCall<AddPostMutation.Data> call2 = awsAppSyncClient.mutate(addPostMutation2, expected);
call1.enqueue(new GraphQLCall.Callback<AddPostMutation.Data>() {
@Override
public void onResponse(@NonNull Response<AddPostMutation.Data> response) {
call1.cancel();
}
@Override
public void onFailure(@NonNull ApolloException e) {
fail("OnError received for first mutation. Unexpected exception: " + e.getMessage());
}
});
call2.enqueue(new GraphQLCall.Callback<AddPostMutation.Data>() {
@Override
public void onResponse(@NonNull Response<AddPostMutation.Data> response) {
call2.cancel();
add2CountDownLatch.countDown();
}
@Override
public void onFailure(@NonNull ApolloException e) {
fail("OnError received for Second mutation. Unexpected exception: " + e.getMessage());
add2CountDownLatch.countDown();
}
});
Await.latch(add2CountDownLatch, REASONABLE_WAIT_TIME_MS);
}
Aggregations