mirror of https://github.com/apache/lucene.git
LUCENE-5543: Add allowReadingFilesStillOpenForWrite to MockDirectoryFactory and MockDirectoryWrapper and set it to true for cloud tests.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1580707 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
742aadf5a2
commit
1567665c96
|
@ -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<>();
|
||||
|
@ -147,6 +148,12 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
|
|||
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.
|
||||
* Set via {@link MockDirectoryWrapper #setThrottling(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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -32,6 +32,9 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
*/
|
||||
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 {
|
||||
Directory dir = LuceneTestCase.newDirectory();
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue