use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class SubscriptionInstrumentationTest method testAddSubscriptionWithApiKeyAuthModel.
private static void testAddSubscriptionWithApiKeyAuthModel(SubscriptionReconnectMode subscriptionReconnectMode) {
boolean shouldAutomaticallyReconnect = SubscriptionReconnectMode.AUTOMATICALLY_RECONNECT.equals(subscriptionReconnectMode);
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withAPIKEYFromAWSConfiguration(shouldAutomaticallyReconnect, 0);
final String title = "Alabama Song [Whisky Bar]";
final String author = "Doors @ " + System.currentTimeMillis();
final String url = "The Doors";
final String content = "Well, show me the way, to the next whisky bar @" + System.currentTimeMillis();
// Subscribe to creations of Post.
AppSyncSubscriptionCall<OnCreatePostSubscription.Data> onCreatePostSubscriptionCall = awsAppSyncClient.subscribe(OnCreatePostSubscription.builder().build());
LatchedSubscriptionCallback<OnCreatePostSubscription.Data> onCreatePostCallback = LatchedSubscriptionCallback.instance();
onCreatePostSubscriptionCall.execute(onCreatePostCallback);
Log.d(TAG, "Subscribed and setup callback handler.");
// Sleep for a while to make sure the subscription goes through
Sleep.milliseconds(REASONABLE_WAIT_TIME_MS);
Posts.add(awsAppSyncClient, title, author, url, content);
Log.d(TAG, "Added Post");
// Did the post show up on the subscription?
onCreatePostCallback.awaitNextSuccessfulResponse();
// Cancel the subscription call, and expect a completion callback.
onCreatePostSubscriptionCall.cancel();
onCreatePostCallback.awaitCompletion();
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class ComplexObjectsInstrumentationTests method listArticles.
Map<String, Response<AllArticlesQuery.Data>> listArticles(AWSAppSyncClient awsAppSyncClient, ResponseFetcher responseFetcher) {
final CountDownLatch cacheLatch = new CountDownLatch(1);
final CountDownLatch networkLatch = new CountDownLatch(1);
final Map<String, Response<AllArticlesQuery.Data>> responses = new HashMap<>();
awsAppSyncClient.query(AllArticlesQuery.builder().build()).responseFetcher(responseFetcher).enqueue(DelegatingGraphQLCallback.to(response -> {
if (response.fromCache()) {
responses.put("CACHE", response);
cacheLatch.countDown();
} else {
responses.put("NETWORK", response);
networkLatch.countDown();
}
}, failure -> {
cacheLatch.countDown();
networkLatch.countDown();
}));
if (AppSyncResponseFetchers.NETWORK_ONLY.equals(responseFetcher) || AppSyncResponseFetchers.CACHE_AND_NETWORK.equals(responseFetcher)) {
Await.latch(networkLatch);
assertNotNull(responses.get("NETWORK"));
}
if (AppSyncResponseFetchers.CACHE_ONLY.equals(responseFetcher) || AppSyncResponseFetchers.CACHE_AND_NETWORK.equals(responseFetcher)) {
Await.latch(cacheLatch);
assertNotNull(responses.get("CACHE"));
}
return responses;
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class ConflictManagementInstrumentationTest method beforeAnyTests.
/**
* We will do one add and 5 updates that try out the various paths of conflict
* management. This function will exit once the add is completed and the
* updates are queued, but not executed. This has the effect of populating
* the persistent queue and exercising the persistent mutation execution flow
* when one of the tests in this suite starts.
*/
@BeforeClass
public static void beforeAnyTests() {
goOnline();
String title = "Minstrel in the Gallery";
String author = "Tull";
CustomCognitoUserPool.setup();
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withAPIKEYFromAWSConfiguration();
LatchedGraphQLCallback<CreateArticleMutation.Data> createArticleCallback = LatchedGraphQLCallback.instance();
awsAppSyncClient.mutate(CreateArticleMutation.builder().input(CreateArticleInput.builder().title(title).author(author).version(100).build()).build(), new CreateArticleMutation.Data(new CreateArticleMutation.CreateArticle("Article", "", "", "", 100, null, null))).enqueue(createArticleCallback);
Response<CreateArticleMutation.Data> response = createArticleCallback.awaitSuccessfulResponse();
assertNotNull(response);
assertNotNull(response.data());
CreateArticleMutation.CreateArticle createArticle = response.data().createArticle();
assertNotNull(createArticle);
assertNotNull(createArticle.id());
String[] titles = { title + System.currentTimeMillis(), "RESOLVE_CONFLICT_INCORRECTLY", title + System.currentTimeMillis(), "ALWAYS DISCARD", title + System.currentTimeMillis() };
for (String string : titles) {
awsAppSyncClient.mutate(UpdateArticleMutation.builder().input(UpdateArticleInput.builder().id(createArticle.id()).title(string).author(author).expectedVersion(1).build()).build(), new UpdateArticleMutation.Data(new UpdateArticleMutation.UpdateArticle("Article", "", "", "", 1, null, null))).enqueue(NoOpGraphQLCallback.instance());
}
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class ConflictManagementInstrumentationTest method testAddUpdateArticleNoConflict.
@Test
public void testAddUpdateArticleNoConflict() {
final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withAPIKEYFromAWSConfiguration();
String title = "Thick as a brick";
String author = "Tull" + System.currentTimeMillis();
String articleID = addArticle(awsAppSyncClient, title, author, 1);
updateArticle(awsAppSyncClient, articleID, title, author + System.currentTimeMillis(), 1, 2);
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testSyncOnlyBaseQuery.
@Test
public void testSyncOnlyBaseQuery() {
List<AWSAppSyncClient> clients = Arrays.asList(AWSAppSyncClients.withAPIKEYFromAWSConfiguration(), AWSAppSyncClients.withIAMFromAWSConfiguration(), AWSAppSyncClients.withUserPoolsFromAWSConfiguration());
for (AWSAppSyncClient client : clients) {
Query<AllPostsQuery.Data, AllPostsQuery.Data, Variables> baseQuery = AllPostsQuery.builder().build();
LatchedGraphQLCallback<Query.Data> baseQueryCallback = LatchedGraphQLCallback.instance();
Cancelable handle = client.sync(baseQuery, baseQueryCallback, 0);
assertFalse(handle.isCanceled());
baseQueryCallback.awaitSuccessfulResponse();
handle.cancel();
assertTrue(handle.isCanceled());
// This should be a No-op. Test to make sure.
handle.cancel();
assertTrue(handle.isCanceled());
}
}
Aggregations