From e0707033c5a5c63fd044a59e7ee4055453334a01 Mon Sep 17 00:00:00 2001 From: Jay J Wylie Date: Mon, 8 Oct 2012 19:20:18 -0700 Subject: [PATCH] Clean up get stats methods in (Queued)KeyedResourcePool. Fix error in test case. --- .../utils/pool/KeyedResourcePool.java | 54 +++++++++---------- .../utils/pool/QueuedKeyedResourcePool.java | 20 ++++--- .../store/memory/SlowStorageEngineTest.java | 4 +- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/java/voldemort/utils/pool/KeyedResourcePool.java b/src/java/voldemort/utils/pool/KeyedResourcePool.java index c6056ebc6b..e71c582b74 100644 --- a/src/java/voldemort/utils/pool/KeyedResourcePool.java +++ b/src/java/voldemort/utils/pool/KeyedResourcePool.java @@ -297,17 +297,15 @@ public synchronized void reset(K key) { * given key. */ public int getTotalResourceCount(K key) { - int rc = 0; - if(!resourcePoolMap.containsKey(key)) { - return rc; - } - try { - Pool resourcePool = getResourcePoolForExistingKey(key); - rc = resourcePool.size.get(); - } catch(IllegalArgumentException iae) { - logger.debug("getTotalResourceCount called on invalid key: ", iae); + if(resourcePoolMap.containsKey(key)) { + try { + Pool resourcePool = getResourcePoolForExistingKey(key); + return resourcePool.size.get(); + } catch(IllegalArgumentException iae) { + logger.debug("getTotalResourceCount called on invalid key: ", iae); + } } - return rc; + return 0; } /** @@ -332,17 +330,15 @@ public int getTotalResourceCount() { * for given key. */ public int getCheckedInResourcesCount(K key) { - int rc = 0; - if(!resourcePoolMap.containsKey(key)) { - return rc; - } - try { - Pool resourcePool = getResourcePoolForExistingKey(key); - rc = resourcePool.queue.size(); - } catch(IllegalArgumentException iae) { - logger.debug("getCheckedInResourceCount called on invalid key: ", iae); + if(resourcePoolMap.containsKey(key)) { + try { + Pool resourcePool = getResourcePoolForExistingKey(key); + return resourcePool.queue.size(); + } catch(IllegalArgumentException iae) { + logger.debug("getCheckedInResourceCount called on invalid key: ", iae); + } } - return rc; + return 0; } /** @@ -367,17 +363,15 @@ public int getCheckedInResourceCount() { * key. */ public int getBlockingGetsCount(K key) { - int rc = 0; - if(!resourcePoolMap.containsKey(key)) { - return rc; - } - try { - Pool resourcePool = getResourcePoolForExistingKey(key); - rc = resourcePool.blockingGets.get(); - } catch(IllegalArgumentException iae) { - logger.debug("getBlockingGetsCount called on invalid key: ", iae); + if(resourcePoolMap.containsKey(key)) { + try { + Pool resourcePool = getResourcePoolForExistingKey(key); + return resourcePool.blockingGets.get(); + } catch(IllegalArgumentException iae) { + logger.debug("getBlockingGetsCount called on invalid key: ", iae); + } } - return rc; + return 0; } /** diff --git a/src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java b/src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java index 783030be7f..2d12f34722 100644 --- a/src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java +++ b/src/java/voldemort/utils/pool/QueuedKeyedResourcePool.java @@ -329,18 +329,16 @@ protected Queue> getRequestQueueForExistingKey(K key) { * exists for given key. */ public int getRegisteredResourceRequestCount(K key) { - int rc = 0; - if(!requestQueueMap.containsKey(key)) { - return rc; - } - try { - Queue> requestQueue = getRequestQueueForExistingKey(key); - // FYI: .size() is not constant time in the next call. ;) - rc = requestQueue.size(); - } catch(IllegalArgumentException iae) { - logger.debug("getRegisteredResourceRequestCount called on invalid key: ", iae); + if(requestQueueMap.containsKey(key)) { + try { + Queue> requestQueue = getRequestQueueForExistingKey(key); + // FYI: .size() is not constant time in the next call. ;) + return requestQueue.size(); + } catch(IllegalArgumentException iae) { + logger.debug("getRegisteredResourceRequestCount called on invalid key: ", iae); + } } - return rc; + return 0; } /** diff --git a/test/unit/voldemort/store/memory/SlowStorageEngineTest.java b/test/unit/voldemort/store/memory/SlowStorageEngineTest.java index 07809807cf..dc5f4b6d41 100644 --- a/test/unit/voldemort/store/memory/SlowStorageEngineTest.java +++ b/test/unit/voldemort/store/memory/SlowStorageEngineTest.java @@ -66,7 +66,9 @@ public void setUp() throws Exception { // unit tests assert on specific delays occurring. OpTimeMap queued = new OpTimeMap(10, 20, 30, 40, 50); OpTimeMap concurrent = new OpTimeMap(50, 40, 30, 20, 10); - this.store = new SlowStorageEngine("test", queued, concurrent); + this.store = new SlowStorageEngine(new InMemoryStorageEngine("test"), + queued, + concurrent); } @Override