* CachedBdbMap.java
    remove debug output
* TestUtils.java
    add info logging
* CachedBdbMapTest.java
    make more robust against prior heap usage, different platforms
This commit is contained in:
gojomo
2009-08-04 06:55:31 +00:00
parent 4f0961c371
commit 272ae19961
3 changed files with 10 additions and 4 deletions
@@ -384,7 +384,6 @@ implements ConcurrentMap<K,V>, Serializable {
logger.info("BdbConfiguration: Cache percentage " +
cfg.getCachePercent() + ", cache size " + cfg.getCacheSize() +
", Map size: " + size() + " cfg=" + cfg);
System.out.println(" cfg=" + cfg); //DEBUG
}
}
@@ -28,6 +28,7 @@ import java.io.ObjectOutputStream;
import java.lang.ref.SoftReference;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.logging.Logger;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -39,6 +40,8 @@ import junit.framework.TestSuite;
* @author gojomo
*/
public class TestUtils {
private static final Logger logger =
Logger.getLogger(TestUtils.class.getName());
/**
* Temporarily exhaust memory, forcing weak/soft references to
@@ -48,17 +51,18 @@ public class TestUtils {
// force soft references to be broken
LinkedList<SoftReference<byte[]>> hog = new LinkedList<SoftReference<byte[]>>();
long blocks = Runtime.getRuntime().maxMemory() / 1000000;
logger.info("forcing scarce memory via "+blocks+" 1MB blocks");
for(long l = 0; l <= blocks; l++) {
try {
hog.add(new SoftReference<byte[]>(new byte[1000000]));
} catch (OutOfMemoryError e) {
hog = null;
logger.info("OOME triggered");
break;
}
}
}
public static void testSerialization(Object proc) throws Exception {
byte[] first = serialize(proc);
ByteArrayInputStream binp = new ByteArrayInputStream(first);
@@ -89,11 +89,14 @@ public class CachedBdbMapTest extends TmpDirTestCase {
*
* NOTE: this test may be especially fragile with regard to
* GC/timing issues; relies on timely finalization, which is
* never guaranteed by JVM/GC.
* never guaranteed by JVM/GC. For example, it is so sensitive
* to CPU speed that a Thread.sleep(1000) succeeds when my
* laptop is plugged in, but fails when it is on battery!
*
* @throws InterruptedException
*/
public void testMemMapCleared() throws InterruptedException {
System.gc(); // minimize effects of earlier test heap use
assertEquals(cache.memMap.size(), 0);
for(int i=0; i < 10000; i++) {
cache.putIfAbsent(""+i, new HashMap<String,String>());
@@ -101,7 +104,7 @@ public class CachedBdbMapTest extends TmpDirTestCase {
assertEquals(cache.memMap.size(), 10000);
assertEquals(cache.size(), 10000);
TestUtils.forceScarceMemory();
Thread.sleep(1000);
Thread.sleep(2000);
// The 'canary' trick makes this explicit expunge, or
// an expunge triggered by a get() or put...(), unnecessary
// cache.expungeStaleEntries();