summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2009-06-11 17:24:53 -0700
committerOwen Lin <owenlin@google.com>2009-06-11 19:47:28 -0700
commit0e9396270cfe12cf7a3804103db5f69cb76c2af5 (patch)
tree9a75799d1284558c6a8a291394884039eaa7ef17 /tests
parent6cc6daff9d7cb02805cd9ce71176c7b49655f8a8 (diff)
downloadLegacyCamera-0e9396270cfe12cf7a3804103db5f69cb76c2af5.zip
LegacyCamera-0e9396270cfe12cf7a3804103db5f69cb76c2af5.tar.gz
LegacyCamera-0e9396270cfe12cf7a3804103db5f69cb76c2af5.tar.bz2
fix bug 1909589 and 1903635. I think the cause root is that the LruCache is not
thread safe. I change it to thread safe and add a test for this.
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/camera/gallery/LruCacheUnitTests.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/src/com/android/camera/gallery/LruCacheUnitTests.java b/tests/src/com/android/camera/gallery/LruCacheUnitTests.java
index f699724..003fdd7 100644
--- a/tests/src/com/android/camera/gallery/LruCacheUnitTests.java
+++ b/tests/src/com/android/camera/gallery/LruCacheUnitTests.java
@@ -1,6 +1,7 @@
package com.android.camera.gallery;
import android.test.AndroidTestCase;
+import android.util.Log;
public class LruCacheUnitTests extends AndroidTestCase {
@@ -34,4 +35,40 @@ public class LruCacheUnitTests extends AndroidTestCase {
System.gc();
assertEquals(Integer.valueOf(0), cache.get(0));
}
+
+ private static final int TEST_COUNT = 10000;
+
+ static class Accessor extends Thread {
+ private final LruCache<Integer,Integer> mMap;
+
+ public Accessor(LruCache<Integer, Integer> map) {
+ mMap = map;
+ }
+
+ @Override
+ public void run() {
+ Log.v("TAG", "start get " + this);
+ for (int i = 0; i < TEST_COUNT; ++i) {
+ mMap.get(i % 2);
+ }
+ Log.v("TAG", "finish get " + this);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testConcurrentAccess() throws Exception {
+ LruCache<Integer, Integer> cache = new LruCache<Integer, Integer>(4);
+ cache.put(0, 0);
+ cache.put(1, 1);
+ Accessor accessor[] = new Accessor[4];
+ for (int i = 0; i < accessor.length; ++i) {
+ accessor[i] = new Accessor(cache);
+ }
+ for (int i = 0; i < accessor.length; ++i) {
+ accessor[i].start();
+ }
+ for (int i = 0; i < accessor.length; ++i) {
+ accessor[i].join();
+ }
+ }
}