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);
|
out = new DirectCFSIndexOutput(dataOut, entry, false);
|
||||||
} else {
|
} else {
|
||||||
entry.dir = this.directory;
|
entry.dir = this.directory;
|
||||||
|
if (directory.fileExists(name)) {
|
||||||
|
throw new IOException("File already exists");
|
||||||
|
}
|
||||||
out = new DirectCFSIndexOutput(directory.createOutput(name), entry,
|
out = new DirectCFSIndexOutput(directory.createOutput(name), entry,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,17 @@ public class MockCompoundFileDirectoryWrapper extends CompoundFileDirectory {
|
||||||
private final CompoundFileDirectory delegate;
|
private final CompoundFileDirectory delegate;
|
||||||
private final String name;
|
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);
|
super(parent, name, 1024);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
super.initForRead(Collections.<String,FileEntry>emptyMap());
|
if (forWrite) {
|
||||||
parent.addFileHandle(this, name, true);
|
super.initForWrite();
|
||||||
|
} else {
|
||||||
|
super.initForRead(Collections.<String,FileEntry>emptyMap());
|
||||||
|
}
|
||||||
|
parent.addFileHandle(this, name, !forWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,4 +144,8 @@ public class MockCompoundFileDirectoryWrapper extends CompoundFileDirectory {
|
||||||
return delegate.openInputSlice(id, offset, length, readBufferSize);
|
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
|
@Override
|
||||||
public synchronized CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
|
public synchronized CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
|
||||||
maybeYield();
|
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. */
|
/** Provided for testing purposes. Use sizeInBytes() instead. */
|
||||||
public synchronized final long getRecomputedSizeInBytes() throws IOException {
|
public synchronized final long getRecomputedSizeInBytes() throws IOException {
|
||||||
if (!(delegate instanceof RAMDirectory))
|
if (!(delegate instanceof RAMDirectory))
|
||||||
|
|
Loading…
Reference in New Issue