1 23 package org.archive.util; 24 25 import java.util.HashMap ; 26 import java.util.logging.Handler ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 30 34 public class CachedBdbMapTest extends TmpDirTestCase { 35 private CachedBdbMap<String ,HashMap <String ,String >> cache; 36 37 @SuppressWarnings ("unchecked") 38 protected void setUp() throws Exception { 39 super.setUp(); 40 this.cache = new CachedBdbMap(getTmpDir(), 41 this.getClass().getName(), String .class, HashMap .class); 42 } 43 44 protected void tearDown() throws Exception { 45 this.cache.close(); 46 super.tearDown(); 47 } 48 49 public void testBackingDbGetsUpdated() { 50 Handler [] handlers = Logger.getLogger("").getHandlers(); 53 for (int index = 0; index < handlers.length; index++) { 54 handlers[index].setLevel(Level.FINEST); 55 } 56 Logger.getLogger(CachedBdbMap.class.getName()). 57 setLevel(Level.FINEST); 58 final String value = "value"; 60 final String key = "key"; 61 final int upperbound = 3; 62 for (int i = 0; i < upperbound; i++) { 64 this.cache.put(key + Integer.toString(i), new HashMap <String ,String >()); 65 } 66 for (int i = 0; i < upperbound; i++) { 68 HashMap <String ,String > m = this.cache.get(key + Integer.toString(i)); 69 m.put(key, value); 70 } 71 this.cache.sync(); 72 for (int i = 0; i < upperbound; i++) { 73 HashMap <String ,String > m = this.cache.get(key + Integer.toString(i)); 74 String v = m.get(key); 75 if (v == null || !v.equals(value)) { 76 Logger.getLogger(CachedBdbMap.class.getName()). 77 warning("Wrong value " + i); 78 } 79 } 80 } 81 82 public static void main(String [] args) { 83 junit.textui.TestRunner.run(CachedBdbMapTest.class); 84 } 85 } 86 | Popular Tags |