Skip to content

Commit

Permalink
Bug fixes for issue 54, 53 and 51. (#56)
Browse files Browse the repository at this point in the history
* Bug fixes for issue 54, 53 and 51.
Added test for issue 51.

* Addressed feedback comments
  • Loading branch information
scb01 authored Nov 8, 2018
1 parent bc81c78 commit e885da0
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log - AWS AppSync SDK for Android

## [Release 2.6.27](https://github.com/awslabs/aws-mobile-appsync-sdk-android/releases/tag/release_v2.6.27)

### Bug Fixes
* Fixed bug in subscribe call that was setting the QoS to be 0. It is now correctly set to QoS 1. See [issue #54](https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/54)
* Fixed bug that was causing a ConcurrentModificationException in the logic to handle connection loss. See [PR #41](https://github.com/awslabs/aws-mobile-appsync-sdk-android/pull/41) and [issue #53](https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/53)
* Fixed null pointer exception in the AppSyncOfflineMutationInterceptor. See [issue #51](https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/51)

## [Release 2.6.26](https://github.com/awslabs/aws-mobile-appsync-sdk-android/releases/tag/release_v2.6.26)

### New Features
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Generated file. Do not edit!
package com.apollographql.android
val VERSION = "2.6.26"
val VERSION = "2.6.27"
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider;
import com.amazonaws.regions.Regions;
import com.apollographql.apollo.GraphQLCall;
import com.apollographql.apollo.api.Error;
import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.exception.ApolloException;
import com.apollographql.apollo.fetcher.ResponseFetcher;
Expand All @@ -58,6 +59,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -708,6 +710,25 @@ public void testCRUD() {
assertNull(getPostQueryResponse.data().getPost());
}

@Test
public void testUpdateWithInvalidID() {

AWSAppSyncClient awsAppSyncClient = createAppSyncClientWithIAM();
assertNotNull(awsAppSyncClient);

//Try to update a Post with a Fake ID
final String updatedContent = "New content coming up @" + System.currentTimeMillis();
final String randomID = UUID.randomUUID().toString();
updatePost(awsAppSyncClient, randomID, updatedContent);
assertNotNull(updatePostMutationResponse);
assertNull(updatePostMutationResponse.data().updatePost());
assertNotNull(updatePostMutationResponse.errors());
Error error = updatePostMutationResponse.errors().get(0);
assertNotNull(error);
assertNotNull(error.message());
assertTrue(error.message().contains("Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ConditionalCheckFailedException;"));

}

private void queryPosts(AWSAppSyncClient awsAppSyncClient, final ResponseFetcher responseFetcher) {

Expand Down Expand Up @@ -1023,10 +1044,10 @@ public void run() {

UpdatePostMutation.Data expected = new UpdatePostMutation.Data( new UpdatePostMutation.UpdatePost(
"Post",
postID,
"",
"",
"",
"",
content,
"",
0
));
Expand Down Expand Up @@ -1054,6 +1075,7 @@ public void onResponse(@Nonnull final Response<UpdatePostMutation.Data> response

@Override
public void onFailure(@Nonnull final ApolloException e) {
Log.d(TAG, "On error called");
e.printStackTrace();
//Set to null to indicate failure
updatePostMutationResponse = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private AWSAppSyncClient(AWSAppSyncClient.Builder builder) {
okHttpClientBuilder = builder.mOkHttpClient.newBuilder();
}

//Create the OK HTTP Client and add our Retry and Signer Interceptors to it.
OkHttpClient okHttpClient = okHttpClientBuilder
.addInterceptor(new RetryInterceptor())
.addInterceptor(appSyncSigV4SignerInterceptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -78,6 +79,7 @@ class InterceptorCallback implements ApolloInterceptor.CallBack {
Operation currentMutation;
String clientState;
String recordIdentifier;
private static final String TAG = InterceptorCallback.class.getSimpleName();

public InterceptorCallback(ApolloInterceptor.CallBack customerCallBack, Handler handler,
final Operation originalMutation,
Expand All @@ -95,29 +97,33 @@ public InterceptorCallback(ApolloInterceptor.CallBack customerCallBack, Handler

@Override
public void onResponse(@Nonnull ApolloInterceptor.InterceptorResponse response) {
Log.d("AppSync", "onResponse()");
Log.d(TAG, "onResponse()");
//The conditional request failed
if ((response.parsedResponse.get() != null) && (response.parsedResponse.get().errors().size() >= 1)) {
Log.d("AppSync", "onResponse -- found error");
if ( response.parsedResponse.get().errors().get(0).toString().contains("The conditional request failed")) {
Log.d("AppSync", "onResponse -- string match");
if ((response.parsedResponse.get() != null) && (response.parsedResponse.get().hasErrors())) {
Log.d(TAG, "onResponse -- found error");
if ( response.parsedResponse.get().errors().get(0).toString().contains("The conditional request failed") ) {
Log.d(TAG, "onResponse -- Got a string match in the errors for \"The conditional request failed\".");
// if !shouldRetry AND conflict detected
if (shouldRetry) {
String conflictString = new JSONObject((Map)((Error) response.parsedResponse.get().errors().get(0)).customAttributes().get("data")).toString();
Log.d("AppSync", "Conflict String: " + conflictString);
Log.d("AppSync", "Client String: " + clientState);
Message message = new Message();
MutationInterceptorMessage msg = new MutationInterceptorMessage(originalMutation, currentMutation);
msg.serverState = conflictString;
msg.clientState = clientState;
msg.requestIdentifier = recordIdentifier;
msg.requestClassName = currentMutation.getClass().getSimpleName();
//msg.requestIdentifier = originalMutation.un
message.obj = msg;
message.what = MessageNumberUtil.RETRY_EXEC;
handler.sendMessage(message);
shouldRetry = false;
return;
Map data = (Map)((Error) response.parsedResponse.get().errors().get(0)).customAttributes().get("data");
//Verify that data was passed as per the contract from the server for mutation conflicts.
if (data != null ) {
String conflictString = new JSONObject(data).toString();
Log.d(TAG, "Conflict String: " + conflictString);
Log.d(TAG, "Client String: " + clientState);
Message message = new Message();
MutationInterceptorMessage msg = new MutationInterceptorMessage(originalMutation, currentMutation);
msg.serverState = conflictString;
msg.clientState = clientState;
msg.requestIdentifier = recordIdentifier;
msg.requestClassName = currentMutation.getClass().getSimpleName();
//msg.requestIdentifier = originalMutation.un
message.obj = msg;
message.what = MessageNumberUtil.RETRY_EXEC;
handler.sendMessage(message);
shouldRetry = false;
return;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
*/

class AppSyncOptimisticUpdateInterceptor implements ApolloInterceptor {

private static final String TAG = AppSyncOptimisticUpdateInterceptor.class.getSimpleName();
private ApolloStore store;

public void setStore(ApolloStore store) {
this.store = store;
}


@Override
public void interceptAsync(@Nonnull final InterceptorRequest request,
@Nonnull ApolloInterceptorChain chain,
Expand All @@ -52,15 +51,14 @@ public void interceptAsync(@Nonnull final InterceptorRequest request,
@Override
public void run() {
try {
Log.d("AppSync", "Starting to do optimistic update!");
Log.d(TAG, "Starting to do optimistic update!");
store.write(request.operation, data).execute();
} catch (Exception e) {
Log.e("AppSync", "failed to write operation optimistic updates, for: " + request.operation);
Log.e(TAG, "failed to write operation optimistic updates, for: " + request.operation);
}
}
});
}

chain.proceedAsync(request, dispatcher, callBack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void onConnect() {
for (String topic : info.topics) {
if (topicSet.contains(topic)) {
Log.d(TAG, String.format("Connecting to topic:[%s]", topic));
client.subscribe(topic, 0, mainMessageCallback);
client.subscribe(topic, 1, mainMessageCallback);
}
}
newClients.add(client);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ org.gradle.jvmargs=-Xmx1536m
org.gradle.parallel=true

GROUP=com.amazonaws
VERSION_NAME=2.6.26
AWS_CORE_SDK_VERSION=2.7.2
VERSION_NAME=2.6.27
AWS_CORE_SDK_VERSION=2.7.7

POM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android
POM_SCM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android
Expand Down

0 comments on commit e885da0

Please sign in to comment.