Apache Lucene open-source search software
tests: make test a little nastier
Mark Robert Millerbe4edb9ca4d3
diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.javaindex 2648c182a56..11a7480abd0 100644--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java@@ -29,6 +29,7 @@ import java.util.Locale;import java.util.Map;import java.util.Set;+import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext.Context;import org.apache.lucene.store.NativeFSLockFactory;@@ -314,7 +315,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {String fullPath = normalize(path);synchronized (this) {if (closed) {- throw new RuntimeException("Already closed");+ throw new AlreadyClosedException("Already closed");}final CacheValue cacheValue = byPathCache.get(fullPath);diff --git a/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.javaindex c5cf655d279..be7e269f543 100644--- a/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java@@ -8,6 +8,7 @@ import java.util.Map;import java.util.Random;import java.util.concurrent.atomic.AtomicInteger;+import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.core.DirectoryFactory.DirContext;@@ -45,20 +46,20 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {final CachingDirectoryFactory df = new RAMDirectoryFactory();List<Thread> threads = new ArrayList<Thread>();- int threadCount = 3;+ int threadCount = 11;for (int i = 0; i < threadCount; i++) {Thread getDirThread = new GetDirThread(df);threads.add(getDirThread);getDirThread.start();}- for (int i = 0; i < 2; i++) {+ for (int i = 0; i < 4; i++) {Thread releaseDirThread = new ReleaseDirThread(df);threads.add(releaseDirThread);releaseDirThread.start();}- for (int i = 0; i < 1; i++) {+ for (int i = 0; i < 2; i++) {Thread incRefThread = new IncRefThread(df);threads.add(incRefThread);incRefThread.start();@@ -66,13 +67,7 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {Thread.sleep(TEST_NIGHTLY ? 30000 : 8000);- stop = true;-- for (Thread thread : threads) {- thread.join();- }-- Thread thread = new Thread() {+ Thread closeThread = new Thread() {public void run() {try {df.close();@@ -81,7 +76,15 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {}}};- thread.start();+ closeThread.start();+++ stop = true;++ for (Thread thread : threads) {+ thread.join();+ }+// do any remaining releasessynchronized (dirs) {@@ -98,7 +101,7 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {}- thread.join();+ closeThread.join();}@@ -128,7 +131,7 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {Tracker tracker = dirsList.get(Math.min(dirsList.size() - 1,random.nextInt(sz + 1)));if (tracker.refCnt.get() > 0) {- if (random.nextBoolean()) {+ if (random.nextInt(10) > 7) {df.doneWithDirectory(tracker.dir);}if (random.nextBoolean()) {@@ -162,7 +165,7 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {random = random();while (!stop) {try {- Thread.sleep(random.nextInt(50) + 1);+ Thread.sleep(random.nextInt(350) + 1);} catch (InterruptedException e1) {throw new RuntimeException(e1);}@@ -181,6 +184,8 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {tracker.refCnt.incrementAndGet();}+ } catch (AlreadyClosedException e) {+ log.warn("Cannot get dir, factory is already closed");} catch (IOException e) {throw new RuntimeException(e);}