Skip to content

Commit

Permalink
LUCENE-4243: MockDirectoryWrapper synchronizes too much
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/branch_4x@1363988 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmuir committed Jul 20, 2012
1 parent 66e224e commit 19ade75
Show file tree
Hide file tree
Showing 36 changed files with 339 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util._TestUtil;
import org.junit.BeforeClass;
Expand All @@ -45,7 +44,7 @@ public static void beforeClassAddIndexesTaskTest() throws Exception {

// create a dummy index under inputDir
inputDir = new File(testDir, "input");
MockDirectoryWrapper tmpDir = newFSDirectory(inputDir);
Directory tmpDir = newFSDirectory(inputDir);
try {
IndexWriter writer = new IndexWriter(tmpDir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
for (int i = 0; i < 10; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testPerFieldCodec() throws Exception {
System.out.println("TEST: NUM_DOCS=" + NUM_DOCS);
}

MockDirectoryWrapper dir = newDirectory();
BaseDirectoryWrapper dir = newDirectory();
dir.setCheckIndexOnClose(false); // we use a custom codec provider
IndexWriter w = new IndexWriter(
dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void eval(MockDirectoryWrapper dir) throws IOException {
}

public void testSubclassConcurrentMergeScheduler() throws IOException {
MockDirectoryWrapper dir = newDirectory();
MockDirectoryWrapper dir = newMockDirectory();
dir.failOn(new FailOnlyOnMerge());

Document doc = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
Expand All @@ -54,7 +55,7 @@ public void test10kPulsed() throws Exception {
Codec cp = _TestUtil.alwaysPostingsFormat(new Pulsing40PostingsFormat(1));

File f = _TestUtil.getTempDir("10kpulsed");
MockDirectoryWrapper dir = newFSDirectory(f);
BaseDirectoryWrapper dir = newFSDirectory(f);
dir.setCheckIndexOnClose(false); // we do this ourselves explicitly
RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));
Expand Down Expand Up @@ -105,7 +106,7 @@ public void test10kNotPulsed() throws Exception {
Codec cp = _TestUtil.alwaysPostingsFormat(new Pulsing40PostingsFormat(freqCutoff));

File f = _TestUtil.getTempDir("10knotpulsed");
MockDirectoryWrapper dir = newFSDirectory(f);
BaseDirectoryWrapper dir = newFSDirectory(f);
dir.setCheckIndexOnClose(false); // we do this ourselves explicitly
RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void testSophisticatedReuse() throws Exception {
public void testNestedPulsing() throws Exception {
// we always run this test with pulsing codec.
Codec cp = _TestUtil.alwaysPostingsFormat(new NestedPulsingPostingsFormat());
MockDirectoryWrapper dir = newDirectory();
BaseDirectoryWrapper dir = newDirectory();
dir.setCheckIndexOnClose(false); // will do this ourselves, custom codec
RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.FieldInfo.IndexOptions;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
Expand All @@ -39,8 +40,10 @@ public class Test2BPostings extends LuceneTestCase {

@Nightly
public void test() throws Exception {
MockDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BPostings"));
dir.setThrottling(MockDirectoryWrapper.Throttling.NEVER);
BaseDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BPostings"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
dir.setCheckIndexOnClose(false); // don't double-checkindex

IndexWriter w = new IndexWriter(dir,
Expand Down
6 changes: 4 additions & 2 deletions lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ public void test2BTerms() throws IOException {

List<BytesRef> savedTerms = null;

MockDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BTerms"));
BaseDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BTerms"));
//MockDirectoryWrapper dir = newFSDirectory(new File("/p/lucene/indices/2bindex"));
dir.setThrottling(MockDirectoryWrapper.Throttling.NEVER);
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
dir.setCheckIndexOnClose(false); // don't double-checkindex

if (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
Expand Down Expand Up @@ -1168,7 +1169,7 @@ public LiveDocsFormat liveDocsFormat() {
* simple test that ensures we getting expected exceptions
*/
public void testAddIndexMissingCodec() throws IOException {
MockDirectoryWrapper toAdd = newDirectory();
BaseDirectoryWrapper toAdd = newDirectory();
// Disable checkIndex, else we get an exception because
// of the unregistered codec:
toAdd.setCheckIndexOnClose(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
Expand Down Expand Up @@ -174,7 +175,7 @@ public void testUnsupportedOldIndexes() throws Exception {
}
File oldIndxeDir = _TestUtil.getTempDir(unsupportedNames[i]);
_TestUtil.unzip(getDataFile("unsupported." + unsupportedNames[i] + ".zip"), oldIndxeDir);
MockDirectoryWrapper dir = newFSDirectory(oldIndxeDir);
BaseDirectoryWrapper dir = newFSDirectory(oldIndxeDir);
// don't checkindex, these are intentionally not supported
dir.setCheckIndexOnClose(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;

Expand Down Expand Up @@ -67,7 +68,7 @@ public void eval(MockDirectoryWrapper dir) throws IOException {
// Make sure running BG merges still work fine even when
// we are hitting exceptions during flushing.
public void testFlushExceptions() throws IOException {
MockDirectoryWrapper directory = newDirectory();
MockDirectoryWrapper directory = newMockDirectory();
FailOnlyOnFlush failure = new FailOnlyOnFlush();
directory.failOn(failure);

Expand Down Expand Up @@ -120,7 +121,7 @@ public void testFlushExceptions() throws IOException {
// Test that deletes committed after a merge started and
// before it finishes, are correctly merged back:
public void testDeleteMerging() throws IOException {
MockDirectoryWrapper directory = newDirectory();
Directory directory = newDirectory();

LogDocMergePolicy mp = new LogDocMergePolicy();
// Force degenerate merging so we can get a mix of
Expand Down Expand Up @@ -164,7 +165,7 @@ TEST_VERSION_CURRENT, new MockAnalyzer(random()))
}

public void testNoExtraFiles() throws IOException {
MockDirectoryWrapper directory = newDirectory();
Directory directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random()))
.setMaxBufferedDocs(2));
Expand Down Expand Up @@ -195,7 +196,7 @@ TEST_VERSION_CURRENT, new MockAnalyzer(random()))
}

public void testNoWaitClose() throws IOException {
MockDirectoryWrapper directory = newDirectory();
Directory directory = newDirectory();
Document doc = new Document();
Field idField = newStringField("id", "", Field.Store.YES);
doc.add(idField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class TestCrash extends LuceneTestCase {

private IndexWriter initIndex(Random random, boolean initialCommit) throws IOException {
return initIndex(random, newDirectory(random), initialCommit);
return initIndex(random, newMockDirectory(random), initialCommit);
}

private IndexWriter initIndex(Random random, MockDirectoryWrapper dir, boolean initialCommit) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LineFileDocs;
Expand All @@ -46,7 +45,7 @@ public class TestCustomNorms extends LuceneTestCase {

public void testFloatNorms() throws IOException {

MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random()));
Similarity provider = new MySimProvider();
Expand Down Expand Up @@ -87,7 +86,7 @@ public void testFloatNorms() throws IOException {
}

public void testExceptionOnRandomType() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random()));
Similarity provider = new MySimProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testSimple() throws Exception {
}

public void testRandom() throws Exception {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();

final int NUM_TERMS = atLeast(20);
final Set<BytesRef> terms = new HashSet<BytesRef>();
Expand Down Expand Up @@ -176,7 +176,7 @@ public void testRandom() throws Exception {
}

public void testRandomWithPrefix() throws Exception {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();

final Set<String> prefixes = new HashSet<String>();
final int numPrefix = _TestUtil.nextInt(random(), 2, 7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void testFilterIndexReader() throws Exception {
Directory target = newDirectory();

// We mess with the postings so this can fail:
((MockDirectoryWrapper) target).setCrossCheckTermVectorsOnClose(false);
((BaseDirectoryWrapper) target).setCrossCheckTermVectorsOnClose(false);

writer = new IndexWriter(target, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
IndexReader reader = new TestReader(DirectoryReader.open(directory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void testStallControl() throws InterruptedException, IOException {
final int numDocumentsToIndex = 50 + random().nextInt(50);
for (int i = 0; i < numThreads.length; i++) {
AtomicInteger numDocs = new AtomicInteger(numDocumentsToIndex);
MockDirectoryWrapper dir = newDirectory();
MockDirectoryWrapper dir = newMockDirectory();
// mock a very slow harddisk sometimes here so that flushing is very slow
dir.setThrottling(MockDirectoryWrapper.Throttling.SOMETIMES);
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void test() throws Exception {
// NOTE: if we see a fail on this test with "NestedPulsing" its because its
// reuse isnt perfect (but reasonable). see TestPulsingReuse.testNestedPulsing
// for more details
final MockDirectoryWrapper dir = newDirectory();
final MockDirectoryWrapper dir = newMockDirectory();
final TieredMergePolicy tmp = new TieredMergePolicy();
tmp.setMaxMergeAtOnce(2);
final RandomIndexWriter w = new RandomIndexWriter(random(), dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
public class TestIndexFileDeleter extends LuceneTestCase {

public void testDeleteLeftoverFiles() throws IOException {
MockDirectoryWrapper dir = newDirectory();
dir.setPreventDoubleWrite(false);
Directory dir = newDirectory();
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setPreventDoubleWrite(false);
}

LogMergePolicy mergePolicy = newLogMergePolicy(true, 10);
mergePolicy.setNoCFSRatio(1); // This test expects all of its segments to be in CFS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testChangesAfterClose() throws IOException {


public void testIndexNoDocuments() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())));
writer.commit();
writer.close();
Expand All @@ -235,7 +235,7 @@ public void testIndexNoDocuments() throws IOException {
}

public void testManyFields() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())).setMaxBufferedDocs(10));
for(int j=0;j<100;j++) {
Document doc = new Document();
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testManyFields() throws IOException {
}

public void testSmallRAMBuffer() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(
dir,
newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())).
Expand Down Expand Up @@ -405,7 +405,7 @@ else if (j < 10) {
}

public void testDiverseDocs() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())).setRAMBufferSizeMB(0.5));
int n = atLeast(1);
for(int i=0;i<n;i++) {
Expand Down Expand Up @@ -454,7 +454,7 @@ public void testDiverseDocs() throws IOException {
}

public void testEnablingNorms() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random())).setMaxBufferedDocs(10));
// Enable norms for only 1 doc, pre flush
FieldType customType = new FieldType(TextField.TYPE_STORED);
Expand Down Expand Up @@ -510,7 +510,7 @@ public void testEnablingNorms() throws IOException {
}

public void testHighFreqTerm() throws IOException {
MockDirectoryWrapper dir = newDirectory();
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random())).setRAMBufferSizeMB(0.01));
// Massive doc that has 128 K a's
Expand Down
Loading

0 comments on commit 19ade75

Please sign in to comment.