Skip to content

Commit

Permalink
LUCENE-2598: factor the behavior of MockRAMDirectory into MockDirecto…
Browse files Browse the repository at this point in the history
…ryWrapper, add experimental -Dtests.directory= to allow running the tests under different directory impls [but the default is still RAMDirectory]

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@988206 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmuir committed Aug 23, 2010
1 parent 9b62d49 commit 07df8d5
Show file tree
Hide file tree
Showing 157 changed files with 801 additions and 580 deletions.
2 changes: 2 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
syntax: glob
*/build/*
3 changes: 3 additions & 0 deletions lucene/common-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<property name="tests.codec" value="random" />
<property name="tests.locale" value="random" />
<property name="tests.timezone" value="random" />
<property name="tests.directory" value="RAMDirectory" />

<property name="javac.deprecation" value="off"/>
<property name="javac.debug" value="on"/>
Expand Down Expand Up @@ -444,6 +445,8 @@
<sysproperty key="tests.locale" value="${tests.locale}"/>
<!-- set the timezone tests should run with -->
<sysproperty key="tests.timezone" value="${tests.timezone}"/>
<!-- set the directory tests should run with -->
<sysproperty key="tests.directory" value="${tests.directory}"/>

<!-- TODO: create propertyset for test properties, so each project can have its own set -->
<sysproperty key="random.multiplier" value="${random.multiplier}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermPositionVector;
import org.apache.lucene.search.Collector;
Expand All @@ -49,7 +48,6 @@
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.OpenBitSet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.automaton.BasicAutomata;
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
import org.apache.lucene.util.automaton.RegExp;
Expand All @@ -95,7 +94,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
static final String FIELD_NAME = "contents";
private static final String NUMERIC_FIELD_NAME = "nfield";
private Query query;
MockRAMDirectory ramDir;
Directory ramDir;
public IndexSearcher searcher = null;
int numHighlights = 0;
final Analyzer analyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);
Expand Down Expand Up @@ -1323,7 +1322,7 @@ public TokenStream init(TokenStream tokenStream) {

public void testMultiSearcher() throws Exception {
// setup index 1
MockRAMDirectory ramDir1 = newDirectory(random);
Directory ramDir1 = newDirectory(random);
IndexWriter writer1 = new IndexWriter(ramDir1, newIndexWriterConfig(random,
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));
Document d = new Document();
Expand All @@ -1335,7 +1334,7 @@ public void testMultiSearcher() throws Exception {
IndexReader reader1 = IndexReader.open(ramDir1, true);

// setup index 2
MockRAMDirectory ramDir2 = newDirectory(random);
Directory ramDir2 = newDirectory(random);
IndexWriter writer2 = new IndexWriter(ramDir2, newIndexWriterConfig(random,
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));
d = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

public abstract class AbstractTestCase extends LuceneTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

public class TestEmptyIndex extends LuceneTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.lucene.index.TermFreqVector;
import org.apache.lucene.index.TermPositionVector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.AttributeImpl;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
Expand All @@ -63,7 +62,7 @@ public class TestIndicesEquals extends LuceneTestCase {

public void testLoadIndexReader() throws Exception {
Random random = newRandom();
MockRAMDirectory dir = newDirectory(random);
Directory dir = newDirectory(random);

// create dir data
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(random,
Expand All @@ -88,7 +87,7 @@ public void testLoadIndexReader() throws Exception {
public void testInstantiatedIndexWriter() throws Exception {

Random random = newRandom();
MockRAMDirectory dir = newDirectory(random);
Directory dir = newDirectory(random);
InstantiatedIndex ii = new InstantiatedIndex();

// create dir data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.analysis.MockAnalyzer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util._TestUtil;

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ public void assertAgainstRAMDirectory() throws Exception {
termField.append(randomTerm());
}

MockRAMDirectory ramdir = newDirectory(random);
Directory ramdir = newDirectory(random);
Analyzer analyzer = randomAnalyzer();
IndexWriter writer = new IndexWriter(ramdir,
new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Expand All @@ -128,7 +128,7 @@ public void assertAgainstRAMDirectory() throws Exception {
/**
* Run all queries against both the RAMDirectory and MemoryIndex, ensuring they are the same.
*/
public void assertAllQueries(MemoryIndex memory, MockRAMDirectory ramdir, Analyzer analyzer) throws Exception {
public void assertAllQueries(MemoryIndex memory, Directory ramdir, Analyzer analyzer) throws Exception {
IndexSearcher ram = new IndexSearcher(ramdir);
IndexSearcher mem = memory.createSearcher();
QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "foo", analyzer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;

public class TestMultiPassIndexSplitter extends LuceneTestCase {
IndexReader input;
int NUM_DOCS = 11;
private Random random;
MockRAMDirectory dir;
Directory dir;

@Override
protected void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

import java.util.Collections;
import java.util.Random;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import org.apache.lucene.index.codecs.SegmentInfosWriter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.Version;
Expand Down Expand Up @@ -118,7 +119,11 @@ public void writeBytes(byte[] b, int offset, int length) throws IOException {
}

@SuppressWarnings("serial")
private static class AppendingRAMDirectory extends MockRAMDirectory {
private static class AppendingRAMDirectory extends MockDirectoryWrapper {

public AppendingRAMDirectory(Directory delegate) {
super(delegate);
}

@Override
public IndexOutput createOutput(String name) throws IOException {
Expand All @@ -130,7 +135,7 @@ public IndexOutput createOutput(String name) throws IOException {
private static final String text = "the quick brown fox jumped over the lazy dog";

public void testCodec() throws Exception {
Directory dir = new AppendingRAMDirectory();
Directory dir = new AppendingRAMDirectory(new RAMDirectory());
IndexWriterConfig cfg = new IndexWriterConfig(Version.LUCENE_40, new MockAnalyzer());

cfg.setCodecProvider(new AppendingCodecProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.document.Document;
Expand All @@ -33,7 +32,7 @@
public class TestHighFreqTerms extends LuceneTestCase {

private static IndexWriter writer =null;
private static MockRAMDirectory dir = null;
private static Directory dir = null;
private static IndexReader reader =null;

public void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.SlowMultiReaderWrapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;

public class BooleanFilterTest extends LuceneTestCase {
private MockRAMDirectory directory;
private Directory directory;
private IndexReader mainReader;
private IndexReader reader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@
import org.apache.lucene.search.TermRangeFilter;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

public class ChainedFilterTest extends LuceneTestCase {
public static final int MAX = 500;

private MockRAMDirectory directory;
private Directory directory;
private IndexSearcher searcher;
private IndexReader reader;
private Query query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;

public class DuplicateFilterTest extends LuceneTestCase {
private static final String KEY_FIELD = "url";
private MockRAMDirectory directory;
private Directory directory;
private IndexReader reader;
TermQuery tq=new TermQuery(new Term("text","lucene"));
private IndexSearcher searcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;

public class FuzzyLikeThisQueryTest extends LuceneTestCase {
private MockRAMDirectory directory;
private Directory directory;
private IndexSearcher searcher;
private IndexReader reader;
private Analyzer analyzer=new MockAnalyzer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.index.SlowMultiReaderWrapper;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.OpenBitSet;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void testCachability() throws Exception
public void testMissingTerms() throws Exception {
String fieldName="field1";
Random random = newRandom();
MockRAMDirectory rd=newDirectory(random);
Directory rd=newDirectory(random);
RandomIndexWriter w = new RandomIndexWriter(random, rd);
for (int i = 0; i < 100; i++) {
Document doc=new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.Random;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.util.LuceneTestCase;

public class TestSpanRegexQuery extends LuceneTestCase {
Expand All @@ -60,7 +59,7 @@ public void tearDown() throws Exception {
}

public void testSpanRegex() throws Exception {
MockRAMDirectory directory = newDirectory(random);
Directory directory = newDirectory(random);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,
TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;

public class TestMoreLikeThis extends LuceneTestCase {
private MockRAMDirectory directory;
private Directory directory;
private IndexReader reader;
private IndexSearcher searcher;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.MockRAMDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;

public class TestComplexPhraseQuery extends LuceneTestCase {
MockRAMDirectory rd;
Directory rd;
Analyzer analyzer = new MockAnalyzer();

DocData docsContent[] = { new DocData("john smith", "1"),
Expand Down
Loading

0 comments on commit 07df8d5

Please sign in to comment.