From 349055aad47184b72cd86de1f37ac1b7557d2e70 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Wed, 17 Nov 2010 09:47:36 -0800 Subject: [PATCH] Allow ProviderTests to work with ContentCache Bug: 3204331 Change-Id: I5399345c2b759fb34d3dc7c694eb0eef8d7de493 --- .../android/email/provider/ContentCache.java | 24 +++++++++++-------- .../android/email/provider/ProviderTests.java | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/com/android/email/provider/ContentCache.java b/src/com/android/email/provider/ContentCache.java index 89b107b49..13d708fea 100644 --- a/src/com/android/email/provider/ContentCache.java +++ b/src/com/android/email/provider/ContentCache.java @@ -68,10 +68,12 @@ import java.util.Set; public final class ContentCache extends LinkedHashMap { private static final long serialVersionUID = 1L; - private static final boolean DEBUG_CACHE = false; - private static final boolean DEBUG_TOKENS = false; - private static final boolean DEBUG_NOT_CACHEABLE = false; - private static final boolean DEBUG_NO_OBJECTS_IN_CACHE = false; + private static final boolean DEBUG_CACHE = false; // DO NOT CHECK IN TRUE + private static final boolean DEBUG_TOKENS = false; // DO NOT CHECK IN TRUE + private static final boolean DEBUG_NOT_CACHEABLE = false; // DO NOT CHECK IN TRUE + + // If false, reads will not use the cache; this is intended for debugging only + private static final boolean READ_CACHE_ENABLED = true; // DO NOT CHECK IN FALSE // Count of non-cacheable queries (debug only) private static int sNotCacheable = 0; @@ -228,15 +230,10 @@ public final class ContentCache extends LinkedHashMap { public static final class CacheToken { private static final long serialVersionUID = 1L; private final String mId; - private boolean mIsValid = true; + private boolean mIsValid = READ_CACHE_ENABLED; /*package*/ CacheToken(String id) { mId = id; - // For debugging purposes only, this will cause all items to be rejected (as though - // there is no cache.) - if (DEBUG_NO_OBJECTS_IN_CACHE) { - mIsValid = false; - } } /*package*/ String getId() { @@ -718,6 +715,13 @@ public final class ContentCache extends LinkedHashMap { } } + // For use with unit tests + public static void invalidateAllCachesForTest() { + for (ContentCache cache: sContentCaches) { + cache.invalidate(); + } + } + static class Statistics { private final ContentCache mCache; private final String mName; diff --git a/tests/src/com/android/email/provider/ProviderTests.java b/tests/src/com/android/email/provider/ProviderTests.java index f1863668c..65677beae 100644 --- a/tests/src/com/android/email/provider/ProviderTests.java +++ b/tests/src/com/android/email/provider/ProviderTests.java @@ -73,6 +73,8 @@ public class ProviderTests extends ProviderTestCase2 { public void setUp() throws Exception { super.setUp(); mMockContext = getMockContext(); + // Invalidate all caches, since we reset the database for each test + ContentCache.invalidateAllCachesForTest(); } @Override