Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

SpiceManager.getDateOfDataInCache doesn't work as expected #128

Closed
mcastets opened this issue Jun 25, 2013 · 21 comments
Closed

SpiceManager.getDateOfDataInCache doesn't work as expected #128

mcastets opened this issue Jun 25, 2013 · 21 comments

Comments

@mcastets
Copy link

This post follows on from this issue

That's about getDateOfDataInCache

  • If there's no such cache key or after using removeDataFromCache(clazz, cacheKey), getDateOfDataInCache(clazz, cacheKey).get() returns Thu Jan 01 01:00:00 UTC+01:00 1970 instead of the expected null.
  • And also something very weird... After locking my phone screen and unlocking it, (going through the onStop() and onStart() process) I got a NullPointerException on running getDateOfDataInCache(clazz, cacheKey)
    Please take note that's happened prior to calling get()
@rciovati
Copy link
Contributor

rciovati commented Jul 3, 2013

Although our tests was passing properly I edited our code for explicitely checking if the cache file exists. If you can try building RS from source your feedback would be appreciated.

@ghost ghost assigned rciovati Jul 9, 2013
@stephanenicolas
Copy link
Owner

@Bobby-Jackson We need some feedback from you. @rciovati I assigned this issue to you so that you can feel free to close it and related issues and pull requests.

@mcastets
Copy link
Author

mcastets commented Jul 9, 2013

Hi, I would like to but how can I build RS from the source? Any guide over there?

@rciovati
Copy link
Contributor

rciovati commented Jul 9, 2013

@Bobby-Jackson here you are the instructions :)

git clone [email protected]:octo-online/robospice.git
cd robospice
git checkout master
mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -Dfindbugs.skip=true -Dcheckstyle.skip=true -Dandroid.dex.optimize=false 

And then in your project replace your current RS version with 1.4.6-SNAPSHOT.

@stephanenicolas
Copy link
Owner

I personally prefer mvn clean install and keep all checks on.

Snapshots on sonatype include latest changes if you wanna try them.

@riccardo can't you deploy snapshots ? Are you missing any password / key ?

S.
Le 9 juil. 2013 10:13, "Riccardo Ciovati" [email protected] a
écrit :

@Bobby-Jackson https://github.com/Bobby-Jackson here you are the
instructions :)

git clone [email protected]:octo-online/robospice.gitcd robospice
git checkout master
mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -Dfindbugs.skip=true -Dcheckstyle.skip=true -Dandroid.dex.optimize=false

And then in your project replace your current RS version with
1.4.6-SNAPSHOT.


Reply to this email directly or view it on GitHubhttps://github.com//issues/128#issuecomment-20659443
.

@rciovati
Copy link
Contributor

rciovati commented Jul 9, 2013

On my machine (mbp with i5, 8gb ram and ssd) the whole process takes about 10minutes, for this reason I suggested the command to skip tests and checks which IHMO are not needed at this stage.

Actually I never tried to deploy snapshots, maybe I will give it a try.

@mcastets
Copy link
Author

Hi guys, I haven't got time yet to test the first bullet point but I have further information about the second one:

And also something very weird... After locking my phone screen and unlocking it, (going through the onStop() and onStart() process) I got a NullPointerException on running getDateOfDataInCache(clazz, cacheKey)
Please take note that's happened prior to calling get()

This error also happens with Future<List<Object>> getAllCacheKeys(Class<T> clazz) (and maybe with every SpiceManager method?)

My test case:

I have a listview inside a fragment and a refresh button. When i click on the refresh button I want to load data over the network so I clear cache and call execute

GetListSkillsRequest request = new GetListSkillsRequest();
String cacheKey = request.createCacheKey();
getSpiceManager().removeDataFromCache(ListSkills.class, cacheKey);  
getSpiceManager().execute(request, cacheKey, CACHE_EXPIRATION, new GetListSkillsRequestListener())

This working fine except when I open a skill (details view) and come back to my list (only onStart() and onResume() are called). Now, if I click to the refresh button, removeDataFromCache seems not to work.

I can't figure out why (same reason?) so I decided to surround removeDataFromCache by

List<Object> l = getSpiceManager().getAllCacheKeys(ListSkills.class).get();
Log.d(TAG, "Nb of cache keys = " + l.size());

Boum.

This working fine except when I open a skill (details view) and come back to my list (only onStart() and onResume() are called). If I click to the refresh button, Future<List<Object>> getSpiceManager().getAllCacheKeys(ListSkills.class) throws NullPointException

