Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Espresso idling resource for Apollo GraphQL client #469

Merged

Conversation

VisheshVadhera
Copy link
Contributor

@VisheshVadhera VisheshVadhera commented Apr 28, 2017

Closes #429

Added a new ApolloTracker class which keeps track of the running ApolloCall & ApolloPrefetch objects. ApolloIdlingResource basically uses this class (indirectly) to keep a count of the running call objects. When the count becomes zero it changes its state from active to idle.

ApolloTracker is very similar to the Dispatcher class in okHttpClient, but without the ExecutorService encapsulated inside.

… feature-espresso-idling-resource

Conflicts:
	apollo-integration/build.gradle
	apollo-integration/src/test/java/com/apollographql/apollo/IntegrationTest.java
	apollo-runtime/src/main/java/com/apollographql/apollo/ApolloClient.java
	apollo-runtime/src/main/java/com/apollographql/apollo/internal/RealApolloCall.java
Not exposing apolloTracker to the clients. Instead they have to call apolloClient's getRunningCount method and setIdleCallback method which then delegates these calls to the apolloTracker
@VisheshVadhera
Copy link
Contributor Author

Please put the review on hold. I just found a flaky test. Will fix it and we can then review this one.

@sav007
Copy link
Contributor

sav007 commented May 2, 2017

com.apollographql.apollo.ApolloPrefetchCallbackTest > onNetworkError[test(AVD) - 4.0.4] FAILED 
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.AssertionError''. Check device logcat for details
Tests on test(AVD) - 4.0.4 failed: Instrumentation run failed due to 'java.lang.AssertionError'
:apollo-android-support:connectedDebugAndroidTest FAILED

… feature-espresso-idling-resource

Conflicts:
	apollo-runtime/src/main/java/com/apollographql/apollo/internal/RealApolloCall.java
…Vadhera/apollo-android into feature-espresso-idling-resource
@VisheshVadhera
Copy link
Contributor Author

@sav007 Fixing it.

…Vadhera/apollo-android into feature-espresso-idling-resource

Conflicts:
	apollo-runtime/src/main/java/com/apollographql/apollo/internal/ApolloCallTracker.java
… feature-espresso-idling-resource

Conflicts:
	gradle/dependencies.gradle
@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=apollo-idling-resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call it then apollo-espresso-support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah adding espresso makes it clear that this module is about supporting espresso testing. apollo-idling-resource sounds vague.

@@ -0,0 +1,61 @@
package com.apollographql.apollo.espresso;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com.apollographql.apollo.test.espresso ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=apollo-idling-resource
POM_NAME=Apollo GraphQL Idling Resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apollo GraphQL Espresso Support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@sav007 sav007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Only question about the naming of this module.

And I feel we need to publish jars instead of aars for all our android libs: http://stackoverflow.com/questions/19307341/android-library-gradle-release-jar

@sav007 sav007 mentioned this pull request May 13, 2017
@VisheshVadhera
Copy link
Contributor Author

@sav007 I think it makes sense to publish jars only as we don't really have any resources in our android modules. Should I open a new issue, so that this can be tackled in another PR?

@VisheshVadhera
Copy link
Contributor Author

VisheshVadhera commented May 13, 2017

Ok, looks like the build failed because the CI server was unable to download guava :|

A problem occurred configuring project ':apollo-android-support'.

Could not resolve all files for configuration ':apollo-android-support:classpath'.
Could not download guava.jar (com.google.guava:guava:18.0)
> Could not get resource 'https://jcenter.bintray.com/com/google/guava/guava/18.0/guava-18.0.jar'.
> Response 304: Not Modified has no content!

@sav007
Copy link
Contributor

sav007 commented May 16, 2017

@digitalbuddha @BenSchwab @marwanad any comments?

@marwanad
Copy link
Contributor

marwanad commented May 16, 2017

I'll take a look tomorrow.

edit: srry got swamped with other stuff. I'll get back to it in a day or two.

… feature-espresso-idling-resource

Conflicts:
	apollo-runtime/src/main/java/com/apollographql/apollo/ApolloClient.java
	apollo-runtime/src/main/java/com/apollographql/apollo/internal/RealApolloCall.java
Copy link
Contributor

@marwanad marwanad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 some minor nits.

Apologies for the delay, I'll finish up the rest of the review later.

I'm not a fan of the eager initialization of the ApolloTracker but it seems inevitable for now. Would combining both the dispatcher and tracker under one extensible class make sense for this?

Last thing, I think it's not worth creating a module for the EspressoIdlingResource under this repo though. Though unlikely, it would guard us against having to maintain that module if Espresso changes in the future.
We should, however, provide the API for an idle callback.

@@ -0,0 +1 @@
/build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

The top-level .gitignore has build/ already I believe.

Copy link
Contributor Author

@VisheshVadhera VisheshVadhera May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the top level .gitignore ignores the module specific build directories, so yeah this is indeed required.

* Creates a new {@link IdlingResource} from {@link ApolloClient} with a given name. Register this instance using
* Espresso class's registerIdlingResource in your test suite's setup method.
*
* @param name name of this idlingResource instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:spacing

@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=apollo-espress-support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

espresso

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=apollo-espress-support
POM_NAME=Apollo GraphQL Espresso Support
POM_DESCRIPTION=An EspressoIdlingResource for Apollo GraphQL Client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EspressoIdlingResource -> Espresso Idling Resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright

/**
* An Espresso {@link IdlingResource} for {@link com.apollographql.apollo.ApolloClient}.
*/
public class ApolloIdlingResource implements IdlingResource {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make final?

*/
public final class ApolloCallTracker {

private IdleResourceCallback idleResourceCallback;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a class for that? Can't we just take a Runnable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use Runnable for this as this is really callback not some runnable action that we need to run.

@VisheshVadhera
Copy link
Contributor Author

@marwanad Well that was the first thought which came to my mind to combine dispatcher and tracker in one class, but decided against it, because I wanted to keep the concerns separate and have a class whose only concern is to track calls and do nothing more.

@sav007
Copy link
Contributor

sav007 commented May 25, 2017

@VisheshVadhera I see all tests related to cache are failing could you pls fix that we can merge this PR

@VisheshVadhera
Copy link
Contributor Author

VisheshVadhera commented May 26, 2017 via email

@VisheshVadhera
Copy link
Contributor Author

@sav007 Fixed the failing tests. Feel free to merge this PR.

@sav007 sav007 merged commit 5b28d8d into apollographql:master Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants