mirror of https://github.com/apache/lucene.git
LUCENE-5431: add FSLockFactory.toString() and fix FilterDirectory to override getLockID(); also change FSDirectory.toString() to use class.getSimpleName()
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1564304 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
732f295c4f
commit
04e66785ca
|
@ -337,7 +337,7 @@ public abstract class FSDirectory extends BaseDirectory {
|
||||||
/** For debug output. */
|
/** For debug output. */
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.getClass().getName() + "@" + directory + " lockFactory=" + getLockFactory();
|
return this.getClass().getSimpleName() + "@" + directory + " lockFactory=" + getLockFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,4 +50,9 @@ public abstract class FSLockFactory extends LockFactory {
|
||||||
return lockDir;
|
return lockDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getClass().getSimpleName() + "@" + lockDir;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,11 @@ public class FilterDirectory extends Directory {
|
||||||
in.setLockFactory(lockFactory);
|
in.setLockFactory(lockFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLockID() {
|
||||||
|
return in.getLockID();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LockFactory getLockFactory() {
|
public LockFactory getLockFactory() {
|
||||||
return in.getLockFactory();
|
return in.getLockFactory();
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.lucene.index;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.apache.lucene.analysis.MockAnalyzer;
|
import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
import org.apache.lucene.document.Document;
|
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.IndexSearcher;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.TopDocs;
|
import org.apache.lucene.search.TopDocs;
|
||||||
import org.apache.lucene.store.BaseDirectory;
|
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.store.FSDirectory;
|
import org.apache.lucene.store.FSDirectory;
|
||||||
|
import org.apache.lucene.store.FilterDirectory;
|
||||||
import org.apache.lucene.store.IOContext;
|
import org.apache.lucene.store.IOContext;
|
||||||
import org.apache.lucene.store.IndexInput;
|
|
||||||
import org.apache.lucene.store.IndexOutput;
|
import org.apache.lucene.store.IndexOutput;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util._TestUtil;
|
import org.apache.lucene.util._TestUtil;
|
||||||
|
@ -147,13 +145,12 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
|
||||||
* This test class provides direct access to "simulating" a crash right after
|
* This test class provides direct access to "simulating" a crash right after
|
||||||
* realDirectory.createOutput(..) has been called on a certain specified name.
|
* 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;
|
private String crashAfterCreateOutput;
|
||||||
|
|
||||||
public CrashAfterCreateOutput(Directory realDirectory) throws IOException {
|
public CrashAfterCreateOutput(Directory realDirectory) throws IOException {
|
||||||
this.realDirectory = realDirectory;
|
super(realDirectory);
|
||||||
setLockFactory(realDirectory.getLockFactory());
|
setLockFactory(realDirectory.getLockFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,14 +158,9 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
|
||||||
this.crashAfterCreateOutput = name;
|
this.crashAfterCreateOutput = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
realDirectory.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexOutput createOutput(String name, IOContext cxt) throws IOException {
|
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)) {
|
if (null != crashAfterCreateOutput && name.equals(crashAfterCreateOutput)) {
|
||||||
// CRASH!
|
// CRASH!
|
||||||
indexOutput.close();
|
indexOutput.close();
|
||||||
|
@ -181,34 +173,6 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
|
||||||
return indexOutput;
|
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<String> names) throws IOException {
|
|
||||||
realDirectory.sync(names);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<String> exclude = new HashSet<String>();
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue