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
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7a1664d
Add apollo-idling-resource module
VisheshVadhera Apr 19, 2017
3ad4610
Restructuring of the module
VisheshVadhera Apr 19, 2017
1210f32
Add IdlingResource class
VisheshVadhera Apr 19, 2017
0dda9b8
Add dispatcher
VisheshVadhera Apr 20, 2017
51817a7
Add ApolloTracker for tracking the requests
VisheshVadhera Apr 22, 2017
76780b3
Execute callback on calls finished
VisheshVadhera Apr 24, 2017
0af44d1
Register espresso callback with apolloTracker
VisheshVadhera Apr 24, 2017
989e102
Add basic test to check that idlingResource is being created properly
VisheshVadhera Apr 24, 2017
b68e8e5
Add test for idleNow
VisheshVadhera Apr 25, 2017
ff6fa0d
Add test for registerCallBack
VisheshVadhera Apr 26, 2017
7158335
Rename variables
VisheshVadhera Apr 26, 2017
873f393
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera Apr 28, 2017
5525529
Change variable names
VisheshVadhera Apr 28, 2017
43a90b6
Add tests for apolloCallTracker
VisheshVadhera Apr 28, 2017
53801bf
Hide usage of apolloTracker in apolloClient
VisheshVadhera Apr 28, 2017
4483920
Fix tests in apolloCallTracker
VisheshVadhera Apr 28, 2017
190ae11
Add tests for syncCalls
VisheshVadhera Apr 28, 2017
664b033
Add test for checking that idleCallback is invoked
VisheshVadhera Apr 28, 2017
41dcb1d
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera Apr 28, 2017
72484ae
Cleanup
VisheshVadhera Apr 28, 2017
cbf6574
Add docs for ApolloCallTracker
VisheshVadhera Apr 28, 2017
de9a829
Checkstyle
VisheshVadhera May 1, 2017
1cc6187
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 2, 2017
07d4b91
Merge branch 'feature-espresso-idling-resource' of github.com:Vishesh…
VisheshVadhera May 2, 2017
5d23a9f
Temp fix for apollo-sample module
VisheshVadhera May 2, 2017
69a28d5
Revert the change made in last commit
VisheshVadhera May 3, 2017
d934cc0
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 3, 2017
8d1a6d6
Fix the assertionError in ApolloPrefetchCallbackTest
VisheshVadhera May 3, 2017
7610a67
Move the test class to idling-resource package
VisheshVadhera May 3, 2017
c75d4c4
Add docs for new methods in apolloClient
VisheshVadhera May 3, 2017
79d2f99
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 4, 2017
f5ba765
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 9, 2017
85581e0
Change method names
VisheshVadhera May 11, 2017
7471952
Move the private method to the last
VisheshVadhera May 11, 2017
f3f1e48
Change method names
VisheshVadhera May 11, 2017
fa598f1
Change Deque with LinkedHashSet
VisheshVadhera May 11, 2017
0d495e1
Remove synchronized from setIdleCallback
VisheshVadhera May 11, 2017
8133815
Rename idleCallback to idleResourceCallback
VisheshVadhera May 12, 2017
1860193
Merge branch 'feature-espresso-idling-resource' of github.com:Vishesh…
VisheshVadhera May 12, 2017
f47672b
Fix checkstyle
VisheshVadhera May 12, 2017
c8102ba
Fix checkstyle
VisheshVadhera May 12, 2017
dd3cb51
Fix failing test
VisheshVadhera May 13, 2017
95c9383
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 13, 2017
f9d36a8
Change package & module name
VisheshVadhera May 13, 2017
ac1e4a8
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 13, 2017
516615b
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 23, 2017
4fab454
Code review
VisheshVadhera May 24, 2017
57c401d
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 29, 2017
c4e5ab5
Change the order of methods in the class
VisheshVadhera May 29, 2017
3dad93e
Add missing tracker to builder in RealApolloCall
VisheshVadhera May 29, 2017
9820c66
Fix tests in queryFetcher
VisheshVadhera May 30, 2017
2096424
Merge branch 'master' of github.com:apollographql/apollo-android into…
VisheshVadhera May 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add docs for ApolloCallTracker
  • Loading branch information
VisheshVadhera committed Apr 28, 2017
commit cbf6574aa06a97e5bcba20698ce98be5adbb1789
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.ArrayDeque;
import java.util.Deque;

