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
|
/* Unzips dirName + ".zip" --> dirName, removing dirName
|
||||||
first */
|
first */
|
||||||
public void unzip(String dirName) throws IOException {
|
public void unzip(String zipName, String destDirName) throws IOException {
|
||||||
rmDir(dirName);
|
|
||||||
|
|
||||||
Enumeration entries;
|
Enumeration entries;
|
||||||
ZipFile zipFile;
|
ZipFile zipFile;
|
||||||
zipFile = new ZipFile(dirName + ".zip");
|
zipFile = new ZipFile(zipName + ".zip");
|
||||||
|
|
||||||
entries = zipFile.entries();
|
entries = zipFile.entries();
|
||||||
|
|
||||||
|
String dirName = fullDir(destDirName);
|
||||||
|
|
||||||
File fileDir = new File(dirName);
|
File fileDir = new File(dirName);
|
||||||
|
rmDir(dirName);
|
||||||
|
|
||||||
fileDir.mkdir();
|
fileDir.mkdir();
|
||||||
|
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
|
@ -89,9 +93,9 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
||||||
for(int i=0;i<oldNames.length;i++) {
|
for(int i=0;i<oldNames.length;i++) {
|
||||||
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
||||||
unzip(dirName);
|
unzip(dirName, oldNames[i]);
|
||||||
searchIndex(dirName);
|
searchIndex(oldNames[i]);
|
||||||
rmDir(dirName);
|
rmDir(oldNames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +103,9 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
||||||
for(int i=0;i<oldNames.length;i++) {
|
for(int i=0;i<oldNames.length;i++) {
|
||||||
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
||||||
unzip(dirName);
|
unzip(dirName, oldNames[i]);
|
||||||
changeIndexNoAdds(dirName);
|
changeIndexNoAdds(oldNames[i]);
|
||||||
rmDir(dirName);
|
rmDir(oldNames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +113,9 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
String[] oldNames = {"prelockless.cfs", "prelockless.nocfs"};
|
||||||
for(int i=0;i<oldNames.length;i++) {
|
for(int i=0;i<oldNames.length;i++) {
|
||||||
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
|
||||||
unzip(dirName);
|
unzip(dirName, oldNames[i]);
|
||||||
changeIndexWithAdds(dirName);
|
changeIndexWithAdds(oldNames[i]);
|
||||||
rmDir(dirName);
|
rmDir(oldNames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +123,8 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
//QueryParser parser = new QueryParser("contents", new WhitespaceAnalyzer());
|
//QueryParser parser = new QueryParser("contents", new WhitespaceAnalyzer());
|
||||||
//Query query = parser.parse("handle:1");
|
//Query query = parser.parse("handle:1");
|
||||||
|
|
||||||
|
dirName = fullDir(dirName);
|
||||||
|
|
||||||
Directory dir = FSDirectory.getDirectory(dirName);
|
Directory dir = FSDirectory.getDirectory(dirName);
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
|
|
||||||
|
@ -137,6 +143,8 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
* setNorm, and search */
|
* setNorm, and search */
|
||||||
public void changeIndexWithAdds(String dirName) throws IOException {
|
public void changeIndexWithAdds(String dirName) throws IOException {
|
||||||
|
|
||||||
|
dirName = fullDir(dirName);
|
||||||
|
|
||||||
Directory dir = FSDirectory.getDirectory(dirName);
|
Directory dir = FSDirectory.getDirectory(dirName);
|
||||||
// open writer
|
// open writer
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
||||||
|
@ -194,6 +202,8 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
* setNorm, and search */
|
* setNorm, and search */
|
||||||
public void changeIndexNoAdds(String dirName) throws IOException {
|
public void changeIndexNoAdds(String dirName) throws IOException {
|
||||||
|
|
||||||
|
dirName = fullDir(dirName);
|
||||||
|
|
||||||
Directory dir = FSDirectory.getDirectory(dirName);
|
Directory dir = FSDirectory.getDirectory(dirName);
|
||||||
|
|
||||||
// make sure searching sees right # hits
|
// make sure searching sees right # hits
|
||||||
|
@ -238,6 +248,8 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
|
|
||||||
public void createIndex(String dirName, boolean doCFS) throws IOException {
|
public void createIndex(String dirName, boolean doCFS) throws IOException {
|
||||||
|
|
||||||
|
dirName = fullDir(dirName);
|
||||||
|
|
||||||
Directory dir = FSDirectory.getDirectory(dirName);
|
Directory dir = FSDirectory.getDirectory(dirName);
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||||
writer.setUseCompoundFile(doCFS);
|
writer.setUseCompoundFile(doCFS);
|
||||||
|
@ -265,7 +277,7 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
public void testExactFileNames() throws IOException {
|
public void testExactFileNames() throws IOException {
|
||||||
|
|
||||||
String outputDir = "lucene.backwardscompat0.index";
|
String outputDir = "lucene.backwardscompat0.index";
|
||||||
Directory dir = FSDirectory.getDirectory(outputDir);
|
Directory dir = FSDirectory.getDirectory(fullDir(outputDir));
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||||
for(int i=0;i<35;i++) {
|
for(int i=0;i<35;i++) {
|
||||||
addDoc(writer, i);
|
addDoc(writer, i);
|
||||||
|
@ -342,8 +354,8 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rmDir(String dir) {
|
private void rmDir(String dir) throws IOException {
|
||||||
File fileDir = new File(dir);
|
File fileDir = new File(fullDir(dir));
|
||||||
if (fileDir.exists()) {
|
if (fileDir.exists()) {
|
||||||
File[] files = fileDir.listFiles();
|
File[] files = fileDir.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
|
@ -354,4 +366,8 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
fileDir.delete();
|
fileDir.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String fullDir(String dirName) throws IOException {
|
||||||
|
return new File(System.getProperty("tempDir"), dirName).getCanonicalPath();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue