diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java index b00f6566fbd..fba28a26b40 100644 --- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java @@ -337,7 +337,7 @@ public abstract class FSDirectory extends BaseDirectory { /** For debug output. */ @Override public String toString() { - return this.getClass().getName() + "@" + directory + " lockFactory=" + getLockFactory(); + return this.getClass().getSimpleName() + "@" + directory + " lockFactory=" + getLockFactory(); } /** diff --git a/lucene/core/src/java/org/apache/lucene/store/FSLockFactory.java b/lucene/core/src/java/org/apache/lucene/store/FSLockFactory.java index 62048fdb113..dc96fabf230 100644 --- a/lucene/core/src/java/org/apache/lucene/store/FSLockFactory.java +++ b/lucene/core/src/java/org/apache/lucene/store/FSLockFactory.java @@ -50,4 +50,9 @@ public abstract class FSLockFactory extends LockFactory { return lockDir; } + @Override + public String toString() { + return this.getClass().getSimpleName() + "@" + lockDir; + } + } diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java index e7b01b38984..30de69a6c3e 100644 --- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java @@ -100,6 +100,11 @@ public class FilterDirectory extends Directory { in.setLockFactory(lockFactory); } + @Override + public String getLockID() { + return in.getLockID(); + } + @Override public LockFactory getLockFactory() { return in.getLockFactory(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java index 90f6206e530..2a3b87c5a8d 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java @@ -19,7 +19,6 @@ package org.apache.lucene.index; import java.io.File; import java.io.IOException; -import java.util.Collection; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; @@ -27,11 +26,10 @@ import org.apache.lucene.document.Field; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.BaseDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.FilterDirectory; import org.apache.lucene.store.IOContext; -import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; @@ -147,28 +145,22 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase { * This test class provides direct access to "simulating" a crash right after * realDirectory.createOutput(..) has been called on a certain specified name. */ - private static class CrashAfterCreateOutput extends BaseDirectory { + private static class CrashAfterCreateOutput extends FilterDirectory { - private Directory realDirectory; private String crashAfterCreateOutput; public CrashAfterCreateOutput(Directory realDirectory) throws IOException { - this.realDirectory = realDirectory; + super(realDirectory); setLockFactory(realDirectory.getLockFactory()); } public void setCrashAfterCreateOutput(String name) { this.crashAfterCreateOutput = name; } - - @Override - public void close() throws IOException { - realDirectory.close(); - } - + @Override public IndexOutput createOutput(String name, IOContext cxt) throws IOException { - IndexOutput indexOutput = realDirectory.createOutput(name, cxt); + IndexOutput indexOutput = in.createOutput(name, cxt); if (null != crashAfterCreateOutput && name.equals(crashAfterCreateOutput)) { // CRASH! indexOutput.close(); @@ -181,34 +173,6 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase { return indexOutput; } - @Override - public void deleteFile(String name) throws IOException { - realDirectory.deleteFile(name); - } - - @Override - public boolean fileExists(String name) throws IOException { - return realDirectory.fileExists(name); - } - - @Override - public long fileLength(String name) throws IOException { - return realDirectory.fileLength(name); - } - - @Override - public String[] listAll() throws IOException { - return realDirectory.listAll(); - } - - @Override - public IndexInput openInput(String name, IOContext cxt) throws IOException { - return realDirectory.openInput(name, cxt); - } - - @Override - public void sync(Collection names) throws IOException { - realDirectory.sync(names); - } } + } diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java new file mode 100644 index 00000000000..3a90c9a3c95 --- /dev/null +++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java @@ -0,0 +1,43 @@ +package org.apache.lucene.store; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; + +import org.apache.lucene.util.LuceneTestCase; +import org.junit.Test; + +public class TestFilterDirectory extends LuceneTestCase { + + @Test + public void testOverrides() throws Exception { + // verify that all methods of Directory are overridden by FilterDirectory, + // except those under the 'exclude' list + Set exclude = new HashSet(); + exclude.add("copy"); + exclude.add("createSlicer"); + for (Method m : FilterDirectory.class.getMethods()) { + if (m.getDeclaringClass() == Directory.class) { + assertTrue("method " + m.getName() + " not overridden!", exclude.contains(m.getName())); + } + } + } + +}