1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.util;
24
25 import java.io.File;
26 import java.util.HashMap;
27 import java.util.logging.Handler;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30
31 /***
32 * @author stack
33 * @version $Date: 2007-02-22 01:15:06 +0000 (Thu, 22 Feb 2007) $, $Revision: 4932 $
34 */
35 public class CachedBdbMapTest extends TmpDirTestCase {
36 File envDir;
37 private CachedBdbMap<String,HashMap<String,String>> cache;
38
39 @SuppressWarnings("unchecked")
40 protected void setUp() throws Exception {
41 super.setUp();
42 this.envDir = new File(getTmpDir(),"CachedBdbMapTest");
43 this.envDir.mkdirs();
44 this.cache = new CachedBdbMap(this.envDir,
45 this.getClass().getName(), String.class, HashMap.class);
46 }
47
48 protected void tearDown() throws Exception {
49 this.cache.close();
50 FileUtils.deleteDir(this.envDir);
51 super.tearDown();
52 }
53
54 public void testBackingDbGetsUpdated() {
55
56
57 Handler [] handlers = Logger.getLogger("").getHandlers();
58 for (int index = 0; index < handlers.length; index++) {
59 handlers[index].setLevel(Level.FINEST);
60 }
61 Logger.getLogger(CachedBdbMap.class.getName()).
62 setLevel(Level.FINEST);
63
64 final String value = "value";
65 final String key = "key";
66 final int upperbound = 3;
67
68 for (int i = 0; i < upperbound; i++) {
69 this.cache.put(key + Integer.toString(i), new HashMap<String,String>());
70 }
71
72 for (int i = 0; i < upperbound; i++) {
73 HashMap<String,String> m = this.cache.get(key + Integer.toString(i));
74 m.put(key, value);
75 }
76 this.cache.sync();
77 for (int i = 0; i < upperbound; i++) {
78 HashMap<String,String> m = this.cache.get(key + Integer.toString(i));
79 String v = m.get(key);
80 if (v == null || !v.equals(value)) {
81 Logger.getLogger(CachedBdbMap.class.getName()).
82 warning("Wrong value " + i);
83 }
84 }
85 }
86
87 public static void main(String [] args) {
88 junit.textui.TestRunner.run(CachedBdbMapTest.class);
89 }
90 }