use of org.apache.lucene.benchmark.byTask.PerfRunData in project lucene-solr by apache.
the class WriteLineDocTaskTest method testRegularFile.
public void testRegularFile() throws Exception {
// Create a document in regular format.
Path file = getWorkDir().resolve("one-line");
PerfRunData runData = createPerfRunData(file, false, WriteLineDocMaker.class.getName());
WriteLineDocTask wldt = new WriteLineDocTask(runData);
wldt.doLogic();
wldt.close();
doReadTest(file, Type.PLAIN, "title", "date", "body");
}
use of org.apache.lucene.benchmark.byTask.PerfRunData in project lucene-solr by apache.
the class WriteLineDocTaskTest method testMultiThreaded.
public void testMultiThreaded() throws Exception {
Path file = getWorkDir().resolve("one-line");
PerfRunData runData = createPerfRunData(file, false, ThreadingDocMaker.class.getName());
final WriteLineDocTask wldt = new WriteLineDocTask(runData);
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread("t" + i) {
@Override
public void run() {
try {
wldt.doLogic();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
for (Thread t : threads) t.start();
for (Thread t : threads) t.join();
wldt.close();
Set<String> ids = new HashSet<>();
try (BufferedReader br = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
String line = br.readLine();
// header line is written once, no matter how many threads there are
assertHeaderLine(line);
for (int i = 0; i < threads.length; i++) {
line = br.readLine();
String[] parts = line.split(Character.toString(WriteLineDocTask.SEP));
assertEquals(3, parts.length);
// check that all thread names written are the same in the same line
String tname = parts[0].substring(parts[0].indexOf('_'));
ids.add(tname);
assertEquals(tname, parts[1].substring(parts[1].indexOf('_')));
assertEquals(tname, parts[2].substring(parts[2].indexOf('_')));
}
// only threads.length lines should exist
assertNull(br.readLine());
assertEquals(threads.length, ids.size());
}
}
use of org.apache.lucene.benchmark.byTask.PerfRunData in project lucene-solr by apache.
the class WriteLineDocTaskTest method createPerfRunData.
private PerfRunData createPerfRunData(Path file, boolean allowEmptyDocs, String docMakerName) throws Exception {
Properties props = new Properties();
props.setProperty("doc.maker", docMakerName);
props.setProperty("line.file.out", file.toAbsolutePath().toString());
// no accidental FS dir.
props.setProperty("directory", "RAMDirectory");
if (allowEmptyDocs) {
props.setProperty("sufficient.fields", ",");
}
if (docMakerName.equals(LegalJustDateDocMaker.class.getName())) {
props.setProperty("line.fields", DocMaker.DATE_FIELD);
props.setProperty("sufficient.fields", DocMaker.DATE_FIELD);
}
Config config = new Config(props);
return new PerfRunData(config);
}
use of org.apache.lucene.benchmark.byTask.PerfRunData in project lucene-solr by apache.
the class WriteLineDocTaskTest method testCharsReplace.
public void testCharsReplace() throws Exception {
// WriteLineDocTask replaced only \t characters w/ a space, since that's its
// separator char. However, it didn't replace newline characters, which
// resulted in errors in LineDocSource.
Path file = getWorkDir().resolve("one-line");
PerfRunData runData = createPerfRunData(file, false, NewLinesDocMaker.class.getName());
WriteLineDocTask wldt = new WriteLineDocTask(runData);
wldt.doLogic();
wldt.close();
doReadTest(file, Type.PLAIN, "title text", "date text", "body text two");
}
use of org.apache.lucene.benchmark.byTask.PerfRunData in project lucene-solr by apache.
the class WriteLineDocTaskTest method testEmptyDoc.
public void testEmptyDoc() throws Exception {
Path file = getWorkDir().resolve("one-line");
PerfRunData runData = createPerfRunData(file, true, EmptyDocMaker.class.getName());
WriteLineDocTask wldt = new WriteLineDocTask(runData);
wldt.doLogic();
wldt.close();
try (BufferedReader br = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
String line = br.readLine();
assertHeaderLine(line);
line = br.readLine();
assertNotNull(line);
}
}
Aggregations