Repository: incubator-blur Updated Branches: refs/heads/master 0e49bdbbc -> f1c6c6024
Fixing cache server test. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/f1c6c602 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/f1c6c602 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/f1c6c602 Branch: refs/heads/master Commit: f1c6c602462df7719c435553c43b15dc6c443a23 Parents: 0e49bdb Author: Aaron McCurry <[email protected]> Authored: Thu Feb 26 14:03:48 2015 -0500 Committer: Aaron McCurry <[email protected]> Committed: Thu Feb 26 14:03:48 2015 -0500 ---------------------------------------------------------------------- .../apache/blur/server/cache/ThriftCache.java | 22 +++-- .../server/cache/ThriftCacheServerTest.java | 93 ++++++++------------ 2 files changed, 52 insertions(+), 63 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f1c6c602/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java b/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java index f3940fb..e4b428c 100644 --- a/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java +++ b/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import org.apache.blur.log.Log; import org.apache.blur.log.LogFactory; @@ -49,6 +50,9 @@ public class ThriftCache { private final Meter _hits; private final Meter _misses; private final Meter _evictions; + private final AtomicLong _hitsAtomicLong; + private final AtomicLong _missesAtomicLong; + private final AtomicLong _evictionsAtomicLong; public ThriftCache(long totalNumberOfBytes) { _hits = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, THRIFT_CACHE, HIT), HIT, TimeUnit.SECONDS); @@ -64,8 +68,12 @@ public class ThriftCache { @Override public void onEviction(ThriftCacheKey<?> key, ThriftCacheValue<?> value) { _evictions.mark(); + _evictionsAtomicLong.incrementAndGet(); } }).maximumWeightedCapacity(totalNumberOfBytes).build(); + _hitsAtomicLong = new AtomicLong(); + _missesAtomicLong = new AtomicLong(); + _evictionsAtomicLong = new AtomicLong(); } public <K extends TBase<?, ?>, V extends TBase<?, ?>> V put(ThriftCacheKey<K> key, V t) throws BlurException { @@ -80,10 +88,12 @@ public class ThriftCache { if (value == null) { LOG.debug("Cache Miss for [{0}]", key); _misses.mark(); + _missesAtomicLong.incrementAndGet(); return null; } LOG.debug("Cache Hit for [{0}]", key); _hits.mark(); + _hitsAtomicLong.incrementAndGet(); return value.getValue(clazz); } @@ -113,16 +123,16 @@ public class ThriftCache { return _cacheMap.weightedSize(); } - public Meter getHits() { - return _hits; + public long getHits() { + return _hitsAtomicLong.get(); } - public Meter getMisses() { - return _misses; + public long getMisses() { + return _missesAtomicLong.get(); } - public Meter getEvictions() { - return _evictions; + public long getEvictions() { + return _evictionsAtomicLong.get(); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f1c6c602/blur-core/src/test/java/org/apache/blur/server/cache/ThriftCacheServerTest.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/server/cache/ThriftCacheServerTest.java b/blur-core/src/test/java/org/apache/blur/server/cache/ThriftCacheServerTest.java index 6f9b20d..33accc3 100644 --- a/blur-core/src/test/java/org/apache/blur/server/cache/ThriftCacheServerTest.java +++ b/blur-core/src/test/java/org/apache/blur/server/cache/ThriftCacheServerTest.java @@ -16,7 +16,8 @@ */ package org.apache.blur.server.cache; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.IOException; import java.util.ArrayList; @@ -53,8 +54,6 @@ import org.apache.blur.thrift.generated.User; import org.junit.Before; import org.junit.Test; -import com.yammer.metrics.core.Meter; - public class ThriftCacheServerTest { private BlurConfiguration _configuration; @@ -73,27 +72,23 @@ public class ThriftCacheServerTest { @Test public void testQuery() throws IOException, BlurException, TException { _thriftCache.clear(); - Meter misses = _thriftCache.getMisses(); - long currentMisses = misses.count(); - Meter hits = _thriftCache.getHits(); - long currentHits = misses.count(); - assertEquals(0 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(0, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); BlurQuery blurQuery1 = new BlurQuery(); blurQuery1.setUserContext("user1"); BlurResults blurResults1 = _thriftCacheServer.query(_table, blurQuery1); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); BlurQuery blurQuery2 = new BlurQuery(); blurQuery1.setUserContext("user2"); BlurResults blurResults2 = _thriftCacheServer.query(_table, blurQuery2); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(1 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(1, _thriftCache.getHits()); assertFalse(blurResults1 == blurResults2); assertEquals(blurResults1, blurResults2); @@ -102,23 +97,19 @@ public class ThriftCacheServerTest { @Test public void testTableStats() throws IOException, BlurException, TException { _thriftCache.clear(); - Meter misses = _thriftCache.getMisses(); - long currentMisses = misses.count(); - Meter hits = _thriftCache.getHits(); - long currentHits = misses.count(); - assertEquals(0 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(0, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); TableStats tableStats1 = _thriftCacheServer.tableStats(_table); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); TableStats tableStats2 = _thriftCacheServer.tableStats(_table); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(1 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(1, _thriftCache.getHits()); assertFalse(tableStats1 == tableStats2); assertEquals(tableStats1, tableStats2); @@ -127,27 +118,23 @@ public class ThriftCacheServerTest { @Test public void testFetchRow() throws BlurException, TException { _thriftCache.clear(); - Meter misses = _thriftCache.getMisses(); - long currentMisses = misses.count(); - Meter hits = _thriftCache.getHits(); - long currentHits = misses.count(); - assertEquals(0 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(0, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); Selector selector1 = new Selector(); selector1.setLocationId("1"); FetchResult fetchRow1 = _thriftCacheServer.fetchRow(_table, selector1); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); Selector selector2 = new Selector(); selector2.setLocationId("1"); FetchResult fetchRow2 = _thriftCacheServer.fetchRow(_table, selector2); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(1 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(1, _thriftCache.getHits()); assertFalse(fetchRow1 == fetchRow2); assertEquals(fetchRow1, fetchRow2); @@ -156,27 +143,23 @@ public class ThriftCacheServerTest { @Test public void testFetchRowBatch1() throws BlurException, TException { _thriftCache.clear(); - Meter misses = _thriftCache.getMisses(); - long currentMisses = misses.count(); - Meter hits = _thriftCache.getHits(); - long currentHits = misses.count(); - assertEquals(0 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(0, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); Selector selector1 = new Selector(); selector1.setLocationId("1"); List<FetchResult> fetchRowBatch1 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector1)); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); Selector selector2 = new Selector(); selector2.setLocationId("1"); List<FetchResult> fetchRowBatch2 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector2)); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(1 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(1, _thriftCache.getHits()); assertFalse(fetchRowBatch1 == fetchRowBatch2); assertEquals(fetchRowBatch1, fetchRowBatch2); @@ -185,27 +168,23 @@ public class ThriftCacheServerTest { @Test public void testFetchRowBatch2() throws BlurException, TException { _thriftCache.clear(); - Meter misses = _thriftCache.getMisses(); - long currentMisses = misses.count(); - Meter hits = _thriftCache.getHits(); - long currentHits = misses.count(); - assertEquals(0 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(0, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); Selector selector1 = new Selector(); selector1.setLocationId("1"); List<FetchResult> fetchRowBatch1 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector1)); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(0 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(0, _thriftCache.getHits()); Selector selector2 = new Selector(); selector2.setLocationId("1"); List<FetchResult> fetchRowBatch2 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector2)); - assertEquals(1 + currentMisses, misses.count()); - assertEquals(1 + currentHits, hits.count()); + assertEquals(1, _thriftCache.getMisses()); + assertEquals(1, _thriftCache.getHits()); assertFalse(fetchRowBatch1 == fetchRowBatch2); assertEquals(fetchRowBatch1, fetchRowBatch2); @@ -215,17 +194,17 @@ public class ThriftCacheServerTest { List<FetchResult> fetchRowBatch3 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector1, selector3)); // one miss for the non cached selector - assertEquals(2 + currentMisses, misses.count()); + assertEquals(2, _thriftCache.getMisses()); // one hit for the cached selector - assertEquals(2 + currentHits, hits.count()); + assertEquals(2, _thriftCache.getHits()); Selector selector4 = new Selector(); selector4.setLocationId("2"); List<FetchResult> fetchRowBatch4 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector2, selector4)); - assertEquals(2 + currentMisses, misses.count()); + assertEquals(2, _thriftCache.getMisses()); // two hits for the cached selectors - assertEquals(4 + currentHits, hits.count()); + assertEquals(4, _thriftCache.getHits()); assertFalse(fetchRowBatch3 == fetchRowBatch4); assertEquals(fetchRowBatch3, fetchRowBatch4);
