mirror of https://github.com/apache/lucene.git
LUCENE-3218: added FileHandle Tracking for CFS tests and throw explicit exception if existing files are overwritten in the CFS
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1138420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
77e3dfc016
commit
21ee32bc25
|
@ -226,6 +226,9 @@ final class CompoundFileWriter {
|
|||
out = new DirectCFSIndexOutput(dataOut, entry, false);
|
||||
} else {
|
||||
entry.dir = this.directory;
|
||||
if (directory.fileExists(name)) {
|
||||
throw new IOException("File already exists");
|
||||
}
|
||||
out = new DirectCFSIndexOutput(directory.createOutput(name), entry,
|
||||
true);
|
||||
}
|
||||
|
|
|
@ -26,13 +26,17 @@ public class MockCompoundFileDirectoryWrapper extends CompoundFileDirectory {
|
|||
private final CompoundFileDirectory delegate;
|
||||
private final String name;
|
||||
|
||||
public MockCompoundFileDirectoryWrapper(String name, MockDirectoryWrapper parent, CompoundFileDirectory delegate) throws IOException {
|
||||
public MockCompoundFileDirectoryWrapper(String name, MockDirectoryWrapper parent, CompoundFileDirectory delegate, boolean forWrite) throws IOException {
|
||||
super(parent, name, 1024);
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
this.delegate = delegate;
|
||||
super.initForRead(Collections.<String,FileEntry>emptyMap());
|
||||
parent.addFileHandle(this, name, true);
|
||||
if (forWrite) {
|
||||
super.initForWrite();
|
||||
} else {
|
||||
super.initForRead(Collections.<String,FileEntry>emptyMap());
|
||||
}
|
||||
parent.addFileHandle(this, name, !forWrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,4 +144,8 @@ public class MockCompoundFileDirectoryWrapper extends CompoundFileDirectory {
|
|||
return delegate.openInputSlice(id, offset, length, readBufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundFileDirectory createCompoundOutput(String name) throws IOException {
|
||||
return delegate.createCompoundOutput(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -420,9 +420,15 @@ public class MockDirectoryWrapper extends Directory {
|
|||
@Override
|
||||
public synchronized CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
|
||||
maybeYield();
|
||||
return new MockCompoundFileDirectoryWrapper(name, this, delegate.openCompoundInput(name, bufferSize));
|
||||
return new MockCompoundFileDirectoryWrapper(name, this, delegate.openCompoundInput(name, bufferSize), false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompoundFileDirectory createCompoundOutput(String name) throws IOException {
|
||||
maybeYield();
|
||||
return new MockCompoundFileDirectoryWrapper(name, this, delegate.createCompoundOutput(name), true);
|
||||
}
|
||||
|
||||
/** Provided for testing purposes. Use sizeInBytes() instead. */
|
||||
public synchronized final long getRecomputedSizeInBytes() throws IOException {
|
||||
if (!(delegate instanceof RAMDirectory))
|
||||
|
|
Loading…
Reference in New Issue