/**
* ApolloCallTracker is responsible for keeping track of running {@link ApolloCall} & {@link ApolloPrefetch} objects.
*/
public class ApolloCallTracker {
Copy link
Contributor

@sav007 sav007 May 9, 2017

Choose a reason for hiding this comment

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

final


private Runnable idleCallback;
Expand All @@ -18,10 +21,25 @@ public class ApolloCallTracker {
public ApolloCallTracker() {
}

void syncPrefetchInProgress(ApolloPrefetch apolloPrefetch) {
/**
* <p>Adds this {@link ApolloPrefetch} to the underlying data structure keeping track of the in progress synchronous
* prefetch objects.</p>
*
* <p><b>Note</b>: This method needs to be called right before a prefetch call is executed.</p>
*/
synchronized void syncPrefetchInProgress(ApolloPrefetch apolloPrefetch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess would be better to add on prefix onSyncPrefetchInProgress

runningSyncPrefetches.add(apolloPrefetch);
}

/**
* <p>Removes this {@link ApolloPrefetch} from the underlying data structure keeping track of the in progress
* synchronous prefetch objects, if it is found, else throws an {@link AssertionError}.</p> If the removal operation
* is successful and no active running calls are found, then the registered {@link ApolloCallTracker#idleCallback} is
* invoked.
*
* <p><b>Note</b>: This method needs to be called right after a prefetch call is completed (whether successful or
* failed).</p>
*/
void syncPrefetchFinished(ApolloPrefetch apolloPrefetch) {
Runnable idleCallback;
int runningCallsCount;
Expand All @@ -35,10 +53,25 @@ void syncPrefetchFinished(ApolloPrefetch apolloPrefetch) {
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback);
}

/**
* <p>Adds this asyncCall representing an asynchronous {@link ApolloPrefetch} to the underlying data structure keeping
* track of the in progress asynchronous prefetch objects.</p>
*
* <p><b>Note</b>: This method needs to be called right before a prefetch call is executed.</p>
*/
synchronized void asyncPrefetchInProgress(RealApolloPrefetch.AsyncCall asyncCall) {
runningAsyncPrefetches.add(asyncCall);
}

/**
* <p>Removes this asyncCall representing an asynchronous {@link ApolloPrefetch} from the underlying data structure
* keeping track of the in progress asynchronous prefetch objects, if it is found, else throws an {@link
* AssertionError}.</p> If the removal operation is successful and no active running calls are found, then the
* registered {@link ApolloCallTracker#idleCallback} is invoked.
*
* <p><b>Note</b>: This method needs to be called right after a prefetch call is completed (whether successful or
* failed).</p>
*/
void asyncPrefetchFinished(RealApolloPrefetch.AsyncCall asyncCall) {
Runnable idleCallback;
int runningCallsCount;
Expand All @@ -52,10 +85,25 @@ void asyncPrefetchFinished(RealApolloPrefetch.AsyncCall asyncCall) {
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback);
}

/**
* <p>Adds this {@link ApolloCall} to the underlying data structure keeping track of the in progress synchronous
* apolloCall objects.</p>
*
* <p><b>Note</b>: This method needs to be called right before an apolloCall is executed.</p>
*/
synchronized void syncCallInProgress(ApolloCall apolloCall) {
runningSyncCalls.add(apolloCall);
}

/**
* <p>Removes this {@link ApolloCall} from the underlying data structure keeping track of the in progress synchronous
* apolloCall objects, if it is found, else throws an {@link AssertionError}.</p> If the removal operation is
* successful and no active running calls are found, then the registered {@link ApolloCallTracker#idleCallback} is
* invoked.
*
* <p><b>Note</b>: This method needs to be called right after an apolloCall is completed (whether successful or
* failed).</p>
*/
void syncCallFinished(ApolloCall apolloCall) {
Runnable idleCallback;
int runningCallsCount;
Expand All @@ -69,10 +117,25 @@ void syncCallFinished(ApolloCall apolloCall) {
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback);
}

/**
* <p>Adds this asyncCall representing an asynchronous {@link ApolloCall} to the underlying data structure keeping
* track of the in progress asynchronous apolloCall objects.</p>
*
* <p><b>Note</b>: This method needs to be called right before an apolloCall is executed.</p>
*/
synchronized void asyncCallInProgress(RealApolloCall<?>.AsyncCall asyncCall) {
runningAsyncCalls.add(asyncCall);
}

/**
* <p>Removes this asyncCall representing an asynchronous {@link ApolloCall} from the underlying data structure
* keeping track of the in progress asynchronous apolloCall objects, if it is found, else throws an {@link
* AssertionError}.</p> If the removal operation is successful and no active running calls are found, then the
* registered {@link ApolloCallTracker#idleCallback} is invoked.
*
* <p><b>Note</b>: This method needs to be called right after an apolloCall is completed (whether successful or
* failed).</p>
*/
void asyncCallFinished(RealApolloCall<?>.AsyncCall asyncCall) {
Runnable idleCallback;
int runningCallsCount;
Expand All @@ -86,6 +149,9 @@ void asyncCallFinished(RealApolloCall<?>.AsyncCall asyncCall) {
executeCallBackIfCallsAreFinished(runningCallsCount, idleCallback);
}

/**
* Registers idleCallback which is invoked when the apolloClient becomes idle.
*/
public synchronized void setIdleCallback(Runnable idleCallback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don;t think we need it to be synchronized, it doesn't have any value.

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.

this.idleCallback = idleCallback;
}
Expand All @@ -96,6 +162,9 @@ private void executeCallBackIfCallsAreFinished(int runningCallsCount, Runnable i
}
}

/**
* Returns a total count of in progress {@link ApolloCall} & {@link ApolloPrefetch} objects.
*/
public int getRunningCallsCount() {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to activeCallCount()

return runningAsyncCalls.size() +
runningSyncCalls.size() +
Expand Down