LUCENE-6120: Fix MockDirectoryWrapper close() handling

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1647599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-12-23 15:45:16 +00:00
parent e8c3a8f6e6
commit 7d4ba636b0
3 changed files with 13 additions and 9 deletions

View File

@ -419,6 +419,9 @@ Tests
* LUCENE-5968: Improve error message when 'ant beast' is run on top-level
modules. (Ramkumar Aiyengar, Uwe Schindler)
* LUCENE-6120: Fix MockDirectoryWrapper's close() handling.
(Mike McCandless, Robert Muir)
Build
* LUCENE-5909: Smoke tester now has better command line parsing and

View File

@ -1,5 +1,6 @@
package org.apache.lucene.store;
import java.io.Closeable;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
@ -43,21 +44,20 @@ public class MockIndexInputWrapper extends IndexInput {
@Override
public void close() throws IOException {
// TODO turn on the following to look for leaks closing inputs,
// after fixing TestTransactions
// dir.maybeThrowDeterministicException();
if (closed) {
delegate.close(); // don't mask double-close bugs
return;
}
closed = true;
try {
// turn on the following to look for leaks closing inputs,
// after fixing TestTransactions
// dir.maybeThrowDeterministicException();
} finally {
delegate.close();
try (Closeable delegate = this.delegate) {
// Pending resolution on LUCENE-686 we may want to
// remove the conditional check so we also track that
// all clones get closed:
assert delegate != null;
if (!isClone) {
dir.removeIndexInput(this, name);
}

View File

@ -17,6 +17,7 @@ package org.apache.lucene.store;
* limitations under the License.
*/
import java.io.Closeable;
import java.io.IOException;
import org.apache.lucene.util.LuceneTestCase;
@ -98,10 +99,11 @@ public class MockIndexOutputWrapper extends IndexOutput {
}
closed = true;
try {
try (Closeable delegate = this.delegate) {
assert delegate != null;
dir.maybeThrowDeterministicException();
} finally {
delegate.close();
dir.removeIndexOutput(this, name);
if (dir.trackDiskUsage) {
// Now compute actual disk usage & track the maxUsedSize
// in the MockDirectoryWrapper:
@ -110,7 +112,6 @@ public class MockIndexOutputWrapper extends IndexOutput {
dir.maxUsedSize = size;
}
}
dir.removeIndexOutput(this, name);
}
}