You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2011/06/28 21:42:44 UTC
svn commit: r1140809 [6/11] - in /lucene/dev/branches/solr2452: ./
dev-tools/eclipse/ dev-tools/idea/.idea/ dev-tools/idea/lucene/contrib/
dev-tools/idea/lucene/contrib/demo/
dev-tools/idea/lucene/contrib/highlighter/
dev-tools/idea/lucene/contrib/inst...
Modified: lucene/dev/branches/solr2452/lucene/src/site/src/documentation/content/xdocs/systemrequirements.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/site/src/documentation/content/xdocs/systemrequirements.xml?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/site/src/documentation/content/xdocs/systemrequirements.xml (original)
+++ lucene/dev/branches/solr2452/lucene/src/site/src/documentation/content/xdocs/systemrequirements.xml Tue Jun 28 19:42:31 2011
@@ -15,9 +15,7 @@
<ul>
<li>Java 1.5.x or greater.</li>
<li>ANT 1.7.0 or greater.</li>
- <li>JUnit 3.8.2 if you wish to run the unit tests.</li>
- <li>CPU, Disk and Memory requirements are based on the many choices made in implementing Lucene (document size, number of documents, and number of hits retrieved to name a few.)
- The benchmarks page has some information related to performance on particular platforms.</li>
+ <li>CPU, Disk and Memory requirements are based on the many choices made in implementing Lucene (document size, number of documents, and number of hits retrieved to name a few.)</li>
</ul>
</p>
<p>Contrib modules may have other requirements, refer to their documentation and build files for information.</p>
Modified: lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java Tue Jun 28 19:42:31 2011
@@ -200,9 +200,21 @@ public class RandomIndexWriter implement
case FLOAT_64:
docValuesField.setFloat(random.nextDouble());
break;
- case INTS:
+ case VAR_INTS:
+ docValuesField.setInt(random.nextLong());
+ break;
+ case FIXED_INTS_16:
+ docValuesField.setInt(random.nextInt(Short.MAX_VALUE));
+ break;
+ case FIXED_INTS_32:
docValuesField.setInt(random.nextInt());
break;
+ case FIXED_INTS_64:
+ docValuesField.setInt(random.nextLong());
+ break;
+ case FIXED_INTS_8:
+ docValuesField.setInt(random.nextInt(128));
+ break;
default:
throw new IllegalArgumentException("no such type: " + type);
}
Modified: lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java Tue Jun 28 19:42:31 2011
@@ -388,7 +388,7 @@ public class MockDirectoryWrapper extend
}
}
- private void addFileHandle(Closeable c, String name, boolean input) {
+ synchronized void addFileHandle(Closeable c, String name, boolean input) {
Integer v = openFiles.get(name);
if (v != null) {
v = Integer.valueOf(v.intValue()+1);
@@ -416,6 +416,18 @@ public class MockDirectoryWrapper extend
addFileHandle(ii, name, true);
return ii;
}
+
+ @Override
+ public synchronized CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
+ maybeYield();
+ 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 {
@@ -481,7 +493,7 @@ public class MockDirectoryWrapper extend
delegate.close();
}
- private synchronized void removeOpenFile(Closeable c, String name) {
+ synchronized void removeOpenFile(Closeable c, String name) {
Integer v = openFiles.get(name);
// Could be null when crash() was called
if (v != null) {
Modified: lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java Tue Jun 28 19:42:31 2011
@@ -633,6 +633,11 @@ public abstract class LuceneTestCase ext
for (Thread t : Thread.getAllStackTraces().keySet()) {
rogueThreads.put(t, true);
}
+
+ if (TEST_ITER > 1) {
+ System.out.println("WARNING: you are using -Dtests.iter=n where n > 1, not all tests support this option.");
+ System.out.println("Some may crash or fail: this is not a bug.");
+ }
}
/**
@@ -713,8 +718,12 @@ public abstract class LuceneTestCase ext
throw e;
}
+ if (insanity.length != 0) {
+ reportAdditionalFailureInfo();
+ }
+
assertEquals(msg + ": Insane FieldCache usage(s) found",
- 0, insanity.length);
+ 0, insanity.length);
insanity = null;
} finally {
@@ -1104,11 +1113,17 @@ public abstract class LuceneTestCase ext
/** Returns a new field instance, using the specified random.
* See {@link #newField(String, String, Field.Store, Field.Index, Field.TermVector)} for more information */
public static Field newField(Random random, String name, String value, Store store, Index index, TermVector tv) {
+
if (usually(random)) {
// most of the time, don't modify the params
return new Field(name, value, store, index, tv);
}
+ if (random.nextBoolean()) {
+ // tickle any code still relying on field names being interned:
+ name = new String(name);
+ }
+
if (!index.isIndexed())
return new Field(name, value, store, index, tv);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestExternalCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestExternalCodecs.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestExternalCodecs.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestExternalCodecs.java Tue Jun 28 19:42:31 2011
@@ -305,7 +305,7 @@ public class TestExternalCodecs extends
}
@Override
- public SeekStatus seek(BytesRef term, boolean useCache) {
+ public SeekStatus seekCeil(BytesRef term, boolean useCache) {
current = term.utf8ToString();
it = null;
if (ramField.termToDocs.containsKey(current)) {
@@ -320,7 +320,7 @@ public class TestExternalCodecs extends
}
@Override
- public SeekStatus seek(long ord) {
+ public void seekExact(long ord) {
throw new UnsupportedOperationException();
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearch.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearch.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearch.java Tue Jun 28 19:42:31 2011
@@ -112,7 +112,7 @@ public class TestSearch extends LuceneTe
Sort sort = new Sort(new SortField[] {
SortField.FIELD_SCORE,
- new SortField("id", SortField.INT)});
+ new SortField("id", SortField.Type.INT)});
QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, "contents", analyzer);
parser.setPhraseSlop(4);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java Tue Jun 28 19:42:31 2011
@@ -112,7 +112,7 @@ public class TestSearchForDuplicates ext
final Sort sort = new Sort(new SortField[] {
SortField.FIELD_SCORE,
- new SortField(ID_FIELD, SortField.INT)});
+ new SortField(ID_FIELD, SortField.Type.INT)});
ScoreDoc[] hits = searcher.search(query, null, MAX_DOCS, sort).scoreDocs;
printHits(out, hits, searcher);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/Test2BTerms.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/Test2BTerms.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/Test2BTerms.java Tue Jun 28 19:42:31 2011
@@ -255,7 +255,7 @@ public class Test2BTerms extends LuceneT
final long t1 = System.currentTimeMillis();
System.out.println(" took " + (t1-t0) + " millis");
- TermsEnum.SeekStatus result = termsEnum.seek(term);
+ TermsEnum.SeekStatus result = termsEnum.seekCeil(term);
if (result != TermsEnum.SeekStatus.FOUND) {
if (result == TermsEnum.SeekStatus.END) {
System.out.println(" FAILED: got END");
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java Tue Jun 28 19:42:31 2011
@@ -1075,8 +1075,8 @@ public class TestAddIndexes extends Luce
IndexWriter w3 = new IndexWriter(dir, conf);
w3.addIndexes(readers);
w3.close();
- // we should now see segments_X, segments.gen,_Y.cfs, _Z.fnx
- assertEquals("Only one compound segment should exist", 4, dir.listAll().length);
+ // we should now see segments_X, segments.gen,_Y.cfs,_Y.cfe, _Z.fnx
+ assertEquals("Only one compound segment should exist", 5, dir.listAll().length);
}
// LUCENE-3126: tests that if a non-CFS segment is copied, it is converted to
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Tue Jun 28 19:42:31 2011
@@ -39,8 +39,8 @@ import org.apache.lucene.search.IndexSea
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Similarity;
-import org.apache.lucene.search.SimilarityProvider;
import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Bits;
@@ -536,7 +536,7 @@ public class TestBackwardsCompatibility
// figure out which field number corresponds to
// "content", and then set our expected file names below
// accordingly:
- CompoundFileReader cfsReader = new CompoundFileReader(dir, "_0.cfs");
+ CompoundFileDirectory cfsReader = dir.openCompoundInput("_0.cfs", 1024);
FieldInfos fieldInfos = new FieldInfos(cfsReader, "_0.fnm");
int contentFieldIndex = -1;
for (FieldInfo fi : fieldInfos) {
@@ -549,7 +549,7 @@ public class TestBackwardsCompatibility
assertTrue("could not locate the 'content' field number in the _2.cfs segment", contentFieldIndex != -1);
// Now verify file names:
- String[] expected = new String[] {"_0.cfs",
+ String[] expected = new String[] {"_0.cfs", "_0.cfe",
"_0_1.del",
"_0_1.s" + contentFieldIndex,
"segments_2",
@@ -632,24 +632,24 @@ public class TestBackwardsCompatibility
// should be found exactly
assertEquals(TermsEnum.SeekStatus.FOUND,
- terms.seek(aaaTerm));
+ terms.seekCeil(aaaTerm));
assertEquals(35, countDocs(terms.docs(null, null)));
assertNull(terms.next());
// should hit end of field
assertEquals(TermsEnum.SeekStatus.END,
- terms.seek(new BytesRef("bbb")));
+ terms.seekCeil(new BytesRef("bbb")));
assertNull(terms.next());
// should seek to aaa
assertEquals(TermsEnum.SeekStatus.NOT_FOUND,
- terms.seek(new BytesRef("a")));
+ terms.seekCeil(new BytesRef("a")));
assertTrue(terms.term().bytesEquals(aaaTerm));
assertEquals(35, countDocs(terms.docs(null, null)));
assertNull(terms.next());
assertEquals(TermsEnum.SeekStatus.FOUND,
- terms.seek(aaaTerm));
+ terms.seekCeil(aaaTerm));
assertEquals(35, countDocs(terms.docs(null, null)));
assertNull(terms.next());
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCodecs.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCodecs.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCodecs.java Tue Jun 28 19:42:31 2011
@@ -266,7 +266,7 @@ public class TestCodecs extends LuceneTe
assertNull(termsEnum.next());
for(int i=0;i<NUM_TERMS;i++) {
- assertEquals(termsEnum.seek(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND);
+ assertEquals(termsEnum.seekCeil(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND);
}
assertNull(fieldsEnum.next());
@@ -461,7 +461,7 @@ public class TestCodecs extends LuceneTe
// Test random seek:
TermData term = field.terms[TestCodecs.random.nextInt(field.terms.length)];
- TermsEnum.SeekStatus status = termsEnum.seek(new BytesRef(term.text2));
+ TermsEnum.SeekStatus status = termsEnum.seekCeil(new BytesRef(term.text2));
assertEquals(status, TermsEnum.SeekStatus.FOUND);
assertEquals(term.docs.length, termsEnum.docFreq());
if (field.omitTF) {
@@ -473,13 +473,14 @@ public class TestCodecs extends LuceneTe
// Test random seek by ord:
final int idx = TestCodecs.random.nextInt(field.terms.length);
term = field.terms[idx];
+ boolean success = false;
try {
- status = termsEnum.seek(idx);
+ termsEnum.seekExact(idx);
+ success = true;
} catch (UnsupportedOperationException uoe) {
// ok -- skip it
- status = null;
}
- if (status != null) {
+ if (success) {
assertEquals(status, TermsEnum.SeekStatus.FOUND);
assertTrue(termsEnum.term().bytesEquals(new BytesRef(term.text2)));
assertEquals(term.docs.length, termsEnum.docFreq());
@@ -493,21 +494,21 @@ public class TestCodecs extends LuceneTe
// Test seek to non-existent terms:
for(int i=0;i<100;i++) {
final String text2 = _TestUtil.randomUnicodeString(random) + ".";
- status = termsEnum.seek(new BytesRef(text2));
+ status = termsEnum.seekCeil(new BytesRef(text2));
assertTrue(status == TermsEnum.SeekStatus.NOT_FOUND ||
status == TermsEnum.SeekStatus.END);
}
// Seek to each term, backwards:
for(int i=field.terms.length-1;i>=0;i--) {
- assertEquals(Thread.currentThread().getName() + ": field=" + field.fieldInfo.name + " term=" + field.terms[i].text2, TermsEnum.SeekStatus.FOUND, termsEnum.seek(new BytesRef(field.terms[i].text2)));
+ assertEquals(Thread.currentThread().getName() + ": field=" + field.fieldInfo.name + " term=" + field.terms[i].text2, TermsEnum.SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef(field.terms[i].text2)));
assertEquals(field.terms[i].docs.length, termsEnum.docFreq());
}
// Seek to each term by ord, backwards
for(int i=field.terms.length-1;i>=0;i--) {
try {
- assertEquals(Thread.currentThread().getName() + ": field=" + field.fieldInfo.name + " term=" + field.terms[i].text2, TermsEnum.SeekStatus.FOUND, termsEnum.seek(i));
+ termsEnum.seekExact(i);
assertEquals(field.terms[i].docs.length, termsEnum.docFreq());
assertTrue(termsEnum.term().bytesEquals(new BytesRef(field.terms[i].text2)));
} catch (UnsupportedOperationException uoe) {
@@ -515,7 +516,7 @@ public class TestCodecs extends LuceneTe
}
// Seek to non-existent empty-string term
- status = termsEnum.seek(new BytesRef(""));
+ status = termsEnum.seekCeil(new BytesRef(""));
assertNotNull(status);
//assertEquals(TermsEnum.SeekStatus.NOT_FOUND, status);
@@ -523,7 +524,7 @@ public class TestCodecs extends LuceneTe
assertTrue(termsEnum.term().bytesEquals(new BytesRef(field.terms[0].text2)));
// Test docs enum
- termsEnum.seek(new BytesRef(""));
+ termsEnum.seekCeil(new BytesRef(""));
upto = 0;
do {
term = field.terms[upto];
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java Tue Jun 28 19:42:31 2011
@@ -23,6 +23,8 @@ import java.io.File;
import org.apache.lucene.util.LuceneTestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
+
+import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
@@ -200,11 +202,11 @@ public class TestCompoundFile extends Lu
for (int i=0; i<data.length; i++) {
String name = "t" + data[i];
createSequenceFile(dir, name, (byte) 0, data[i]);
- CompoundFileWriter csw = new CompoundFileWriter(dir, name + ".cfs");
- csw.addFile(name);
+ CompoundFileDirectory csw = dir.createCompoundOutput(name + ".cfs");
+ dir.copy(csw, name, name);
csw.close();
- CompoundFileReader csr = new CompoundFileReader(dir, name + ".cfs");
+ CompoundFileDirectory csr = dir.openCompoundInput(name + ".cfs", 1024);
IndexInput expected = dir.openInput(name);
IndexInput actual = csr.openInput(name);
assertSameStreams(name, expected, actual);
@@ -223,12 +225,12 @@ public class TestCompoundFile extends Lu
createSequenceFile(dir, "d1", (byte) 0, 15);
createSequenceFile(dir, "d2", (byte) 0, 114);
- CompoundFileWriter csw = new CompoundFileWriter(dir, "d.csf");
- csw.addFile("d1");
- csw.addFile("d2");
+ CompoundFileDirectory csw = dir.createCompoundOutput("d.cfs");
+ dir.copy(csw, "d1", "d1");
+ dir.copy(csw, "d2", "d2");
csw.close();
- CompoundFileReader csr = new CompoundFileReader(dir, "d.csf");
+ CompoundFileDirectory csr = dir.openCompoundInput("d.cfs", 1024);
IndexInput expected = dir.openInput("d1");
IndexInput actual = csr.openInput("d1");
assertSameStreams("d1", expected, actual);
@@ -273,17 +275,18 @@ public class TestCompoundFile extends Lu
createRandomFile(dir, segment + ".notIn2", 51);
// Now test
- CompoundFileWriter csw = new CompoundFileWriter(dir, "test.cfs");
+ CompoundFileDirectory csw = dir.createCompoundOutput("test.cfs");
final String data[] = new String[] {
".zero", ".one", ".ten", ".hundred", ".big1", ".big2", ".big3",
".big4", ".big5", ".big6", ".big7"
};
for (int i=0; i<data.length; i++) {
- csw.addFile(segment + data[i]);
+ String fileName = segment + data[i];
+ dir.copy(csw, fileName, fileName);
}
csw.close();
- CompoundFileReader csr = new CompoundFileReader(dir, "test.cfs");
+ CompoundFileDirectory csr = dir.openCompoundInput("test.cfs", 1024);
for (int i=0; i<data.length; i++) {
IndexInput check = dir.openInput(segment + data[i]);
IndexInput test = csr.openInput(segment + data[i]);
@@ -302,10 +305,11 @@ public class TestCompoundFile extends Lu
* the size of each file is 1000 bytes.
*/
private void setUp_2() throws IOException {
- CompoundFileWriter cw = new CompoundFileWriter(dir, "f.comp");
+ CompoundFileDirectory cw = dir.createCompoundOutput("f.comp");
for (int i=0; i<20; i++) {
createSequenceFile(dir, "f" + i, (byte) 0, 2000);
- cw.addFile("f" + i);
+ String fileName = "f" + i;
+ dir.copy(cw, fileName, fileName);
}
cw.close();
}
@@ -350,26 +354,9 @@ public class TestCompoundFile extends Lu
}
}
-
- static boolean isCSIndexInput(IndexInput is) {
- return is instanceof CompoundFileReader.CSIndexInput;
- }
-
- static boolean isCSIndexInputOpen(IndexInput is) throws IOException {
- if (isCSIndexInput(is)) {
- CompoundFileReader.CSIndexInput cis =
- (CompoundFileReader.CSIndexInput) is;
-
- return _TestHelper.isSimpleFSIndexInputOpen(cis.base);
- } else {
- return false;
- }
- }
-
-
public void testClonedStreamsClosing() throws IOException {
setUp_2();
- CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
+ CompoundFileDirectory cr = dir.openCompoundInput("f.comp", 1024);
// basic clone
IndexInput expected = dir.openInput("f11");
@@ -379,10 +366,8 @@ public class TestCompoundFile extends Lu
assertTrue(_TestHelper.isSimpleFSIndexInputOpen(expected));
IndexInput one = cr.openInput("f11");
- assertTrue(isCSIndexInputOpen(one));
IndexInput two = (IndexInput) one.clone();
- assertTrue(isCSIndexInputOpen(two));
assertSameStreams("basic clone one", expected, one);
expected.seek(0);
@@ -390,7 +375,6 @@ public class TestCompoundFile extends Lu
// Now close the first stream
one.close();
- assertTrue("Only close when cr is closed", isCSIndexInputOpen(one));
// The following should really fail since we couldn't expect to
// access a file once close has been called on it (regardless of
@@ -402,8 +386,6 @@ public class TestCompoundFile extends Lu
// Now close the compound reader
cr.close();
- assertFalse("Now closed one", isCSIndexInputOpen(one));
- assertFalse("Now closed two", isCSIndexInputOpen(two));
// The following may also fail since the compound stream is closed
expected.seek(0);
@@ -426,7 +408,7 @@ public class TestCompoundFile extends Lu
*/
public void testRandomAccess() throws IOException {
setUp_2();
- CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
+ CompoundFileDirectory cr = dir.openCompoundInput("f.comp", 1024);
// Open two files
IndexInput e1 = dir.openInput("f11");
@@ -505,7 +487,7 @@ public class TestCompoundFile extends Lu
*/
public void testRandomAccessClones() throws IOException {
setUp_2();
- CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
+ CompoundFileDirectory cr = dir.openCompoundInput("f.comp", 1024);
// Open two files
IndexInput e1 = cr.openInput("f11");
@@ -582,7 +564,7 @@ public class TestCompoundFile extends Lu
public void testFileNotFound() throws IOException {
setUp_2();
- CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
+ CompoundFileDirectory cr = dir.openCompoundInput("f.comp", 1024);
// Open two files
try {
@@ -600,7 +582,7 @@ public class TestCompoundFile extends Lu
public void testReadPastEOF() throws IOException {
setUp_2();
- CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
+ CompoundFileDirectory cr = dir.openCompoundInput("f.comp", 1024);
IndexInput is = cr.openInput("f2");
is.seek(is.length() - 10);
byte b[] = new byte[100];
@@ -653,11 +635,11 @@ public class TestCompoundFile extends Lu
createSequenceFile(dir, "d1", (byte) 0, 15);
Directory newDir = newDirectory();
- CompoundFileWriter csw = new CompoundFileWriter(newDir, "d.csf");
- csw.addFile("d1", dir);
+ CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
+ dir.copy(csw, "d1", "d1");
csw.close();
- CompoundFileReader csr = new CompoundFileReader(newDir, "d.csf");
+ CompoundFileDirectory csr = newDir.openCompoundInput("d.cfs", 1024);
IndexInput expected = dir.openInput("d1");
IndexInput actual = csr.openInput("d1");
assertSameStreams("d1", expected, actual);
@@ -668,5 +650,72 @@ public class TestCompoundFile extends Lu
newDir.close();
}
+
+
+ public void testAppend() throws IOException {
+ Directory newDir = newDirectory();
+ CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
+ int size = 5 + random.nextInt(128);
+ for (int j = 0; j < 2; j++) {
+ IndexOutput os = csw.createOutput("seg" + j + "_foo.txt");
+ for (int i = 0; i < size; i++) {
+ os.writeInt(i);
+ }
+ os.close();
+ String[] listAll = newDir.listAll();
+ assertEquals(1, listAll.length);
+ assertEquals("d.cfs", listAll[0]);
+ }
+ createSequenceFile(dir, "d1", (byte) 0, 15);
+ dir.copy(csw, "d1", "d1");
+ String[] listAll = newDir.listAll();
+ assertEquals(1, listAll.length);
+ assertEquals("d.cfs", listAll[0]);
+ csw.close();
+ CompoundFileDirectory csr = newDir.openCompoundInput("d.cfs", 1024);
+ for (int j = 0; j < 2; j++) {
+ IndexInput openInput = csr.openInput("seg" + j + "_foo.txt");
+ assertEquals(size * 4, openInput.length());
+ for (int i = 0; i < size; i++) {
+ assertEquals(i, openInput.readInt());
+ }
+
+ openInput.close();
+
+ }
+ IndexInput expected = dir.openInput("d1");
+ IndexInput actual = csr.openInput("d1");
+ assertSameStreams("d1", expected, actual);
+ assertSameSeekBehavior("d1", expected, actual);
+ expected.close();
+ actual.close();
+ csr.close();
+ newDir.close();
+ }
+
+ public void testAppendTwice() throws IOException {
+ Directory newDir = newDirectory();
+ CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
+ createSequenceFile(newDir, "d1", (byte) 0, 15);
+ IndexOutput out = csw.createOutput("d.xyz");
+ out.writeInt(0);
+ try {
+ newDir.copy(csw, "d1", "d1");
+ fail("file does already exist");
+ } catch (IOException e) {
+ //
+ }
+ out.close();
+ assertEquals(1, csw.listAll().length);
+ assertEquals("d.xyz", csw.listAll()[0]);
+
+ csw.close();
+
+ CompoundFileDirectory cfr = newDir.openCompoundInput("d.cfs", 1024);
+ assertEquals(1, cfr.listAll().length);
+ assertEquals("d.xyz", cfr.listAll()[0]);
+ cfr.close();
+ newDir.close();
+ }
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java Tue Jun 28 19:42:31 2011
@@ -166,14 +166,14 @@ public class TestDirectoryReader extends
// test mixing up TermDocs and TermEnums from different readers.
TermsEnum te2 = MultiFields.getTerms(mr2, "body").iterator();
- te2.seek(new BytesRef("wow"));
+ te2.seekCeil(new BytesRef("wow"));
DocsEnum td = MultiFields.getTermDocsEnum(mr2,
MultiFields.getDeletedDocs(mr2),
"body",
te2.term());
TermsEnum te3 = MultiFields.getTerms(mr3, "body").iterator();
- te3.seek(new BytesRef("wow"));
+ te3.seekCeil(new BytesRef("wow"));
td = te3.docs(MultiFields.getDeletedDocs(mr3),
td);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java Tue Jun 28 19:42:31 2011
@@ -479,7 +479,7 @@ public class TestDocTermOrds extends Luc
Terms terms = MultiFields.getTerms(r, "field");
if (terms != null) {
TermsEnum termsEnum = terms.iterator();
- TermsEnum.SeekStatus result = termsEnum.seek(prefixRef, false);
+ TermsEnum.SeekStatus result = termsEnum.seekCeil(prefixRef, false);
if (result != TermsEnum.SeekStatus.END) {
assertFalse("term=" + termsEnum.term().utf8ToString() + " matches prefix=" + prefixRef.utf8ToString(), termsEnum.term().startsWith(prefixRef));
} else {
@@ -494,7 +494,7 @@ public class TestDocTermOrds extends Luc
if (VERBOSE) {
System.out.println("TEST: TERMS:");
- te.seek(0);
+ te.seekExact(0);
while(true) {
System.out.println(" ord=" + te.ord() + " term=" + te.term().utf8ToString());
if (te.next() == null) {
@@ -515,7 +515,7 @@ public class TestDocTermOrds extends Luc
while(true) {
final int chunk = iter.read(buffer);
for(int idx=0;idx<chunk;idx++) {
- assertEquals(TermsEnum.SeekStatus.FOUND, te.seek((long) buffer[idx]));
+ te.seekExact((long) buffer[idx]);
final BytesRef expected = termsArray[answers[upto++]];
if (VERBOSE) {
System.out.println(" exp=" + expected.utf8ToString() + " actual=" + te.term().utf8ToString());
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java Tue Jun 28 19:42:31 2011
@@ -39,7 +39,6 @@ public class TestDocumentsWriterDeleteQu
for (int i = 0; i < ids.length; i++) {
ids[i] = random.nextInt();
}
- Term template = new Term("id");
DeleteSlice slice1 = queue.newSlice();
DeleteSlice slice2 = queue.newSlice();
BufferedDeletes bd1 = new BufferedDeletes(false);
@@ -50,7 +49,7 @@ public class TestDocumentsWriterDeleteQu
for (int j = 0; j < ids.length; j++) {
Integer i = ids[j];
// create an array here since we compare identity below against tailItem
- Term[] term = new Term[] {template.createTerm(i.toString())};
+ Term[] term = new Term[] {new Term("id", i.toString())};
uniqueValues.add(term[0]);
queue.addDelete(term);
if (random.nextInt(20) == 0 || j == ids.length - 1) {
@@ -79,16 +78,14 @@ public class TestDocumentsWriterDeleteQu
private void assertAllBetween(int start, int end, BufferedDeletes deletes,
Integer[] ids) {
- Term template = new Term("id");
for (int i = start; i <= end; i++) {
- assertEquals(Integer.valueOf(end), deletes.terms.get(template
- .createTerm(ids[i].toString())));
+ assertEquals(Integer.valueOf(end), deletes.terms.get(new Term("id",
+ ids[i].toString())));
}
}
public void testClear() {
DocumentsWriterDeleteQueue queue = new DocumentsWriterDeleteQueue();
- Term template = new Term("id");
assertFalse(queue.anyChanges());
queue.clear();
assertFalse(queue.anyChanges());
@@ -96,7 +93,7 @@ public class TestDocumentsWriterDeleteQu
int termsSinceFreeze = 0;
int queriesSinceFreeze = 0;
for (int i = 0; i < size; i++) {
- Term term = template.createTerm("" + i);
+ Term term = new Term("id", "" + i);
if (random.nextInt(10) == 0) {
queue.addDelete(new TermQuery(term));
queriesSinceFreeze++;
@@ -116,12 +113,11 @@ public class TestDocumentsWriterDeleteQu
public void testAnyChanges() {
DocumentsWriterDeleteQueue queue = new DocumentsWriterDeleteQueue();
- Term template = new Term("id");
final int size = 200 + random.nextInt(500) * RANDOM_MULTIPLIER;
int termsSinceFreeze = 0;
int queriesSinceFreeze = 0;
for (int i = 0; i < size; i++) {
- Term term = template.createTerm("" + i);
+ Term term = new Term("id", "" + i);
if (random.nextInt(10) == 0) {
queue.addDelete(new TermQuery(term));
queriesSinceFreeze++;
@@ -147,10 +143,9 @@ public class TestDocumentsWriterDeleteQu
Set<Term> uniqueValues = new HashSet<Term>();
final int size = 10000 + random.nextInt(500) * RANDOM_MULTIPLIER;
Integer[] ids = new Integer[size];
- Term template = new Term("id");
for (int i = 0; i < ids.length; i++) {
ids[i] = random.nextInt();
- uniqueValues.add(template.createTerm(ids[i].toString()));
+ uniqueValues.add(new Term("id", ids[i].toString()));
}
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger index = new AtomicInteger(0);
@@ -204,10 +199,9 @@ public class TestDocumentsWriterDeleteQu
} catch (InterruptedException e) {
throw new ThreadInterruptedException(e);
}
- Term template = new Term("id");
int i = 0;
while ((i = index.getAndIncrement()) < ids.length) {
- Term term = template.createTerm(ids[i].toString());
+ Term term = new Term("id", ids[i].toString());
queue.add(term, slice);
assertTrue(slice.isTailItem(term));
slice.apply(deletes, BufferedDeletes.MAX_INT);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java Tue Jun 28 19:42:31 2011
@@ -59,6 +59,11 @@ public class TestFieldsReader extends Lu
IndexWriter writer = new IndexWriter(dir, conf);
writer.addDocument(testDoc);
writer.close();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
FaultyIndexInput.doFail = false;
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java Tue Jun 28 19:42:31 2011
@@ -155,7 +155,7 @@ public class TestFilterIndexReader exten
assertTrue(terms.term().utf8ToString().indexOf('e') != -1);
}
- assertEquals(TermsEnum.SeekStatus.FOUND, terms.seek(new BytesRef("one")));
+ assertEquals(TermsEnum.SeekStatus.FOUND, terms.seekCeil(new BytesRef("one")));
DocsAndPositionsEnum positions = terms.docsAndPositions(MultiFields.getDeletedDocs(reader),
null);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlex.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlex.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlex.java Tue Jun 28 19:42:31 2011
@@ -53,7 +53,7 @@ public class TestFlex extends LuceneTest
IndexReader r = w.getReader();
TermsEnum terms = MultiFields.getTerms(r, "field3").iterator();
- assertEquals(TermsEnum.SeekStatus.END, terms.seek(new BytesRef("abc")));
+ assertEquals(TermsEnum.SeekStatus.END, terms.seekCeil(new BytesRef("abc")));
r.close();
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java Tue Jun 28 19:42:31 2011
@@ -50,28 +50,27 @@ public class TestFlushByRamOrCountsPolic
public void testFlushByRam() throws CorruptIndexException,
LockObtainFailedException, IOException, InterruptedException {
- int[] numThreads = new int[] { 3 + random.nextInt(12), 1 };
- for (int i = 0; i < numThreads.length; i++) {
- runFlushByRam(numThreads[i],
- 1 + random.nextInt(10) + random.nextDouble(), false);
- }
-
- for (int i = 0; i < numThreads.length; i++) {
- // with a 256 mb ram buffer we should never stall
- runFlushByRam(numThreads[i], 256.d, true);
- }
+ final double ramBuffer = (TEST_NIGHTLY ? 1 : 10) + atLeast(2)
+ + random.nextDouble();
+ runFlushByRam(1 + random.nextInt(TEST_NIGHTLY ? 5 : 1), ramBuffer, false);
+ }
+
+ public void testFlushByRamLargeBuffer() throws CorruptIndexException,
+ LockObtainFailedException, IOException, InterruptedException {
+ // with a 256 mb ram buffer we should never stall
+ runFlushByRam(1 + random.nextInt(TEST_NIGHTLY ? 5 : 1), 256.d, true);
}
protected void runFlushByRam(int numThreads, double maxRamMB,
boolean ensureNotStalled) throws IOException, CorruptIndexException,
LockObtainFailedException, InterruptedException {
- final int numDocumentsToIndex = 50 + random.nextInt(150);
+ final int numDocumentsToIndex = 10 + atLeast(30);
AtomicInteger numDocs = new AtomicInteger(numDocumentsToIndex);
Directory dir = newDirectory();
MockDefaultFlushPolicy flushPolicy = new MockDefaultFlushPolicy();
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random)).setFlushPolicy(flushPolicy);
- final int numDWPT = 1 + random.nextInt(8);
+ final int numDWPT = 1 + atLeast(2);
DocumentsWriterPerThreadPool threadPool = new ThreadAffinityDocumentsWriterThreadPool(
numDWPT);
iwc.setIndexerThreadPool(threadPool);
@@ -118,21 +117,21 @@ public class TestFlushByRamOrCountsPolic
public void testFlushDocCount() throws CorruptIndexException,
LockObtainFailedException, IOException, InterruptedException {
- int[] numThreads = new int[] { 3 + random.nextInt(12), 1 };
+ int[] numThreads = new int[] { 2 + atLeast(1), 1 };
for (int i = 0; i < numThreads.length; i++) {
- final int numDocumentsToIndex = 50 + random.nextInt(150);
+ final int numDocumentsToIndex = 50 + atLeast(30);
AtomicInteger numDocs = new AtomicInteger(numDocumentsToIndex);
Directory dir = newDirectory();
MockDefaultFlushPolicy flushPolicy = new MockDefaultFlushPolicy();
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random)).setFlushPolicy(flushPolicy);
- final int numDWPT = 1 + random.nextInt(8);
+ final int numDWPT = 1 + atLeast(2);
DocumentsWriterPerThreadPool threadPool = new ThreadAffinityDocumentsWriterThreadPool(
numDWPT);
iwc.setIndexerThreadPool(threadPool);
- iwc.setMaxBufferedDocs(2 + random.nextInt(50));
+ iwc.setMaxBufferedDocs(2 + atLeast(10));
iwc.setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH);
iwc.setMaxBufferedDeleteTerms(IndexWriterConfig.DISABLE_AUTO_FLUSH);
IndexWriter writer = new IndexWriter(dir, iwc);
@@ -170,7 +169,7 @@ public class TestFlushByRamOrCountsPolic
public void testRandom() throws IOException, InterruptedException {
final int numThreads = 1 + random.nextInt(8);
- final int numDocumentsToIndex = 100 + random.nextInt(300);
+ final int numDocumentsToIndex = 50 + atLeast(70);
AtomicInteger numDocs = new AtomicInteger(numDocumentsToIndex);
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT,
@@ -317,11 +316,7 @@ public class TestFlushByRamOrCountsPolic
ramSize = newRamSize;
}
if (doRandomCommit) {
- int commit;
- synchronized (random) {
- commit = random.nextInt(20);
- }
- if (commit == 0) {
+ if (rarely()) {
writer.commit();
}
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java Tue Jun 28 19:42:31 2011
@@ -20,6 +20,7 @@ package org.apache.lucene.index;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.Similarity;
+import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
@@ -91,7 +92,7 @@ public class TestIndexFileDeleter extend
// figure out which field number corresponds to
// "content", and then set our expected file names below
// accordingly:
- CompoundFileReader cfsReader = new CompoundFileReader(dir, "_2.cfs");
+ CompoundFileDirectory cfsReader = dir.openCompoundInput("_2.cfs", 1024);
FieldInfos fieldInfos = new FieldInfos(cfsReader, "_2.fnm");
int contentFieldIndex = -1;
for (FieldInfo fi : fieldInfos) {
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Tue Jun 28 19:42:31 2011
@@ -687,7 +687,8 @@ public class TestIndexReaderReopen exten
public void testThreadSafety() throws Exception {
final Directory dir = newDirectory();
- final int n = atLeast(30);
+ // NOTE: this also controls the number of threads!
+ final int n = _TestUtil.nextInt(random, 20, 40);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random)));
for (int i = 0; i < n; i++) {
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java Tue Jun 28 19:42:31 2011
@@ -30,9 +30,6 @@ import org.apache.lucene.analysis.MockTo
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.document.Field.Index;
-import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.document.Field.TermVector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
@@ -940,7 +937,7 @@ public class TestIndexWriterDelete exten
count++;
}
}
- assertTrue("flush happened too quickly during " + (doIndexing ? "indexing" : "deleting") + " count=" + count, count > 3000);
+ assertTrue("flush happened too quickly during " + (doIndexing ? "indexing" : "deleting") + " count=" + count, count > 2500);
}
w.close();
dir.close();
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java Tue Jun 28 19:42:31 2011
@@ -163,7 +163,7 @@ public class TestIndexWriterUnicode exte
BytesRef tr = new BytesRef(it.next());
assertEquals("seek failed for term=" + termDesc(tr.utf8ToString()),
TermsEnum.SeekStatus.FOUND,
- terms.seek(tr));
+ terms.seekCeil(tr));
}
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java Tue Jun 28 19:42:31 2011
@@ -184,6 +184,8 @@ public class TestIndexWriterWithThreads
if (threads[i].addCount > 0) {
done = true;
break;
+ } else if (!threads[i].isAlive()) {
+ fail("thread failed before indexing a single document");
}
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java Tue Jun 28 19:42:31 2011
@@ -430,7 +430,7 @@ public class TestNRTThreads extends Luce
trigger = totTermCount.get()/10;
//System.out.println("trigger " + trigger);
shift = random.nextInt(trigger);
- termsEnum.seek(new BytesRef(""));
+ termsEnum.seekCeil(new BytesRef(""));
continue;
}
seenTermCount++;
@@ -579,7 +579,7 @@ public class TestNRTThreads extends Luce
private int runQuery(IndexSearcher s, Query q) throws Exception {
s.search(q, 10);
- return s.search(q, null, 10, new Sort(new SortField("title", SortField.STRING))).totalHits;
+ return s.search(q, null, 10, new Sort(new SortField("title", SortField.Type.STRING))).totalHits;
}
private void smokeTestReader(IndexReader r) throws Exception {
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestPerSegmentDeletes.java Tue Jun 28 19:42:31 2011
@@ -24,7 +24,6 @@ import java.util.Random;
import java.util.Map;
import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.index.TermsEnum.SeekStatus;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
@@ -225,8 +224,7 @@ public class TestPerSegmentDeletes exten
Fields fields = MultiFields.getFields(reader);
Terms cterms = fields.terms(term.field);
TermsEnum ctermsEnum = cterms.iterator();
- SeekStatus ss = ctermsEnum.seek(new BytesRef(term.text()), false);
- if (ss.equals(SeekStatus.FOUND)) {
+ if (ctermsEnum.seekExact(new BytesRef(term.text()), false)) {
DocsEnum docsEnum = ctermsEnum.docs(bits, null);
return toArray(docsEnum);
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestRollback.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestRollback.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestRollback.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestRollback.java Tue Jun 28 19:42:31 2011
@@ -40,13 +40,12 @@ public class TestRollback extends Lucene
// If buffer size is small enough to cause a flush, errors ensue...
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMaxBufferedDocs(2).setOpenMode(IndexWriterConfig.OpenMode.APPEND));
- Term pkTerm = new Term("pk", "");
for (int i = 0; i < 3; i++) {
Document doc = new Document();
String value = Integer.toString(i);
doc.add(newField("pk", value, Store.YES, Index.ANALYZED_NO_NORMS));
doc.add(newField("text", "foo", Store.YES, Index.ANALYZED_NO_NORMS));
- w.updateDocument(pkTerm.createTerm(value), doc);
+ w.updateDocument(new Term("pk", value), doc);
}
w.rollback();
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java Tue Jun 28 19:42:31 2011
@@ -60,7 +60,7 @@ public class TestSegmentTermDocs extends
assertEquals(indexDivisor, reader.getTermInfosIndexDivisor());
TermsEnum terms = reader.fields().terms(DocHelper.TEXT_FIELD_2_KEY).iterator();
- terms.seek(new BytesRef("field"));
+ terms.seekCeil(new BytesRef("field"));
DocsEnum termDocs = terms.docs(reader.getDeletedDocs(), null);
if (termDocs.nextDoc() != DocsEnum.NO_MORE_DOCS) {
int docId = termDocs.docID();
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java Tue Jun 28 19:42:31 2011
@@ -93,7 +93,7 @@ public class TestSegmentTermEnum extends
assertEquals("bbb", terms.term().utf8ToString());
assertNull(terms.next());
- assertEquals(TermsEnum.SeekStatus.FOUND, terms.seek(ordB));
+ terms.seekExact(ordB);
assertEquals("bbb", terms.term().utf8ToString());
reader.close();
}
@@ -119,7 +119,7 @@ public class TestSegmentTermEnum extends
// create enumeration of terms after term 'aaa',
// including 'aaa'
- termEnum.seek(new BytesRef("aaa"));
+ termEnum.seekCeil(new BytesRef("aaa"));
// assert that term is 'aaa'
assertEquals("aaa", termEnum.term().utf8ToString());
assertEquals(200, termEnum.docFreq());
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressAdvance.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressAdvance.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressAdvance.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressAdvance.java Tue Jun 28 19:42:31 2011
@@ -74,11 +74,11 @@ public class TestStressAdvance extends L
if (VERBOSE) {
System.out.println("\nTEST: iter=" + iter + " iter2=" + iter2);
}
- assertEquals(TermsEnum.SeekStatus.FOUND, te.seek(new BytesRef("a")));
+ assertEquals(TermsEnum.SeekStatus.FOUND, te.seekCeil(new BytesRef("a")));
de = te.docs(null, de);
testOne(de, aDocIDs);
- assertEquals(TermsEnum.SeekStatus.FOUND, te.seek(new BytesRef("b")));
+ assertEquals(TermsEnum.SeekStatus.FOUND, te.seekCeil(new BytesRef("b")));
de = te.docs(null, de);
testOne(de, bDocIDs);
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java Tue Jun 28 19:42:31 2011
@@ -312,7 +312,6 @@ public class TestStressIndexing2 extends
int[] r2r1 = new int[r2.maxDoc()]; // r2 id to r1 id mapping
// create mapping from id2 space to id2 based on idField
- idField = StringHelper.intern(idField);
final Fields f1 = MultiFields.getFields(r1);
if (f1 == null) {
// make sure r2 is empty
@@ -669,7 +668,7 @@ public class TestStressIndexing2 extends
ArrayList<Field> fields = new ArrayList<Field>();
String idString = getIdString();
- Field idField = newField(idTerm.field(), idString, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
+ Field idField = newField("id", idString, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
fields.add(idField);
int nFields = nextInt(maxFields);
@@ -720,7 +719,7 @@ public class TestStressIndexing2 extends
if (VERBOSE) {
System.out.println(Thread.currentThread().getName() + ": indexing id:" + idString);
}
- w.updateDocument(idTerm.createTerm(idString), d);
+ w.updateDocument(new Term("id", idString), d);
//System.out.println(Thread.currentThread().getName() + ": indexing "+d);
docs.put(idString, d);
}
@@ -730,7 +729,7 @@ public class TestStressIndexing2 extends
if (VERBOSE) {
System.out.println(Thread.currentThread().getName() + ": del id:" + idString);
}
- w.deleteDocuments(idTerm.createTerm(idString));
+ w.deleteDocuments(new Term("id", idString));
docs.remove(idString);
}
@@ -739,7 +738,7 @@ public class TestStressIndexing2 extends
if (VERBOSE) {
System.out.println(Thread.currentThread().getName() + ": del query id:" + idString);
}
- w.deleteDocuments(new TermQuery(idTerm.createTerm(idString)));
+ w.deleteDocuments(new TermQuery(new Term("id", idString)));
docs.remove(idString);
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java Tue Jun 28 19:42:31 2011
@@ -104,7 +104,7 @@ public class TestTermdocPerf extends Luc
int ret=0;
DocsEnum tdocs = null;
for (int i=0; i<iter; i++) {
- tenum.seek(new BytesRef("val"));
+ tenum.seekCeil(new BytesRef("val"));
tdocs = tenum.docs(MultiFields.getDeletedDocs(reader), tdocs);
while (tdocs.nextDoc() != DocsEnum.NO_MORE_DOCS) {
ret += tdocs.docID();
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java Tue Jun 28 19:42:31 2011
@@ -75,8 +75,15 @@ public class TestSurrogates extends Luce
}
private static class SortTermAsUTF16Comparator implements Comparator<Term> {
- public int compare(Term o1, Term o2) {
- return o1.compareToUTF16(o2);
+ private static final Comparator<BytesRef> legacyComparator =
+ BytesRef.getUTF8SortedAsUTF16Comparator();
+
+ public int compare(Term term1, Term term2) {
+ if (term1.field().equals(term2.field())) {
+ return legacyComparator.compare(term1.bytes(), term2.bytes());
+ } else {
+ return term1.field().compareTo(term2.field());
+ }
}
}
@@ -159,7 +166,7 @@ public class TestSurrogates extends Luce
// seek should find the term
assertEquals(TermsEnum.SeekStatus.FOUND,
- te.seek(term.bytes()));
+ te.seekCeil(term.bytes()));
// now .next() this many times:
int ct = _TestUtil.nextInt(r, 5, 100);
@@ -171,7 +178,7 @@ public class TestSurrogates extends Luce
break;
}
term = fieldTerms.get(1+spot+i);
- if (term.field() != field) {
+ if (!term.field().equals(field)) {
assertNull(te.next());
break;
} else {
@@ -224,10 +231,10 @@ public class TestSurrogates extends Luce
spot = -spot - 1;
- if (spot == fieldTerms.size() || fieldTerms.get(spot).field() != field) {
- assertEquals(TermsEnum.SeekStatus.END, te.seek(tx.bytes()));
+ if (spot == fieldTerms.size() || !fieldTerms.get(spot).field().equals(field)) {
+ assertEquals(TermsEnum.SeekStatus.END, te.seekCeil(tx.bytes()));
} else {
- assertEquals(TermsEnum.SeekStatus.NOT_FOUND, te.seek(tx.bytes()));
+ assertEquals(TermsEnum.SeekStatus.NOT_FOUND, te.seekCeil(tx.bytes()));
if (VERBOSE) {
System.out.println(" got term=" + UnicodeUtil.toHexString(te.term().utf8ToString()));
@@ -247,7 +254,7 @@ public class TestSurrogates extends Luce
break;
}
Term term = fieldTerms.get(1+spot+i);
- if (term.field() != field) {
+ if (!term.field().equals(field)) {
assertNull(te.next());
break;
} else {
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java Tue Jun 28 19:42:31 2011
@@ -170,76 +170,241 @@ public class TestDocValues extends Lucen
dir.close();
}
- public void testInts() throws IOException {
- long[] maxMin = new long[] {
- Long.MIN_VALUE, Long.MAX_VALUE,
- 1, Long.MAX_VALUE,
- 0, Long.MAX_VALUE,
- -1, Long.MAX_VALUE,
- Long.MIN_VALUE, -1,
- random.nextInt(), random.nextInt() };
- for (int j = 0; j < maxMin.length; j+=2) {
- long maxV = 1;
- final int NUM_VALUES = 777 + random.nextInt(777);
- final long[] values = new long[NUM_VALUES];
- for (int rx = 1; rx < 63; rx++, maxV *= 2) {
- Directory dir = newDirectory();
- final AtomicLong trackBytes = new AtomicLong(0);
- Writer w = Ints.getWriter(dir, "test", false, trackBytes);
- values[0] = maxMin[j];
- w.add(0, values[0]);
- values[1] = maxMin[j+1];
- w.add(1, values[1]);
- for (int i = 2; i < NUM_VALUES; i++) {
- final long v = random.nextLong() % (1 + maxV);
- values[i] = v;
- w.add(i, v);
- }
- final int additionalDocs = 1 + random.nextInt(9);
- w.finish(NUM_VALUES + additionalDocs);
- assertEquals(0, trackBytes.get());
-
- IndexDocValues r = Ints.getValues(dir, "test", false);
- for (int iter = 0; iter < 2; iter++) {
- Source s = getSource(r);
- for (int i = 0; i < NUM_VALUES; i++) {
- final long v = s.getInt(i);
- assertEquals("index " + i, values[i], v);
- }
+ public void testVariableIntsLimits() throws IOException {
+ long[][] minMax = new long[][] { { Long.MIN_VALUE, Long.MAX_VALUE },
+ { Long.MIN_VALUE + 1, 1 }, { -1, Long.MAX_VALUE },
+ { Long.MIN_VALUE, -1 }, { 1, Long.MAX_VALUE },
+ { -1, Long.MAX_VALUE - 1 }, { Long.MIN_VALUE + 2, 1 }, };
+ ValueType[] expectedTypes = new ValueType[] { ValueType.FIXED_INTS_64,
+ ValueType.FIXED_INTS_64, ValueType.FIXED_INTS_64,
+ ValueType.FIXED_INTS_64, ValueType.VAR_INTS, ValueType.VAR_INTS,
+ ValueType.VAR_INTS, };
+ for (int i = 0; i < minMax.length; i++) {
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.VAR_INTS);
+ w.add(0, minMax[i][0]);
+ w.add(1, minMax[i][1]);
+ w.finish(2);
+ assertEquals(0, trackBytes.get());
+ IndexDocValues r = Ints.getValues(dir, "test", 2);
+ Source source = getSource(r);
+ assertEquals(i + " with min: " + minMax[i][0] + " max: " + minMax[i][1],
+ expectedTypes[i], source.type());
+ assertEquals(minMax[i][0], source.getInt(0));
+ assertEquals(minMax[i][1], source.getInt(1));
+ ValuesEnum iEnum = getEnum(r);
+ assertEquals(i + " with min: " + minMax[i][0] + " max: " + minMax[i][1],
+ expectedTypes[i], iEnum.type());
+ assertEquals(0, iEnum.nextDoc());
+ assertEquals(minMax[i][0], iEnum.intsRef.get());
+ assertEquals(1, iEnum.nextDoc());
+ assertEquals(minMax[i][1], iEnum.intsRef.get());
+ assertEquals(ValuesEnum.NO_MORE_DOCS, iEnum.nextDoc());
+
+ r.close();
+ dir.close();
+ }
+ }
+
+ public void testVInts() throws IOException {
+ testInts(ValueType.VAR_INTS, 63);
+ }
+
+ public void testFixedInts() throws IOException {
+ testInts(ValueType.FIXED_INTS_64, 63);
+ testInts(ValueType.FIXED_INTS_32, 31);
+ testInts(ValueType.FIXED_INTS_16, 15);
+ testInts(ValueType.FIXED_INTS_8, 7);
+
+ }
+
+ public void testGetInt8Array() throws IOException {
+ byte[] sourceArray = new byte[] {1,2,3};
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_8);
+ for (int i = 0; i < sourceArray.length; i++) {
+ w.add(i, (long) sourceArray[i]);
+ }
+ w.finish(sourceArray.length);
+ IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length);
+ Source source = r.getSource();
+ assertTrue(source.hasArray());
+ byte[] loaded = ((byte[])source.getArray());
+ assertEquals(loaded.length, sourceArray.length);
+ for (int i = 0; i < loaded.length; i++) {
+ assertEquals("value didn't match at index " + i, sourceArray[i], loaded[i]);
+ }
+ r.close();
+ dir.close();
+ }
+
+ public void testGetInt16Array() throws IOException {
+ short[] sourceArray = new short[] {1,2,3};
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_16);
+ for (int i = 0; i < sourceArray.length; i++) {
+ w.add(i, (long) sourceArray[i]);
+ }
+ w.finish(sourceArray.length);
+ IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length);
+ Source source = r.getSource();
+ assertTrue(source.hasArray());
+ short[] loaded = ((short[])source.getArray());
+ assertEquals(loaded.length, sourceArray.length);
+ for (int i = 0; i < loaded.length; i++) {
+ assertEquals("value didn't match at index " + i, sourceArray[i], loaded[i]);
+ }
+ r.close();
+ dir.close();
+ }
+
+ public void testGetInt64Array() throws IOException {
+ long[] sourceArray = new long[] {1,2,3};
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_64);
+ for (int i = 0; i < sourceArray.length; i++) {
+ w.add(i, sourceArray[i]);
+ }
+ w.finish(sourceArray.length);
+ IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length);
+ Source source = r.getSource();
+ assertTrue(source.hasArray());
+ long[] loaded = ((long[])source.getArray());
+ assertEquals(loaded.length, sourceArray.length);
+ for (int i = 0; i < loaded.length; i++) {
+ assertEquals("value didn't match at index " + i, sourceArray[i], loaded[i]);
+ }
+ r.close();
+ dir.close();
+ }
+
+ public void testGetInt32Array() throws IOException {
+ int[] sourceArray = new int[] {1,2,3};
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_32);
+ for (int i = 0; i < sourceArray.length; i++) {
+ w.add(i, (long) sourceArray[i]);
+ }
+ w.finish(sourceArray.length);
+ IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length);
+ Source source = r.getSource();
+ assertTrue(source.hasArray());
+ int[] loaded = ((int[])source.getArray());
+ assertEquals(loaded.length, sourceArray.length);
+ for (int i = 0; i < loaded.length; i++) {
+ assertEquals("value didn't match at index " + i, sourceArray[i], loaded[i]);
+ }
+ r.close();
+ dir.close();
+ }
+
+ public void testGetFloat32Array() throws IOException {
+ float[] sourceArray = new float[] {1,2,3};
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Floats.getWriter(dir, "test", 4, trackBytes);
+ for (int i = 0; i < sourceArray.length; i++) {
+ w.add(i, sourceArray[i]);
+ }
+ w.finish(sourceArray.length);
+ IndexDocValues r = Floats.getValues(dir, "test", 3);
+ Source source = r.getSource();
+ assertTrue(source.hasArray());
+ float[] loaded = ((float[])source.getArray());
+ assertEquals(loaded.length, sourceArray.length);
+ for (int i = 0; i < loaded.length; i++) {
+ assertEquals("value didn't match at index " + i, sourceArray[i], loaded[i], 0.0f);
+ }
+ r.close();
+ dir.close();
+ }
+
+ public void testGetFloat64Array() throws IOException {
+ double[] sourceArray = new double[] {1,2,3};
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Floats.getWriter(dir, "test", 8, trackBytes);
+ for (int i = 0; i < sourceArray.length; i++) {
+ w.add(i, sourceArray[i]);
+ }
+ w.finish(sourceArray.length);
+ IndexDocValues r = Floats.getValues(dir, "test", 3);
+ Source source = r.getSource();
+ assertTrue(source.hasArray());
+ double[] loaded = ((double[])source.getArray());
+ assertEquals(loaded.length, sourceArray.length);
+ for (int i = 0; i < loaded.length; i++) {
+ assertEquals("value didn't match at index " + i, sourceArray[i], loaded[i], 0.0d);
+ }
+ r.close();
+ dir.close();
+ }
+
+ private void testInts(ValueType type, int maxBit) throws IOException {
+ long maxV = 1;
+ final int NUM_VALUES = 333 + random.nextInt(333);
+ final long[] values = new long[NUM_VALUES];
+ for (int rx = 1; rx < maxBit; rx++, maxV *= 2) {
+ Directory dir = newDirectory();
+ final AtomicLong trackBytes = new AtomicLong(0);
+ Writer w = Ints.getWriter(dir, "test", trackBytes, type);
+ for (int i = 0; i < NUM_VALUES; i++) {
+ final long v = random.nextLong() % (1 + maxV);
+ values[i] = v;
+ w.add(i, v);
+ }
+ final int additionalDocs = 1 + random.nextInt(9);
+ w.finish(NUM_VALUES + additionalDocs);
+ assertEquals(0, trackBytes.get());
+
+ IndexDocValues r = Ints.getValues(dir, "test", NUM_VALUES + additionalDocs);
+ for (int iter = 0; iter < 2; iter++) {
+ Source s = getSource(r);
+ assertEquals(type, s.type());
+ for (int i = 0; i < NUM_VALUES; i++) {
+ final long v = s.getInt(i);
+ assertEquals("index " + i, values[i], v);
}
+ }
- for (int iter = 0; iter < 2; iter++) {
- ValuesEnum iEnum = getEnum(r);
- LongsRef ints = iEnum.getInt();
- for (int i = 0; i < NUM_VALUES + additionalDocs; i++) {
- assertEquals(i, iEnum.nextDoc());
- if (i < NUM_VALUES) {
- assertEquals(values[i], ints.get());
- } else {
- assertEquals(0, ints.get());
- }
+ for (int iter = 0; iter < 2; iter++) {
+ ValuesEnum iEnum = getEnum(r);
+ assertEquals(type, iEnum.type());
+ LongsRef ints = iEnum.getInt();
+ for (int i = 0; i < NUM_VALUES + additionalDocs; i++) {
+ assertEquals(i, iEnum.nextDoc());
+ if (i < NUM_VALUES) {
+ assertEquals(values[i], ints.get());
+ } else {
+ assertEquals(0, ints.get());
}
- assertEquals(ValuesEnum.NO_MORE_DOCS, iEnum.nextDoc());
- iEnum.close();
}
+ assertEquals(ValuesEnum.NO_MORE_DOCS, iEnum.nextDoc());
+ iEnum.close();
+ }
- for (int iter = 0; iter < 2; iter++) {
- ValuesEnum iEnum = getEnum(r);
- LongsRef ints = iEnum.getInt();
- for (int i = 0; i < NUM_VALUES + additionalDocs; i += 1 + random.nextInt(25)) {
- assertEquals(i, iEnum.advance(i));
- if (i < NUM_VALUES) {
- assertEquals(values[i], ints.get());
- } else {
- assertEquals(0, ints.get());
- }
+ for (int iter = 0; iter < 2; iter++) {
+ ValuesEnum iEnum = getEnum(r);
+ assertEquals(type, iEnum.type());
+ LongsRef ints = iEnum.getInt();
+ for (int i = 0; i < NUM_VALUES + additionalDocs; i += 1 + random.nextInt(25)) {
+ assertEquals(i, iEnum.advance(i));
+ if (i < NUM_VALUES) {
+ assertEquals(values[i], ints.get());
+ } else {
+ assertEquals(0, ints.get());
}
- assertEquals(ValuesEnum.NO_MORE_DOCS, iEnum.advance(NUM_VALUES + additionalDocs));
- iEnum.close();
}
- r.close();
- dir.close();
+ assertEquals(ValuesEnum.NO_MORE_DOCS, iEnum.advance(NUM_VALUES + additionalDocs));
+ iEnum.close();
}
+ r.close();
+ dir.close();
}
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java Tue Jun 28 19:42:31 2011
@@ -113,44 +113,20 @@ public class TestDocValuesIndexing exten
dir.close();
}
- /**
- * Tests complete indexing of {@link ValueType} including deletions, merging and
- * sparse value fields on Compound-File
- */
- public void testIndexBytesNoDeletesCFS() throws IOException {
- runTestIndexBytes(writerConfig(true), false);
- }
-
- public void testIndexBytesDeletesCFS() throws IOException {
- runTestIndexBytes(writerConfig(true), true);
- }
-
- public void testIndexNumericsNoDeletesCFS() throws IOException {
- runTestNumerics(writerConfig(true), false);
- }
-
- public void testIndexNumericsDeletesCFS() throws IOException {
- runTestNumerics(writerConfig(true), true);
- }
-
- /**
- * Tests complete indexing of {@link ValueType} including deletions, merging and
- * sparse value fields on None-Compound-File
- */
public void testIndexBytesNoDeletes() throws IOException {
- runTestIndexBytes(writerConfig(false), false);
+ runTestIndexBytes(writerConfig(random.nextBoolean()), false);
}
public void testIndexBytesDeletes() throws IOException {
- runTestIndexBytes(writerConfig(false), true);
+ runTestIndexBytes(writerConfig(random.nextBoolean()), true);
}
public void testIndexNumericsNoDeletes() throws IOException {
- runTestNumerics(writerConfig(false), false);
+ runTestNumerics(writerConfig(random.nextBoolean()), false);
}
public void testIndexNumericsDeletes() throws IOException {
- runTestNumerics(writerConfig(false), true);
+ runTestNumerics(writerConfig(random.nextBoolean()), true);
}
public void testAddIndexes() throws IOException {
@@ -204,7 +180,11 @@ public class TestDocValuesIndexing exten
case BYTES_VAR_STRAIGHT:
case FLOAT_32:
case FLOAT_64:
- case INTS:
+ case VAR_INTS:
+ case FIXED_INTS_16:
+ case FIXED_INTS_32:
+ case FIXED_INTS_64:
+ case FIXED_INTS_8:
assertEquals(msg, valuesPerIndex-1, vE_2_merged.advance(valuesPerIndex-1));
}
@@ -246,7 +226,7 @@ public class TestDocValuesIndexing exten
throws IOException {
Directory d = newDirectory();
IndexWriter w = new IndexWriter(d, cfg);
- final int numValues = 179 + random.nextInt(151);
+ final int numValues = 50 + atLeast(10);
final List<ValueType> numVariantList = new ArrayList<ValueType>(NUMERICS);
// run in random order to test if fill works correctly during merges
@@ -258,8 +238,16 @@ public class TestDocValuesIndexing exten
IndexReader r = IndexReader.open(w, true);
final int numRemainingValues = (int) (numValues - deleted.cardinality());
final int base = r.numDocs() - numRemainingValues;
+ // for FIXED_INTS_8 we use value mod 128 - to enable testing in
+ // one go we simply use numValues as the mod for all other INT types
+ int mod = numValues;
switch (val) {
- case INTS: {
+ case FIXED_INTS_8:
+ mod = 128;
+ case FIXED_INTS_16:
+ case FIXED_INTS_32:
+ case FIXED_INTS_64:
+ case VAR_INTS: {
IndexDocValues intsReader = getDocValues(r, val.name());
assertNotNull(intsReader);
@@ -283,8 +271,8 @@ public class TestDocValuesIndexing exten
}
assertEquals("advance failed at index: " + i + " of " + r.numDocs()
+ " docs", i, intsEnum.advance(i));
- assertEquals(expected, ints.getInt(i));
- assertEquals(expected, enumRef.get());
+ assertEquals(val + " mod: " + mod + " index: " + i, expected%mod, ints.getInt(i));
+ assertEquals(expected%mod, enumRef.get());
}
}
@@ -338,11 +326,11 @@ public class TestDocValuesIndexing exten
final List<ValueType> byteVariantList = new ArrayList<ValueType>(BYTES);
// run in random order to test if fill works correctly during merges
Collections.shuffle(byteVariantList, random);
- final int numValues = 179 + random.nextInt(151);
+ final int numValues = 50 + atLeast(10);
for (ValueType byteIndexValue : byteVariantList) {
List<Closeable> closeables = new ArrayList<Closeable>();
- int bytesSize = 1 + random.nextInt(128);
+ int bytesSize = 1 + atLeast(10);
OpenBitSet deleted = indexValues(w, numValues, byteIndexValue,
byteVariantList, withDeletions, bytesSize);
final IndexReader r = IndexReader.open(w, withDeletions);
@@ -485,8 +473,12 @@ public class TestDocValuesIndexing exten
ValueType.BYTES_FIXED_SORTED, ValueType.BYTES_FIXED_STRAIGHT, ValueType.BYTES_VAR_DEREF,
ValueType.BYTES_VAR_SORTED, ValueType.BYTES_VAR_STRAIGHT);
- private static EnumSet<ValueType> NUMERICS = EnumSet.of(ValueType.INTS,
- ValueType.FLOAT_32, ValueType.FLOAT_64);
+ private static EnumSet<ValueType> NUMERICS = EnumSet.of(ValueType.VAR_INTS,
+ ValueType.FIXED_INTS_16, ValueType.FIXED_INTS_32,
+ ValueType.FIXED_INTS_64,
+ ValueType.FIXED_INTS_8,
+ ValueType.FLOAT_32,
+ ValueType.FLOAT_64);
private static Index[] IDX_VALUES = new Index[] { Index.ANALYZED,
Index.ANALYZED_NO_NORMS, Index.NOT_ANALYZED, Index.NOT_ANALYZED_NO_NORMS,
@@ -517,8 +509,20 @@ public class TestDocValuesIndexing exten
for (int i = 0; i < numValues; i++) {
if (isNumeric) {
switch (value) {
- case INTS:
- valField.setInt(i);
+ case VAR_INTS:
+ valField.setInt((long)i);
+ break;
+ case FIXED_INTS_16:
+ valField.setInt((short)i, random.nextInt(10) != 0);
+ break;
+ case FIXED_INTS_32:
+ valField.setInt(i, random.nextInt(10) != 0);
+ break;
+ case FIXED_INTS_64:
+ valField.setInt((long)i, random.nextInt(10) != 0);
+ break;
+ case FIXED_INTS_8:
+ valField.setInt((byte)(0xFF & (i % 128)), random.nextInt(10) != 0);
break;
case FLOAT_32:
valField.setFloat(2.0f * i);
@@ -526,6 +530,7 @@ public class TestDocValuesIndexing exten
case FLOAT_64:
valField.setFloat(2.0d * i);
break;
+
default:
fail("unexpected value " + value);
}
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java Tue Jun 28 19:42:31 2011
@@ -86,7 +86,7 @@ public class TestCustomSearcherSort exte
// log("Run testFieldSortCustomSearcher");
// define the sort criteria
Sort custSort = new Sort(
- new SortField("publicationDate_", SortField.STRING),
+ new SortField("publicationDate_", SortField.Type.STRING),
SortField.FIELD_SCORE);
IndexSearcher searcher = new CustomSearcher(reader, 2);
// search and check hits
@@ -100,7 +100,7 @@ public class TestCustomSearcherSort exte
// log("Run testFieldSortSingleSearcher");
// define the sort criteria
Sort custSort = new Sort(
- new SortField("publicationDate_", SortField.STRING),
+ new SortField("publicationDate_", SortField.Type.STRING),
SortField.FIELD_SCORE);
IndexSearcher searcher = new CustomSearcher(reader, 2);
// search and check hits
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestDateSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestDateSort.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestDateSort.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestDateSort.java Tue Jun 28 19:42:31 2011
@@ -79,7 +79,7 @@ public class TestDateSort extends Lucene
public void testReverseDateSort() throws Exception {
IndexSearcher searcher = newSearcher(reader);
- Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.STRING, true));
+ Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.Type.STRING, true));
QueryParser queryParser = new QueryParser(TEST_VERSION_CURRENT, TEXT_FIELD, new MockAnalyzer(random));
Query query = queryParser.parse("Document");
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java Tue Jun 28 19:42:31 2011
@@ -73,7 +73,7 @@ public class TestElevationComparator ext
Sort sort = new Sort(
new SortField("id", new ElevationComparatorSource(priority), false),
- new SortField(null, SortField.SCORE, reversed)
+ new SortField(null, SortField.Type.SCORE, reversed)
);
TopDocsCollector<Entry> topCollector = TopFieldCollector.create(sort, 50, false, true, true, true);
Modified: lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestFieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestFieldCache.java?rev=1140809&r1=1140808&r2=1140809&view=diff
==============================================================================
--- lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestFieldCache.java (original)
+++ lucene/dev/branches/solr2452/lucene/src/test/org/apache/lucene/search/TestFieldCache.java Tue Jun 28 19:42:31 2011
@@ -189,7 +189,7 @@ public class TestFieldCache extends Luce
for (int i = 0; i < num; i++) {
int k = _TestUtil.nextInt(random, 1, nTerms-1);
BytesRef val1 = termsIndex.lookup(k, val);
- assertEquals(TermsEnum.SeekStatus.FOUND, tenum.seek(val1));
+ assertEquals(TermsEnum.SeekStatus.FOUND, tenum.seekCeil(val1));
assertEquals(val1, tenum.term());
}