Skip to content

Commit 191887d

Browse files
committed
Added refCount assertion due to LUCENE-5362
1 parent 11e2b1b commit 191887d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/test/java/org/elasticsearch/test/engine/MockRobinEngine.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ public final class AssertingSearcher implements Searcher {
9797
private final ShardId shardId;
9898
private RuntimeException firstReleaseStack;
9999
private final Object lock = new Object();
100+
private final int initialRefCount;
100101

101102
public AssertingSearcher(Searcher searcher, ShardId shardId) {
102103
this.searcher = searcher;
103104
this.shardId = shardId;
105+
initialRefCount = searcher.reader().getRefCount();
106+
assert initialRefCount > 0 : "IndexReader#getRefCount() was [" + initialRefCount + "] expected a value > [0] - reader is already closed";
104107
INFLIGHT_ENGINE_SEARCHERS.put(this, new RuntimeException("Unreleased Searcher, source [" + searcher.source() + "]"));
105108
}
106109

@@ -124,6 +127,10 @@ public boolean release() throws ElasticSearchException {
124127
firstReleaseStack = new RuntimeException("Searcher Released first here, source [" + searcher.source() + "]");
125128
}
126129
}
130+
final int refCount = searcher.reader().getRefCount();
131+
// this assert seems to be paranoid but given LUCENE-5362 we better add some assertions here to make sure we catch any potential
132+
// problems.
133+
assert refCount > 0 : "IndexReader#getRefCount() was [" + refCount + "] expected a value > [0] - reader is already closed. Initial refCount was: [" + initialRefCount + "]";
127134
try {
128135
return searcher.release();
129136
} catch (RuntimeException ex) {

0 commit comments

Comments
 (0)