@mcastets
Copy link
Author

When coming back from my details view (or locking screen for instance) and hitting the refresh button, as I said before, the removeDataFromCache doesn't work.

I looked at the logs and the only difference I saw was the binding step. This doesn't appear...

07-10 14:13:24.895: D//SpiceManager.java:1110(23854): 14:13:24.899 Thread-5230 Waiting for service to be bound.
07-10 14:13:24.895: D//SpiceManager.java:1117(23854): 14:13:24.900 Thread-5230 Bound ok.

@mcastets
Copy link
Author

If there's no such cache key or after using removeDataFromCache(clazz, cacheKey), getDateOfDataInCache(clazz, > cacheKey).get() returns Thu Jan 01 01:00:00 UTC+01:00 1970 instead of the expected null.

stephanenicolas commented

Bobby-Jackson We need some feedback from you

This issue has been resolved with 1.4.6-SNAPSHOT

Thank you.

@stephanenicolas
Copy link
Owner

If I understand everything here, the issue can be closed.
Please re-open if needed, I just try to things a bit more clear in the issue list.

@mcastets
Copy link
Author

I'm sorry for not being very clear.

I had two issues (two bullet points in the first message). The first one is solved with 1.4.6-SNAPSHOT but the second is pending (you can get more information in my following messages).

I can open a new issue for the second issue if you want to.

@stephanenicolas
Copy link
Owner

