1 7 package org.jboss.cache.loader; 8 9 import junit.textui.TestRunner; 10 import org.jboss.cache.CacheImpl; 11 12 17 public class CacheLoaderMethodCallCounterTest extends AbstractCacheLoaderTestBase 18 { 19 private CacheImpl cache; 20 private DummyCacheLoader dummyLoader; 21 22 public static void main(String [] args) 23 { 24 TestRunner.run(CacheLoaderMethodCallCounterTest.class); 25 } 26 27 protected void setUp() throws Exception 28 { 29 if (cache != null) tearDown(); 30 cache = new CacheImpl(); 31 cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, false)); 32 cache.start(); 33 dummyLoader = (DummyCacheLoader) cache.getCacheLoaderManager().getCacheLoader(); 34 } 35 36 protected void tearDown() 37 { 38 if (cache != null) 39 cache.stop(); 40 cache.destroy(); 41 cache = null; 42 } 43 44 45 public void testPut() throws Exception 46 { 47 cache.put("/node", "key", "value"); 48 printReport("putKeyValue", dummyLoader); 49 } 50 51 public void testGet() throws Exception 52 { 53 cache.get("/node", "key"); 54 printReport("getKey", dummyLoader); 55 } 56 57 public void testRemove() throws Exception 58 { 59 cache.remove("/node", "key"); 60 printReport("removeKey", dummyLoader); 61 } 62 63 private void printReport(String test, DummyCacheLoader d) 64 { 65 System.out.println("------------------------------"); 66 System.out.println(" Test name: " + test); 67 System.out.println(" cache loader stats:"); 68 System.out.println(" put count: " + d.getPutCount()); 69 System.out.println(" get count: " + d.getGetCount()); 70 System.out.println(" exists count: " + d.getExistsCount()); 71 System.out.println(" remove count: " + d.getRemoveCount()); 72 System.out.println(" getChildrenNames count: " + d.getGetChildrenNamesCount()); 73 System.out.println("------------------------------"); 74 } 75 76 public void testLoopedGets() throws Exception 77 { 78 cache.put("/test", "key", "value"); 80 81 assertEquals(1, dummyLoader.getPutCount()); 83 assertEquals(0, dummyLoader.getGetCount()); 85 86 for (int i = 0; i < 2000; i++) 87 { 88 cache.get("/test"); 89 } 90 91 assertEquals(1, dummyLoader.getPutCount()); 92 assertEquals(1, dummyLoader.getGetCount()); 93 assertEquals(0, dummyLoader.getRemoveCount()); 94 assertEquals(0, dummyLoader.getExistsCount()); 95 } 96 } 97 | Popular Tags |