mirror of https://github.com/apache/lucene.git
LUCENE-720: fix two new unit tests (with lockless) to dynamically compute field number since this number can vary depending on JRE
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@478239 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b797db9788
commit
19f90a38ee
|
@ -274,7 +274,7 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
/* Verifies that the expected file names were produced */
|
/* Verifies that the expected file names were produced */
|
||||||
|
|
||||||
// disable until hardcoded file names are fixes:
|
// disable until hardcoded file names are fixes:
|
||||||
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, true);
|
Directory dir = FSDirectory.getDirectory(outputDir, true);
|
||||||
|
@ -295,12 +295,30 @@ public class TestBackwardsCompatibility extends TestCase
|
||||||
reader.setNorm(21, "content", (float) 1.5);
|
reader.setNorm(21, "content", (float) 1.5);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
|
// The numbering of fields can vary depending on which
|
||||||
|
// JRE is in use. On some JREs we see content bound to
|
||||||
|
// field 0; on others, field 1. So, here we have to
|
||||||
|
// figure out which field number corresponds to
|
||||||
|
// "content", and then set our expected file names below
|
||||||
|
// accordingly:
|
||||||
|
CompoundFileReader cfsReader = new CompoundFileReader(dir, "_2.cfs");
|
||||||
|
FieldInfos fieldInfos = new FieldInfos(cfsReader, "_2.fnm");
|
||||||
|
int contentFieldIndex = -1;
|
||||||
|
for(int i=0;i<fieldInfos.size();i++) {
|
||||||
|
FieldInfo fi = fieldInfos.fieldInfo(i);
|
||||||
|
if (fi.name.equals("content")) {
|
||||||
|
contentFieldIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue("could not locate the 'content' field number in the _2.cfs segment", contentFieldIndex != -1);
|
||||||
|
|
||||||
// Now verify file names:
|
// Now verify file names:
|
||||||
String[] expected = {"_0.cfs",
|
String[] expected = {"_0.cfs",
|
||||||
"_0_1.del",
|
"_0_1.del",
|
||||||
"_1.cfs",
|
"_1.cfs",
|
||||||
"_2.cfs",
|
"_2.cfs",
|
||||||
"_2_1.s0",
|
"_2_1.s" + contentFieldIndex,
|
||||||
"_3.cfs",
|
"_3.cfs",
|
||||||
"segments_a",
|
"segments_a",
|
||||||
"segments.gen"};
|
"segments.gen"};
|
||||||
|
|
|
@ -29,12 +29,7 @@ import java.util.zip.*;
|
||||||
|
|
||||||
public class TestIndexFileDeleter extends TestCase
|
public class TestIndexFileDeleter extends TestCase
|
||||||
{
|
{
|
||||||
// disable until hardcoded file names are fixes:
|
public void testDeleteLeftoverFiles() throws IOException {
|
||||||
public void testDummy() {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void _testDeleteLeftoverFiles() throws IOException {
|
|
||||||
|
|
||||||
Directory dir = new RAMDirectory();
|
Directory dir = new RAMDirectory();
|
||||||
|
|
||||||
|
@ -64,25 +59,45 @@ public class TestIndexFileDeleter extends TestCase
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// The numbering of fields can vary depending on which
|
||||||
|
// JRE is in use. On some JREs we see content bound to
|
||||||
|
// field 0; on others, field 1. So, here we have to
|
||||||
|
// figure out which field number corresponds to
|
||||||
|
// "content", and then set our expected file names below
|
||||||
|
// accordingly:
|
||||||
|
CompoundFileReader cfsReader = new CompoundFileReader(dir, "_2.cfs");
|
||||||
|
FieldInfos fieldInfos = new FieldInfos(cfsReader, "_2.fnm");
|
||||||
|
int contentFieldIndex = -1;
|
||||||
|
for(int i=0;i<fieldInfos.size();i++) {
|
||||||
|
FieldInfo fi = fieldInfos.fieldInfo(i);
|
||||||
|
if (fi.name.equals("content")) {
|
||||||
|
contentFieldIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue("could not locate the 'content' field number in the _2.cfs segment", contentFieldIndex != -1);
|
||||||
|
|
||||||
|
String normSuffix = "s" + contentFieldIndex;
|
||||||
|
|
||||||
// Create a bogus separate norms file for a
|
// Create a bogus separate norms file for a
|
||||||
// segment/field that actually has a separate norms file
|
// segment/field that actually has a separate norms file
|
||||||
// already:
|
// already:
|
||||||
copyFile(dir, "_2_1.s0", "_2_2.s0");
|
copyFile(dir, "_2_1." + normSuffix, "_2_2." + normSuffix);
|
||||||
|
|
||||||
// Create a bogus separate norms file for a
|
// Create a bogus separate norms file for a
|
||||||
// segment/field that actually has a separate norms file
|
// segment/field that actually has a separate norms file
|
||||||
// already, using the "not compound file" extension:
|
// already, using the "not compound file" extension:
|
||||||
copyFile(dir, "_2_1.s0", "_2_2.f0");
|
copyFile(dir, "_2_1." + normSuffix, "_2_2.f" + contentFieldIndex);
|
||||||
|
|
||||||
// Create a bogus separate norms file for a
|
// Create a bogus separate norms file for a
|
||||||
// segment/field that does not have a separate norms
|
// segment/field that does not have a separate norms
|
||||||
// file already:
|
// file already:
|
||||||
copyFile(dir, "_2_1.s0", "_1_1.s0");
|
copyFile(dir, "_2_1." + normSuffix, "_1_1." + normSuffix);
|
||||||
|
|
||||||
// Create a bogus separate norms file for a
|
// Create a bogus separate norms file for a
|
||||||
// segment/field that does not have a separate norms
|
// segment/field that does not have a separate norms
|
||||||
// file already using the "not compound file" extension:
|
// file already using the "not compound file" extension:
|
||||||
copyFile(dir, "_2_1.s0", "_1_1.f0");
|
copyFile(dir, "_2_1." + normSuffix, "_1_1.f" + contentFieldIndex);
|
||||||
|
|
||||||
// Create a bogus separate del file for a
|
// Create a bogus separate del file for a
|
||||||
// segment that already has a separate del file:
|
// segment that already has a separate del file:
|
||||||
|
|
Loading…
Reference in New Issue