mirror of https://github.com/apache/lucene.git
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:
parent
77ababf249
commit
16e3abe513
|
@ -194,7 +194,7 @@ public abstract class ReferenceManager<G> implements Closeable {
|
|||
try {
|
||||
doMaybeRefresh();
|
||||
} finally {
|
||||
refreshLock.lock();
|
||||
refreshLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue