Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3218: added FileHandle Tracking for CFS tests and throw explicit exception if existing files are overwritten in the CFS

Simon Willnauer21ee32bc2541
diff --git a/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java b/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
index 29f9b09ccb3..748a1787eda 100644
--- a/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
+++ b/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
@@ -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);
}
diff --git a/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java b/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
index 0dd89240e22..cd0f498e78f 100644
--- a/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
+++ b/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
@@ -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);
+ }
}
diff --git a/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
index c2e1e013955..e75412936bd 100644
--- a/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
+++ b/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
@@ -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))