InterceptorResponse resolveFromCache(InterceptorRequest request) throws ApolloException { ResponseNormalizer<Record> responseNormalizer = apolloStore.cacheResponseNormalizer(); //noinspection unchecked ApolloStoreOperation<Response> apolloStoreOperation = apolloStore.read(request.operation, responseFieldMapper, responseNormalizer, request.cacheHeaders); Response cachedResponse = apolloStoreOperation.execute(); if (cachedResponse.data() != null) { logger.d("Cache HIT for operation %s", request.operation); return new InterceptorResponse(null, cachedResponse, responseNormalizer.records()); } logger.d("Cache MISS for operation %s", request.operation); throw new ApolloException(String.format("Cache miss for operation %s", request.operation)); }
ArgumentCaptor.forClass(ApolloInterceptor.InterceptorResponse.class); verify(interceptorCallBack).onResponse(interceptorResponseArgumentCaptor.capture()); assertThat(interceptorResponseArgumentCaptor.getValue().parsedResponse.get().data()).isNotNull(); assertThat(interceptorResponseArgumentCaptor.getValue().parsedResponse.get().hasErrors()).isFalse();
verify(interceptorCallBack).onResponse(interceptorResponseArgumentCaptor.capture()); assertThat(interceptorResponseArgumentCaptor.getValue().parsedResponse.get().hasErrors()).isFalse(); assertThat(interceptorResponseArgumentCaptor.getValue().parsedResponse.get().data()).isNotNull();
verify(interceptorCallBack).onResponse(interceptorResponseArgumentCaptor.capture()); assertThat(interceptorResponseArgumentCaptor.getValue().parsedResponse.get().hasErrors()).isFalse(); assertThat(interceptorResponseArgumentCaptor.getValue().parsedResponse.get().data()).isNotNull();
private InterceptorResponse resolveFromCache(InterceptorRequest request) throws ApolloException { ResponseNormalizer<Record> responseNormalizer = mApolloStore.cacheResponseNormalizer(); //noinspection unchecked GraphQLStoreOperation<Response> graphQLStoreOperation = mApolloStore.read(request.operation, responseFieldMapper, responseNormalizer, request.cacheHeaders); Response cachedResponse = graphQLStoreOperation.execute(); if (cachedResponse.data() != null) { logger.d("Cache HIT for operation %s", request.operation); return new InterceptorResponse(null, cachedResponse, responseNormalizer.records()); } logger.d("Cache MISS for operation %s", request.operation); throw new ApolloException(String.format("Cache miss for operation %s", request.operation)); }
private InterceptorResponse resolveFromCache(InterceptorRequest request) throws ApolloException { ResponseNormalizer<Record> responseNormalizer = mApolloStore.cacheResponseNormalizer(); //noinspection unchecked GraphQLStoreOperation<Response> graphQLStoreOperation = mApolloStore.read(request.operation, responseFieldMapper, responseNormalizer, request.cacheHeaders); Response cachedResponse = graphQLStoreOperation.execute(); if (cachedResponse.data() != null) { logger.d("Cache HIT for operation %s", request.operation); return new InterceptorResponse(null, cachedResponse, responseNormalizer.records()); } logger.d("Cache MISS for operation %s", request.operation); throw new ApolloException(String.format("Cache miss for operation %s", request.operation)); }
public void testCache() { AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.createAppSyncClientWithIAM(); assertNotNull(awsAppSyncClient); String postID = "ce228ceb-c2fc-483e-8c3e-3d33fb8dd61f"; queryPost(awsAppSyncClient, AppSyncResponseFetchers.NETWORK_ONLY,postID); assertNotNull(getPostQueryResponse); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertEquals(postID, getPostQueryResponse.data().getPost().id()); getPostQueryResponse = null; queryPost(awsAppSyncClient, AppSyncResponseFetchers.CACHE_ONLY,postID); assertNotNull(getPostQueryResponse); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertEquals(postID, getPostQueryResponse.data().getPost().id()); }
@Test public void testUpdateWithInvalidID() { AWSAppSyncClient awsAppSyncClient = AppSyncTestSetupHelper.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;")); }
assertNotNull(addPostMutationResponse.data()); assertNotNull(addPostMutationResponse.data().createPost()); assertNotNull(addPostMutationResponse.data().createPost().id()); String postID = addPostMutationResponse.data().createPost().id(); Log.d(TAG, "Added Post ID: " + postID); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertEquals(postID, getPostQueryResponse.data().getPost().id()); assertTrue(content.equals(getPostQueryResponse.data().getPost().content())); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertEquals(postID, getPostQueryResponse.data().getPost().id()); assertTrue(content.equals(getPostQueryResponse.data().getPost().content())); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertTrue(postID.equals(getPostQueryResponse.data().getPost().id())); assertTrue(content.equals(getPostQueryResponse.data().getPost().content())); assertNotNull(updatePostMutationResponse.data()); assertNotNull(updatePostMutationResponse.data().updatePost()); assertNotNull(updatePostMutationResponse.data().updatePost().content()); assertEquals(true, updatedContent.equals(updatePostMutationResponse.data().updatePost().content())); assertEquals(false, content.equals(updatePostMutationResponse.data().updatePost().content())); assertNotNull(getPostQueryResponse.data());
assertNotNull(addPostMutationResponse.data()); assertNotNull(addPostMutationResponse.data().createPost()); assertNotNull(addPostMutationResponse.data().createPost().id()); final String postID = addPostMutationResponse.data().createPost().id(); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertNotNull(getPostQueryResponse.data().getPost().author()); assertEquals( updatedAuthor, getPostQueryResponse.data().getPost().author());
assertNotNull(addPostMutationResponse.data()); assertNotNull(addPostMutationResponse.data().createPost()); assertNotNull(addPostMutationResponse.data().createPost().id()); final String postID = addPostMutationResponse.data().createPost().id(); assertNotNull(getPostQueryResponse.data()); assertNotNull(getPostQueryResponse.data().getPost()); assertNotNull(getPostQueryResponse.data().getPost().author()); assertEquals( author + (numberOfLatches -1), getPostQueryResponse.data().getPost().author());
String postID = addPostMutationResponse.data().createPost().id(); Log.d(TAG, "Added Post");