mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-10-07 12:51:21 +00:00
copy 'springy' branch to heritrix3
This commit is contained in:
commit
e047bf68e0
966 files changed
+124796
No files matched your search
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file is part of the Heritrix web crawler (crawler.archive.org).
|
||||
*
|
||||
* Licensed to the Internet Archive (IA) by one or more individual
|
||||
* contributors.
|
||||
*
|
||||
* The IA licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.archive.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
/**
|
||||
* @author stack
|
||||
* @version $Date$, $Revision$
|
||||
*/
|
||||
public class CachedBdbMapTest extends TmpDirTestCase {
|
||||
File envDir;
|
||||
private CachedBdbMap<String,HashMap<String,String>> cache;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.envDir = new File(getTmpDir(),"CachedBdbMapTest");
|
||||
this.envDir.mkdirs();
|
||||
this.cache = new CachedBdbMap(this.envDir,
|
||||
this.getClass().getName(), String.class, HashMap.class);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
this.cache.close();
|
||||
FileUtils.deleteDirectory(this.envDir);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testBackingDbGetsUpdated() {
|
||||
// Enable all logging. Up the level on the handlers and then
|
||||
// on the big map itself.
|
||||
Handler [] handlers = Logger.getLogger("").getHandlers();
|
||||
for (int index = 0; index < handlers.length; index++) {
|
||||
handlers[index].setLevel(Level.FINEST);
|
||||
}
|
||||
Logger.getLogger(CachedBdbMap.class.getName()).
|
||||
setLevel(Level.FINEST);
|
||||
// Set up values.
|
||||
final String value = "value";
|
||||
final String key = "key";
|
||||
final int upperbound = 3;
|
||||
// First put in empty hashmap.
|
||||
for (int i = 0; i < upperbound; i++) {
|
||||
this.cache.put(key + Integer.toString(i), new HashMap<String,String>());
|
||||
}
|
||||
// Now add value to hash map.
|
||||
for (int i = 0; i < upperbound; i++) {
|
||||
HashMap<String,String> m = this.cache.get(key + Integer.toString(i));
|
||||
m.put(key, value);
|
||||
}
|
||||
this.cache.sync();
|
||||
for (int i = 0; i < upperbound; i++) {
|
||||
HashMap<String,String> m = this.cache.get(key + Integer.toString(i));
|
||||
String v = m.get(key);
|
||||
if (v == null || !v.equals(value)) {
|
||||
Logger.getLogger(CachedBdbMap.class.getName()).
|
||||
warning("Wrong value " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String [] args) {
|
||||
junit.textui.TestRunner.run(CachedBdbMapTest.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user