HBASE-8547 Fix java.lang.RuntimeException: Cached an already cached block

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1482697 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Enis Soztutar 2013-05-15 06:57:37 +00:00
parent cb53db35f3
commit ba37032a72
3 changed files with 9 additions and 5 deletions

View File

@ -292,7 +292,9 @@ public class LruBlockCache implements BlockCache, HeapSize {
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory) {
CachedBlock cb = map.get(cacheKey);
if(cb != null) {
throw new RuntimeException("Cached an already cached block");
String msg = "Cached an already cached block: " + cacheKey + " cb:" + cb.getCacheKey();
LOG.warn(msg);
assert false : msg;
}
cb = new CachedBlock(cacheKey, buf, count.incrementAndGet(), inMemory);
long newSize = updateSizeMetrics(cb, false);

View File

@ -123,8 +123,9 @@ public class TestLruBlockCache {
try {
cache.cacheBlock(block.cacheKey, block);
assertTrue("Cache should not allow re-caching a block", false);
} catch(RuntimeException re) {
} catch(AssertionError re) {
// expected
assertTrue(re.getMessage().contains("Cached an already cached block"));
}
}

View File

@ -19,6 +19,8 @@
package org.apache.hadoop.hbase.util;
import static org.junit.Assert.assertTrue;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.Callable;
@ -27,12 +29,10 @@ import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.junit.Assert.*;
import org.apache.hadoop.hbase.MediumTests;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@ -105,6 +105,7 @@ public class TestIdLock {
idLock.assertMapEmpty();
} finally {
exec.shutdown();
exec.awaitTermination(5000, TimeUnit.MILLISECONDS);
}
}