fix test bug

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1644127 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-12-09 17:27:18 +00:00
parent 5929d5b436
commit 735ea0129d
3 changed files with 22 additions and 4 deletions

View File

@ -32,7 +32,7 @@ import org.apache.lucene.util.TestUtil;
public class TestForTooMuchCloning extends LuceneTestCase {
// Make sure we don't clone IndexInputs too frequently
// during merging:
// during merging and searching:
public void test() throws Exception {
final MockDirectoryWrapper dir = newMockDirectory();
final TieredMergePolicy tmp = new TieredMergePolicy();
@ -55,12 +55,14 @@ public class TestForTooMuchCloning extends LuceneTestCase {
final IndexReader r = w.getReader();
w.close();
final int cloneCount = dir.getInputCloneCount();
//System.out.println("merge clone count=" + cloneCount);
assertTrue("too many calls to IndexInput.clone during merging: " + dir.getInputCloneCount(), cloneCount < 500);
assertTrue("too many calls to IndexInput.clone during merging: " + dir.getInputCloneCount(), dir.getInputCloneCount() < 500);
final IndexSearcher s = newSearcher(r);
// important: set this after newSearcher, it might have run checkindex
final int cloneCount = dir.getInputCloneCount();
// dir.setVerboseClone(true);
// MTQ that matches all terms so the AUTO_REWRITE should
// cutover to filter rewrite and reuse a single DocsEnum
// across all terms;

View File

@ -134,6 +134,16 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
public int getInputCloneCount() {
return inputCloneCount.get();
}
boolean verboseClone;
/**
* If set to true, we print a fake exception
* with filename and stacktrace on every indexinput clone()
*/
public void setVerboseClone(boolean v) {
verboseClone = v;
}
public void setTrackDiskUsage(boolean v) {
trackDiskUsage = v;

View File

@ -67,6 +67,9 @@ public class MockIndexInputWrapper extends IndexInput {
@Override
public MockIndexInputWrapper clone() {
ensureOpen();
if (dir.verboseClone) {
new Exception("clone: " + this).printStackTrace(System.out);
}
dir.inputCloneCount.incrementAndGet();
IndexInput iiclone = delegate.clone();
MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, name, iiclone);
@ -91,6 +94,9 @@ public class MockIndexInputWrapper extends IndexInput {
@Override
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
ensureOpen();
if (dir.verboseClone) {
new Exception("slice: " + this).printStackTrace(System.out);
}
dir.inputCloneCount.incrementAndGet();
IndexInput slice = delegate.slice(sliceDescription, offset, length);
MockIndexInputWrapper clone = new MockIndexInputWrapper(dir, sliceDescription, slice);