mirror of https://github.com/apache/lucene.git
Fixing backwards compatibility unit test to make its test dirs under tempDir
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@515249 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
83efa50f5e
commit
2380a957ef
|
@ -43,15 +43,19 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
|
||||
/* Unzips dirName + ".zip" --> dirName, removing dirName
|
||||
first */
|
||||
public void unzip(String dirName) throws IOException {
|
||||
rmDir(dirName);
|
||||
public void unzip(String zipName, String destDirName) throws IOException {
|
||||
|
||||
Enumeration entries;
|
||||
ZipFile zipFile;
|
||||
zipFile = new ZipFile(dirName + ".zip");
|
||||
zipFile = new ZipFile(zipName + ".zip");
|
||||
|
||||
entries = zipFile.entries();
|
||||
|
||||
String dirName = fullDir(destDirName);
|
||||
|
||||
File fileDir = new File(dirName);
|
||||
rmDir(dirName);
|
||||
|
||||
fileDir.mkdir();
|
||||
|
||||
while (entries.hasMoreElements()) {
|
||||
|
@ -89,9 +93,9 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
||||
for(int i=0;i<oldNames.length;i++) {
|
||||
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
||||
unzip(dirName);
|
||||
searchIndex(dirName);
|
||||
rmDir(dirName);
|
||||
unzip(dirName, oldNames[i]);
|
||||
searchIndex(oldNames[i]);
|
||||
rmDir(oldNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,9 +103,9 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
||||
for(int i=0;i<oldNames.length;i++) {
|
||||
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
||||
unzip(dirName);
|
||||
changeIndexNoAdds(dirName);
|
||||
rmDir(dirName);
|
||||
unzip(dirName, oldNames[i]);
|
||||
changeIndexNoAdds(oldNames[i]);
|
||||
rmDir(oldNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,9 +113,9 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
||||
for(int i=0;i<oldNames.length;i++) {
|
||||
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
||||
unzip(dirName);
|
||||
changeIndexWithAdds(dirName);
|
||||
rmDir(dirName);
|
||||
unzip(dirName, oldNames[i]);
|
||||
changeIndexWithAdds(oldNames[i]);
|
||||
rmDir(oldNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,6 +123,8 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
//QueryParser parser = new QueryParser("contents", new WhitespaceAnalyzer());
|
||||
//Query query = parser.parse("handle:1");
|
||||
|
||||
dirName = fullDir(dirName);
|
||||
|
||||
Directory dir = FSDirectory.getDirectory(dirName);
|
||||
IndexSearcher searcher = new IndexSearcher(dir);
|
||||
|
||||
|
@ -137,6 +143,8 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
* setNorm, and search */
|
||||
public void changeIndexWithAdds(String dirName) throws IOException {
|
||||
|
||||
dirName = fullDir(dirName);
|
||||
|
||||
Directory dir = FSDirectory.getDirectory(dirName);
|
||||
// open writer
|
||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
||||
|
@ -194,6 +202,8 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
* setNorm, and search */
|
||||
public void changeIndexNoAdds(String dirName) throws IOException {
|
||||
|
||||
dirName = fullDir(dirName);
|
||||
|
||||
Directory dir = FSDirectory.getDirectory(dirName);
|
||||
|
||||
// make sure searching sees right # hits
|
||||
|
@ -238,6 +248,8 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
|
||||
public void createIndex(String dirName, boolean doCFS) throws IOException {
|
||||
|
||||
dirName = fullDir(dirName);
|
||||
|
||||
Directory dir = FSDirectory.getDirectory(dirName);
|
||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
writer.setUseCompoundFile(doCFS);
|
||||
|
@ -265,7 +277,7 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
public void testExactFileNames() throws IOException {
|
||||
|
||||
String outputDir = "lucene.backwardscompat0.index";
|
||||
Directory dir = FSDirectory.getDirectory(outputDir);
|
||||
Directory dir = FSDirectory.getDirectory(fullDir(outputDir));
|
||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
for(int i=0;i<35;i++) {
|
||||
addDoc(writer, i);
|
||||
|
@ -342,8 +354,8 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
writer.addDocument(doc);
|
||||
}
|
||||
|
||||
private void rmDir(String dir) {
|
||||
File fileDir = new File(dir);
|
||||
private void rmDir(String dir) throws IOException {
|
||||
File fileDir = new File(fullDir(dir));
|
||||
if (fileDir.exists()) {
|
||||
File[] files = fileDir.listFiles();
|
||||
if (files != null) {
|
||||
|
@ -354,4 +366,8 @@ public class TestBackwardsCompatibility extends TestCase
|
|||
fileDir.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static String fullDir(String dirName) throws IOException {
|
||||
return new File(System.getProperty("tempDir"), dirName).getCanonicalPath();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue