mirror of https://github.com/apache/lucene.git
LUCENE-2858: Step-by-step: port tests to new static API of DirectoryReader
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237306 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
adbadb03aa
commit
b26194d5fc
|
@ -346,7 +346,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
|||
assertEquals(1 + (needsMerging ? 1:0), policy.numOnCommit);
|
||||
|
||||
// Test listCommits
|
||||
Collection<IndexCommit> commits = IndexReader.listCommits(dir);
|
||||
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
|
||||
// 2 from closing writer
|
||||
assertEquals(1 + (needsMerging ? 1:0), commits.size());
|
||||
|
||||
|
@ -410,7 +410,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
|||
}
|
||||
writer.close();
|
||||
|
||||
Collection<IndexCommit> commits = IndexReader.listCommits(dir);
|
||||
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
|
||||
assertEquals(5, commits.size());
|
||||
IndexCommit lastCommit = null;
|
||||
for (final IndexCommit commit : commits) {
|
||||
|
@ -426,7 +426,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
|||
writer.forceMerge(1);
|
||||
writer.close();
|
||||
|
||||
assertEquals(6, IndexReader.listCommits(dir).size());
|
||||
assertEquals(6, DirectoryReader.listCommits(dir).size());
|
||||
|
||||
// Now open writer on the commit just before merge:
|
||||
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
|
||||
|
@ -449,7 +449,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
|
|||
writer.close();
|
||||
|
||||
// Now 8 because we made another commit
|
||||
assertEquals(7, IndexReader.listCommits(dir).size());
|
||||
assertEquals(7, DirectoryReader.listCommits(dir).size());
|
||||
|
||||
r = IndexReader.open(dir);
|
||||
// Not fully merged because we rolled it back, and now only
|
||||
|
|
|
@ -384,17 +384,17 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
public void testLastModified() throws Exception {
|
||||
for(int i=0;i<2;i++) {
|
||||
final Directory dir = newDirectory();
|
||||
assertFalse(IndexReader.indexExists(dir));
|
||||
assertFalse(DirectoryReader.indexExists(dir));
|
||||
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
|
||||
addDocumentWithFields(writer);
|
||||
assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
|
||||
writer.close();
|
||||
assertTrue(IndexReader.indexExists(dir));
|
||||
assertTrue(DirectoryReader.indexExists(dir));
|
||||
IndexReader reader = IndexReader.open(dir);
|
||||
assertFalse(IndexWriter.isLocked(dir)); // reader only, no lock
|
||||
long version = IndexReader.lastModified(dir);
|
||||
long version = DirectoryReader.lastModified(dir);
|
||||
if (i == 1) {
|
||||
long version2 = IndexReader.lastModified(dir);
|
||||
long version2 = DirectoryReader.lastModified(dir);
|
||||
assertEquals(version, version2);
|
||||
}
|
||||
reader.close();
|
||||
|
@ -406,7 +406,7 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
addDocumentWithFields(writer);
|
||||
writer.close();
|
||||
reader = IndexReader.open(dir);
|
||||
assertTrue("old lastModified is " + version + "; new lastModified is " + IndexReader.lastModified(dir), version <= IndexReader.lastModified(dir));
|
||||
assertTrue("old lastModified is " + version + "; new lastModified is " + DirectoryReader.lastModified(dir), version <= IndexReader.lastModified(dir));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -414,15 +414,15 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
|
||||
public void testVersion() throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
assertFalse(IndexReader.indexExists(dir));
|
||||
assertFalse(DirectoryReader.indexExists(dir));
|
||||
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||
addDocumentWithFields(writer);
|
||||
assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
|
||||
writer.close();
|
||||
assertTrue(IndexReader.indexExists(dir));
|
||||
assertTrue(DirectoryReader.indexExists(dir));
|
||||
IndexReader reader = IndexReader.open(dir);
|
||||
assertFalse(IndexWriter.isLocked(dir)); // reader only, no lock
|
||||
long version = IndexReader.getCurrentVersion(dir);
|
||||
long version = DirectoryReader.getCurrentVersion(dir);
|
||||
reader.close();
|
||||
// modify index and check version has been
|
||||
// incremented:
|
||||
|
@ -430,7 +430,7 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
addDocumentWithFields(writer);
|
||||
writer.close();
|
||||
reader = IndexReader.open(dir);
|
||||
assertTrue("old version is " + version + "; new version is " + IndexReader.getCurrentVersion(dir), version < IndexReader.getCurrentVersion(dir));
|
||||
assertTrue("old version is " + version + "; new version is " + DirectoryReader.getCurrentVersion(dir), version < IndexReader.getCurrentVersion(dir));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -713,7 +713,7 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
writer.addDocument(createDocument("a"));
|
||||
writer.close();
|
||||
|
||||
Collection<IndexCommit> commits = IndexReader.listCommits(dir);
|
||||
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
|
||||
for (final IndexCommit commit : commits) {
|
||||
Collection<String> files = commit.getFileNames();
|
||||
HashSet<String> seen = new HashSet<String>();
|
||||
|
@ -882,7 +882,7 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
sdp.snapshot("c3");
|
||||
writer.close();
|
||||
long currentGen = 0;
|
||||
for (IndexCommit ic : IndexReader.listCommits(dir)) {
|
||||
for (IndexCommit ic : DirectoryReader.listCommits(dir)) {
|
||||
assertTrue("currentGen=" + currentGen + " commitGen=" + ic.getGeneration(), currentGen < ic.getGeneration());
|
||||
currentGen = ic.getGeneration();
|
||||
}
|
||||
|
@ -895,9 +895,9 @@ public class TestIndexReader extends LuceneTestCase {
|
|||
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||
writer.addDocument(new Document());
|
||||
writer.prepareCommit();
|
||||
assertFalse(IndexReader.indexExists(dir));
|
||||
assertFalse(DirectoryReader.indexExists(dir));
|
||||
writer.close();
|
||||
assertTrue(IndexReader.indexExists(dir));
|
||||
assertTrue(DirectoryReader.indexExists(dir));
|
||||
dir.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -845,7 +845,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
|
|||
IndexReader r = IndexReader.open(dir);
|
||||
assertEquals(0, r.numDocs());
|
||||
|
||||
Collection<IndexCommit> commits = IndexReader.listCommits(dir);
|
||||
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
|
||||
for (final IndexCommit commit : commits) {
|
||||
IndexReader r2 = IndexReader.openIfChanged(r, commit);
|
||||
assertNotNull(r2);
|
||||
|
|
|
@ -1407,7 +1407,7 @@ public class TestIndexWriter extends LuceneTestCase {
|
|||
doc.add(newField("c", "val", customType));
|
||||
writer.addDocument(doc);
|
||||
writer.commit();
|
||||
assertEquals(1, IndexReader.listCommits(dir).size());
|
||||
assertEquals(1, DirectoryReader.listCommits(dir).size());
|
||||
|
||||
// Keep that commit
|
||||
sdp.snapshot("id");
|
||||
|
@ -1417,12 +1417,12 @@ public class TestIndexWriter extends LuceneTestCase {
|
|||
doc.add(newField("c", "val", customType));
|
||||
writer.addDocument(doc);
|
||||
writer.commit();
|
||||
assertEquals(2, IndexReader.listCommits(dir).size());
|
||||
assertEquals(2, DirectoryReader.listCommits(dir).size());
|
||||
|
||||
// Should delete the unreferenced commit
|
||||
sdp.release("id");
|
||||
writer.deleteUnusedFiles();
|
||||
assertEquals(1, IndexReader.listCommits(dir).size());
|
||||
assertEquals(1, DirectoryReader.listCommits(dir).size());
|
||||
|
||||
writer.close();
|
||||
dir.close();
|
||||
|
|
|
@ -435,7 +435,7 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
|||
|
||||
// open "first" with IndexWriter
|
||||
IndexCommit commit = null;
|
||||
for(IndexCommit c : IndexReader.listCommits(dir)) {
|
||||
for(IndexCommit c : DirectoryReader.listCommits(dir)) {
|
||||
if (c.getUserData().get("tag").equals("first")) {
|
||||
commit = c;
|
||||
break;
|
||||
|
@ -456,7 +456,7 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
|||
|
||||
// make sure "second" commit is still there
|
||||
commit = null;
|
||||
for(IndexCommit c : IndexReader.listCommits(dir)) {
|
||||
for(IndexCommit c : DirectoryReader.listCommits(dir)) {
|
||||
if (c.getUserData().get("tag").equals("second")) {
|
||||
commit = c;
|
||||
break;
|
||||
|
@ -475,14 +475,14 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
|||
Directory dir = newDirectory();
|
||||
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||
try {
|
||||
IndexReader.listCommits(dir);
|
||||
DirectoryReader.listCommits(dir);
|
||||
fail("listCommits should have thrown an exception over empty index");
|
||||
} catch (IndexNotFoundException e) {
|
||||
// that's expected !
|
||||
}
|
||||
// No changes still should generate a commit, because it's a new index.
|
||||
writer.close();
|
||||
assertEquals("expected 1 commits!", 1, IndexReader.listCommits(dir).size());
|
||||
assertEquals("expected 1 commits!", 1, DirectoryReader.listCommits(dir).size());
|
||||
dir.close();
|
||||
}
|
||||
|
||||
|
@ -620,7 +620,7 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
|||
TestIndexWriter.addDoc(w);
|
||||
w.close();
|
||||
|
||||
assertEquals(0, IndexReader.getCommitUserData(dir).size());
|
||||
assertEquals(0, DirectoryReader.getCommitUserData(dir).size());
|
||||
|
||||
IndexReader r = IndexReader.open(dir);
|
||||
// commit(Map) never called for this index
|
||||
|
@ -635,7 +635,7 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
|||
w.commit(data);
|
||||
w.close();
|
||||
|
||||
assertEquals("test1", IndexReader.getCommitUserData(dir).get("label"));
|
||||
assertEquals("test1", DirectoryReader.getCommitUserData(dir).get("label"));
|
||||
|
||||
r = IndexReader.open(dir);
|
||||
assertEquals("test1", r.getCommitUserData().get("label"));
|
||||
|
@ -645,7 +645,7 @@ public class TestIndexWriterCommit extends LuceneTestCase {
|
|||
w.forceMerge(1);
|
||||
w.close();
|
||||
|
||||
assertEquals("test1", IndexReader.getCommitUserData(dir).get("label"));
|
||||
assertEquals("test1", DirectoryReader.getCommitUserData(dir).get("label"));
|
||||
|
||||
dir.close();
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads {
|
|||
if (file.isDirectory()) {
|
||||
MockDirectoryWrapper dir = newFSDirectory(file);
|
||||
dir.setCheckIndexOnClose(false); // don't double-checkindex
|
||||
if (IndexReader.indexExists(dir)) {
|
||||
if (DirectoryReader.indexExists(dir)) {
|
||||
if (VERBOSE) {
|
||||
System.err.println("Checking index: " + file);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class TestNoDeletionPolicy extends LuceneTestCase {
|
|||
doc.add(newField("c", "a" + i, TextField.TYPE_STORED));
|
||||
writer.addDocument(doc);
|
||||
writer.commit();
|
||||
assertEquals("wrong number of commits !", i + 1, IndexReader.listCommits(dir).size());
|
||||
assertEquals("wrong number of commits !", i + 1, DirectoryReader.listCommits(dir).size());
|
||||
}
|
||||
writer.close();
|
||||
dir.close();
|
||||
|
|
|
@ -252,7 +252,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase {
|
|||
writer = new IndexWriter(dir, getConfig(random, sdp));
|
||||
writer.deleteUnusedFiles();
|
||||
writer.close();
|
||||
assertEquals("no snapshots should exist", 1, IndexReader.listCommits(dir).size());
|
||||
assertEquals("no snapshots should exist", 1, DirectoryReader.listCommits(dir).size());
|
||||
|
||||
for (int i = 0; i < numSnapshots; i++) {
|
||||
try {
|
||||
|
@ -304,7 +304,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase {
|
|||
sdp.release(t.getName());
|
||||
writer.deleteUnusedFiles();
|
||||
}
|
||||
assertEquals(1, IndexReader.listCommits(dir).size());
|
||||
assertEquals(1, DirectoryReader.listCommits(dir).size());
|
||||
writer.close();
|
||||
dir.close();
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TestTransactionRollback extends LuceneTestCase {
|
|||
// System.out.println("Attempting to rollback to "+id);
|
||||
String ids="-"+id;
|
||||
IndexCommit last=null;
|
||||
Collection<IndexCommit> commits = IndexReader.listCommits(dir);
|
||||
Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
|
||||
for (Iterator<IndexCommit> iterator = commits.iterator(); iterator.hasNext();) {
|
||||
IndexCommit commit = iterator.next();
|
||||
Map<String,String> ud=commit.getUserData();
|
||||
|
@ -107,7 +107,7 @@ public class TestTransactionRollback extends LuceneTestCase {
|
|||
|
||||
/*
|
||||
private void showAvailableCommitPoints() throws Exception {
|
||||
Collection commits = IndexReader.listCommits(dir);
|
||||
Collection commits = DirectoryReader.listCommits(dir);
|
||||
for (Iterator iterator = commits.iterator(); iterator.hasNext();) {
|
||||
IndexCommit comm = (IndexCommit) iterator.next();
|
||||
System.out.print("\t Available commit point:["+comm.getUserData()+"] files=");
|
||||
|
|
Loading…
Reference in New Issue