From 1cdc4e655e80ca48c1bc8d4f8bf402c21a60a8f5 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Fri, 1 Oct 2010 23:21:49 +0000 Subject: [PATCH] SOLR-2135: Fix behavior of ConcurrentLRUCache when asking for getLatestAccessedItems(0) or getOldestAccessedItems(0) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1003703 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 4 ++++ .../org/apache/solr/common/util/ConcurrentLRUCache.java | 4 ++++ .../src/test/org/apache/solr/search/TestFastLRUCache.java | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 019f93b58bb..31510ff42c1 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -505,6 +505,10 @@ Bug Fixes wildcard support. For example, a query of *zemog* would match documents that contain 'gomez'. (Landon Kuhn via Robert Muir) +* SOLR-2135: Fix behavior of ConcurrentLRUCache when asking for + getLatestAccessedItems(0) or getOldestAccessedItems(0). + (David Smiley via hossman) + Other Changes ---------------------- diff --git a/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java b/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java index ac21ef4f2d0..ed352f2e186 100644 --- a/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java +++ b/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java @@ -398,6 +398,8 @@ public class ConcurrentLRUCache { */ public Map getOldestAccessedItems(int n) { Map result = new LinkedHashMap(); + if (n <= 0) + return result; TreeSet tree = new TreeSet(); markAndSweepLock.lock(); try { @@ -424,6 +426,8 @@ public class ConcurrentLRUCache { public Map getLatestAccessedItems(int n) { Map result = new LinkedHashMap(); + if (n <= 0) + return result; TreeSet tree = new TreeSet(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); diff --git a/solr/src/test/org/apache/solr/search/TestFastLRUCache.java b/solr/src/test/org/apache/solr/search/TestFastLRUCache.java index 5733bf2b295..6c42eacf283 100644 --- a/solr/src/test/org/apache/solr/search/TestFastLRUCache.java +++ b/solr/src/test/org/apache/solr/search/TestFastLRUCache.java @@ -243,6 +243,14 @@ public class TestFastLRUCache extends LuceneTestCase { assertNotNull(m.get(5)); assertNotNull(m.get(4)); assertNotNull(m.get(2)); + + m = cache.getOldestAccessedItems(0); + assertTrue(m.isEmpty()); + + //test this too + m = cache.getLatestAccessedItems(0); + assertTrue(m.isEmpty()); + cache.destroy(); }