Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5543: Add allowReadingFilesStillOpenForWrite to MockDirectoryFactory and MockDirectoryWrapper and set it to true for cloud tests.

Mark Robert Miller1567665c96fc
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
index d2c02f521a1..142ab38e0d0 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
@@ -75,6 +75,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
boolean trackDiskUsage = false;
boolean wrapLockFactory = true;
boolean allowRandomFileNotFoundException = true;
+ boolean allowReadingFilesStillOpenForWrite = false;
private Set<String> unSyncedFiles;
private Set<String> createdFiles;
private Set<String> openFilesForWrite = new HashSet<>();
@@ -146,6 +147,12 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
public void setAllowRandomFileNotFoundException(boolean value) {
allowRandomFileNotFoundException = value;
}
+
+ /** If set to true, you can open an inputstream on a file
+ * that is still open for writes. */
+ public void setAllowReadingFilesStillOpenForWrite(boolean value) {
+ allowReadingFilesStillOpenForWrite = value;
+ }
/**
* Enum for controlling hard disk throttling.
@@ -564,7 +571,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
// cannot open a file for input if it's still open for
// output, except for segments.gen and segments_N
- if (openFilesForWrite.contains(name) && !name.startsWith("segments")) {
+ if (!allowReadingFilesStillOpenForWrite && openFilesForWrite.contains(name) && !name.startsWith("segments")) {
throw (IOException) fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);
}
@@ -1004,4 +1011,5 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
* e.g. from {@link MockDirectoryWrapper.Failure}. */
public static class FakeIOException extends IOException {
}
+
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
index 0e505045120..820216defda 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
@@ -30,6 +30,7 @@ import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.Diagnostics;
+import org.apache.solr.core.MockDirectoryFactory;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.zookeeper.KeeperException;
import org.junit.After;
@@ -69,6 +70,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
System.setProperty(ENABLE_UPDATE_LOG, "true");
System.setProperty(REMOVE_VERSION_FIELD, "true");
System.setProperty(ZOOKEEPER_FORCE_SYNC, "false");
+ System.setProperty(MockDirectoryFactory.SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE, "true");
String schema = getSchemaFile();
if (schema == null) schema = "schema.xml";
@@ -224,6 +226,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
System.clearProperty("solr.test.sys.prop1");
System.clearProperty("solr.test.sys.prop2");
System.clearProperty(ZOOKEEPER_FORCE_SYNC);
+ System.clearProperty(MockDirectoryFactory.SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);
resetExceptionIgnores();
super.tearDown();
diff --git a/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java b/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
index ed53eded43c..2d065892d91 100644
--- a/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
@@ -31,6 +31,9 @@ import org.apache.lucene.util.LuceneTestCase;
* Opens a directory with {@link LuceneTestCase#newDirectory()}
*/
public class MockDirectoryFactory extends EphemeralDirectoryFactory {
+
+ public static final String SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE = "solr.tests.allow_reading_files_still_open_for_write";
+ private boolean allowReadingFilesStillOpenForWrite = Boolean.getBoolean(SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
@@ -59,6 +62,10 @@ public class MockDirectoryFactory extends EphemeralDirectoryFactory {
// tries to write to index.properties after the file has
// already been created.
mockDirWrapper.setPreventDoubleWrite(false);
+
+ if (allowReadingFilesStillOpenForWrite) {
+ mockDirWrapper.setAllowReadingFilesStillOpenForWrite(true);
+ }
}
return dir;