fix a bug in ReferenceManager.maybeRefreshBlocking -- call unlock() in finally, not lock()\!

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1332733 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2012-05-01 16:15:59 +00:00
parent 77ababf249
commit 16e3abe513
2 changed files with 32 additions and 1 deletions

View File

@ -194,7 +194,7 @@ public abstract class ReferenceManager<G> implements Closeable {
try {
doMaybeRefresh();
} finally {
refreshLock.lock();
refreshLock.unlock();
}
}

View File

@ -353,4 +353,35 @@ public class TestSearcherManager extends ThreadedIndexingAndSearchingTestCase {
other.close();
dir.close();
}
public void testMaybeRefreshBlockingLock() throws Exception {
// make sure that maybeRefreshBlocking releases the lock, otherwise other
// threads cannot obtain it.
final Directory dir = newDirectory();
final RandomIndexWriter w = new RandomIndexWriter(random(), dir);
w.close();
final SearcherManager sm = new SearcherManager(dir, null);
Thread t = new Thread() {
@Override
public void run() {
try {
// this used to not release the lock, preventing other threads from obtaining it.
sm.maybeRefreshBlocking();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
t.start();
t.join();
// if maybeRefreshBlocking didn't release the lock, this will fail.
assertTrue("failde to obtain the refreshLock!", sm.maybeRefresh());
sm.close();
dir.close();
}
}