KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > util > CachedBdbMapTest


1 /* CachedBdbMapTest
2  *
3  * Created on Apr 11, 2005
4  *
5  * Copyright (C) 2005 Internet Archive.
6  *
7  * This file is part of the Heritrix web crawler (crawler.archive.org).
8  *
9  * Heritrix is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * any later version.
13  *
14  * Heritrix is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser Public License
20  * along with Heritrix; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23 package org.archive.util;
24
25 import java.util.HashMap JavaDoc;
26 import java.util.logging.Handler JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30 /**
31  * @author stack
32  * @version $Date: 2007/01/13 01:31:39 $, $Revision: 1.2.16.1 $
33  */

34 public class CachedBdbMapTest extends TmpDirTestCase {
35     private CachedBdbMap<String JavaDoc,HashMap JavaDoc<String JavaDoc,String JavaDoc>> cache;
36     
37     @SuppressWarnings JavaDoc("unchecked")
38     protected void setUp() throws Exception JavaDoc {
39         super.setUp();
40         this.cache = new CachedBdbMap(getTmpDir(),
41             this.getClass().getName(), String JavaDoc.class, HashMap JavaDoc.class);
42     }
43     
44     protected void tearDown() throws Exception JavaDoc {
45         this.cache.close();
46         super.tearDown();
47     }
48     
49     public void testBackingDbGetsUpdated() {
50         // Enable all logging. Up the level on the handlers and then
51
// on the big map itself.
52
Handler JavaDoc [] 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         // Set up values.
59
final String JavaDoc value = "value";
60         final String JavaDoc key = "key";
61         final int upperbound = 3;
62         // First put in empty hashmap.
63
for (int i = 0; i < upperbound; i++) {
64             this.cache.put(key + Integer.toString(i), new HashMap JavaDoc<String JavaDoc,String JavaDoc>());
65         }
66         // Now add value to hash map.
67
for (int i = 0; i < upperbound; i++) {
68             HashMap JavaDoc<String JavaDoc,String JavaDoc> 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 JavaDoc<String JavaDoc,String JavaDoc> m = this.cache.get(key + Integer.toString(i));
74             String JavaDoc 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 JavaDoc [] args) {
83         junit.textui.TestRunner.run(CachedBdbMapTest.class);
84     }
85 }
86
Popular Tags