It's strange, the following test works fine since the introduction of this feature (from SpiceManagerTest) :

 public void test_getDateOfDataInCache_when_there_is_no_data_in_cache() throws InterruptedException, SpiceException, ExecutionException, TimeoutException {
        // given
        // we use double to get some in memory cache implementation
        spiceManager.start(getInstrumentation().getTargetContext());
        spiceManager.removeDataFromCache(TEST_CLASS, true);

        // when

        // test
        assertNull(spiceManager.getDateOfDataInCache(TEST_CLASS, TEST_CACHE_KEY).get(SPICE_MANAGER_WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
    }

@mcastets
Copy link
Author

I have also this problem with:

  • removeDataFromCache
  • getAllCacheKeys
  • ...

and maybe more methods from the SpiceManager.

I'm pretty sure that comes from the same point: a binding problem.

My test case again:

A fragment that uses spiceManager.onStart(getActivity()); in onStart() and

if (spiceManager.isStarted()) {
            spiceManager.shouldStop();
        }

in onStop()

Now after getting my result successfully once, I lock my screen, unlock it and when coming back to the fragment (for instance), I try to refresh my data using some of the above methods and they don't work at all

I noticed these logs are missing whereas they appear when it works (refreshing before unlocking screen):

07-10 14:13:24.895: D//SpiceManager.java:1110(23854): 14:13:24.899 Thread-5230 Waiting for service to be bound.
07-10 14:13:24.895: D//SpiceManager.java:1117(23854): 14:13:24.900 Thread-5230 Bound ok.

@stephanenicolas
Copy link
Owner

Hi Mathieu,

Does it still happen with 1.4.6-snapshot ?
When you get the NPE, can we get the stack trace ?
Did you protect your fragment's nonstop method's call to spice
manager.should stop() (as explained in the starter guide , by checking that
the spice manager is started).

S.
Le 12 juil. 2013 09:42, "Mathieu Castets" [email protected] a
écrit :

I have also this problem with:

  • removeDataFromCache
  • getAllCacheKeys
  • ...

and maybe more methods from the SpiceManager.

I'm pretty sure that comes from the same point: a binding problem.

My test case again:

A fragment that use spiceManager.onStart(getActivity()); in onStart().
Now after getting my result successfully once, for instance, I lock my
screen, unlock it and when coming back to the fragment, going through
onStart() and onResume(), the above methods don't work (
NullPointerException or no errors for removeDataFromCache) and these logs
are missing:

07-10 14:13:24.895: D//SpiceManager.java:1110(23854): 14:13:24.899 Thread-5230 Waiting for service to be bound.
07-10 14:13:24.895: D//SpiceManager.java:1117(23854): 14:13:24.900 Thread-5230 Bound ok.


Reply to this email directly or view it on GitHubhttps://github.com//issues/128#issuecomment-20862764
.

@mcastets
Copy link
Author

Please see my message above on GitHub (#128 (comment)), I updated my message to be more accurate.

So yes, it still happen with 1.4.6-snapshot.
The NPE stacktrace is not related to RS as the NPE happens on the second line:

Future<List<Object>> f = getSpiceManager().getAllCacheKeys(ListSkills.class);
List<Object> l = f.get();

@mcastets
Copy link
Author

I managed to reproduce this issue with the robospice-sample-core-fragment sample.

I guess it will be easier for you, the RS team, to figure this tough bug out :-)

Here's the code:

I just add some code to the MainFragment.java

private void performRequest(String searchQuery) {
        resultTextView.setText("");

        MainFragment.this.getActivity().setProgressBarIndeterminateVisibility(true);

        ReverseStringRequest request = new ReverseStringRequest(searchQuery);

        // ADD
        clearSpecificCacheKey("dundee");
        // END

        spiceManager.execute(request, searchQuery, DurationInMillis.ALWAYS_RETURNED, new ReverseStringRequestListener());

        hideKeyboard();
    }
private void clearSpecificCacheKey(String cacheKey) {
        Log.d(TAG, "---------------------------------------");
        Log.d(TAG, "getAllCacheKeys");
        Log.d(TAG, "---------------------------------------");


        List<Object> listOfCacheKeys = null;

        try {
            // https://github.com/octo-online/robospice/issues/128
            Future<List<Object>> f = spiceManager.getAllCacheKeys(String.class);
            listOfCacheKeys = f.get();
        }
        catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for(Object key : listOfCacheKeys) {
            Log.d(TAG, key.toString());
        }

        Log.d(TAG, "Number of cache keys = " + listOfCacheKeys.size());

        Log.d(TAG, "---------------------------------------");
        Log.d(TAG, "RemoveDataFromCache -> " + cacheKey);
        Log.d(TAG, "---------------------------------------");

        // https://github.com/octo-online/robospice/issues/128
        spiceManager.removeDataFromCache(String.class, cacheKey);

        Log.d(TAG, "---------------------------------------");
        Log.d(TAG, "getAllCacheKeys");
        Log.d(TAG, "---------------------------------------");

        listOfCacheKeys = null;

        try {
            // https://github.com/octo-online/robospice/issues/128
            Future<List<Object>> f = spiceManager.getAllCacheKeys(String.class);
            listOfCacheKeys = f.get();
        }
        catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for(Object key : listOfCacheKeys) {
            Log.d(TAG, key.toString());
        }

        Log.d(TAG, "Number of cache keys = " + listOfCacheKeys.size());
    }

What I want to achieve, it will work in some cases:

  1. Type in "dundee"
  2. Hit the Reverse button
  3. "dundee" is stored in the cache
  4. Type in whatever you want

You can see the logs that prove it worked!

---------------------------------------
getAllCacheKeys
---------------------------------------
Number of cache keys = 1

---------------------------------------
RemoveDataFromCache -> dundee
---------------------------------------

---------------------------------------
getAllCacheKeys
---------------------------------------
Number of cache keys = 0

But now, a way to reproduce the bug:

  1. Lock your screen and unlock it
  2. Type in whatever you want
  3. Hit the Reverse button -> crash
---------------------------------------
getAllCacheKeys
---------------------------------------
FATAL EXCEPTION: main
java.lang.NullPointerException (on f.get())

Hope it helps,
Mathieu.

@stephanenicolas
Copy link
Owner

Bug is reproduced, thanks for this @Bobby-Jackson . I am working on that bug.

@stephanenicolas
Copy link
Owner

Thanks @Bobby-Jackson , that was a good one. A change introduced in 1.4.5 prevented the spiceManager from being restarted. The life cycle you proposed showed that pretty well. A bug fix is pending, a snapshot should be released within a few minutes to correct the bug.

Can you confirm it, please ?

@stephanenicolas
Copy link
Owner

Personal note : TODO : add a test to stop and restart a spicemanager.

Don't close the issue until it's done.

@mcastets
Copy link
Author

Bug is fixed, thanks a lot Stephane! This one drove me nuts!

@stephanenicolas
Copy link
Owner

Test added in commit 5d049b1.

Thanks for reporting it. That has been a real regression !

ajans pushed a commit to ajans/robospice that referenced this issue Dec 17, 2014
ajans pushed a commit to ajans/robospice that referenced this issue Dec 17, 2014
mcesar pushed a commit to project-draco-hr/robospice that referenced this issue Oct 2, 2016
mcesar pushed a commit to project-draco-hr/robospice that referenced this issue Oct 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants