svn commit: r929396 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r929396 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java

doogie-3
Author: doogie
Date: Wed Mar 31 06:09:14 2010
New Revision: 929396

URL: http://svn.apache.org/viewvc?rev=929396&view=rev
Log:
Add tests for the file store feature.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java?rev=929396&r1=929395&r2=929396&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java Wed Mar 31 06:09:14 2010
@@ -240,6 +240,81 @@ public class UtilCacheTests extends Gene
         assertEquals("values", Collections.emptyList(), cache.values());
     }
 
+    public void testBasicDisk() throws Exception {
+        UtilCache<String, String> cache = createUtilCache(0, 0, 0, false, true);
+        Listener<String, String> gotListener = createListener(cache);
+        Listener<String, String> wantedListener = new Listener<String, String>();
+        for (int i = 0; i < 2; i++) {
+            assertTrue("UtilCacheTable.keySet", UtilCache.getUtilCacheTableKeySet().contains(cache.getName()));
+            assertSame("UtilCache.findCache", cache, UtilCache.findCache(cache.getName()));
+            assertSame("UtilCache.getOrCreateUtilCache", cache, UtilCache.getOrCreateUtilCache(cache.getName(), cache.getMaxSize(), cache.getMaxInMemory(), cache.getExpireTime(), cache.getUseSoftReference(), cache.getUseFileSystemStore()));
+
+            assertNoSingleKey(cache, "one");
+            long origByteSize = cache.getSizeInBytes();
+
+            /*
+            wantedListener.noteKeyAddition(cache, null, "null");
+            assertNull("put", cache.put(null, "null"));
+            assertHasSingleKey(cache, null, "null");
+            long nullByteSize = cache.getSizeInBytes();
+            assertThat(nullByteSize, greaterThan(origByteSize));
+
+            wantedListener.noteKeyRemoval(cache, null, "null");
+            assertEquals("remove", "null", cache.remove(null));
+            assertNoSingleKey(cache, null);
+            */
+
+            wantedListener.noteKeyAddition(cache, "one", "uno");
+            assertNull("put", cache.put("one", "uno"));
+            assertHasSingleKey(cache, "one", "uno");
+            long unoByteSize = cache.getSizeInBytes();
+            assertThat(unoByteSize, greaterThan(origByteSize));
+
+            wantedListener.noteKeyUpdate(cache, "one", "single", "uno");
+            assertEquals("replace", "uno", cache.put("one", "single"));
+            assertHasSingleKey(cache, "one", "single");
+            long singleByteSize = cache.getSizeInBytes();
+            assertThat(singleByteSize, greaterThan(origByteSize));
+            assertThat(singleByteSize, greaterThan(unoByteSize));
+
+            wantedListener.noteKeyRemoval(cache, "one", "single");
+            assertEquals("remove", "single", cache.remove("one"));
+            assertNoSingleKey(cache, "one");
+            assertEquals("byteSize", origByteSize, cache.getSizeInBytes());
+
+            wantedListener.noteKeyAddition(cache, "one", "uno");
+            assertNull("put", cache.put("one", "uno"));
+            assertHasSingleKey(cache, "one", "uno");
+
+            wantedListener.noteKeyUpdate(cache, "one", "only", "uno");
+            assertEquals("replace", "uno", cache.put("one", "only"));
+            assertHasSingleKey(cache, "one", "only");
+
+            wantedListener.noteKeyRemoval(cache, "one", "only");
+            assertEquals("remove", "only", cache.remove("one"));
+            assertNoSingleKey(cache, "one");
+            assertEquals("byteSize", origByteSize, cache.getSizeInBytes());
+
+            cache.setExpireTime(100);
+            wantedListener.noteKeyAddition(cache, "one", "uno");
+            assertNull("put", cache.put("one", "uno"));
+            assertHasSingleKey(cache, "one", "uno");
+
+            wantedListener.noteKeyRemoval(cache, "one", "uno");
+            Thread.sleep(200);
+            assertNoSingleKey(cache, "one");
+        }
+
+        assertEquals("get-miss", 8, cache.getMissCountNotFound());
+        assertEquals("get-miss-total", 8, cache.getMissCountTotal());
+        assertEquals("get-hit", 20, cache.getHitCount());
+        assertEquals("remove-hit", 4, cache.getRemoveHitCount());
+        assertEquals("remove-miss", 8, cache.getRemoveMissCount());
+        cache.removeListener(gotListener);
+        assertEquals("listener", wantedListener, gotListener);
+        cache.clear();
+    }
+
     public void testSimple() throws Exception {
         UtilCache<String, String> cache = createUtilCache(5, 0, 0, false, false);
         Listener<String, String> gotListener = createListener(cache);