Search in sources :

Example 11 with PerfRunData

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");
}
Also used : Path(java.nio.file.Path) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData)

Example 12 with PerfRunData

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());
    }
}
Also used : Path(java.nio.file.Path) BufferedReader(java.io.BufferedReader) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData) HashSet(java.util.HashSet)

Example 13 with PerfRunData

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);
}
Also used : Config(org.apache.lucene.benchmark.byTask.utils.Config) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData) Properties(java.util.Properties)

Example 14 with PerfRunData

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");
}
Also used : Path(java.nio.file.Path) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData)

Example 15 with PerfRunData

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);
    }
}
Also used : Path(java.nio.file.Path) BufferedReader(java.io.BufferedReader) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData)

Aggregations

PerfRunData (org.apache.lucene.benchmark.byTask.PerfRunData)40 Config (org.apache.lucene.benchmark.byTask.utils.Config)13 Path (java.nio.file.Path)12 Properties (java.util.Properties)10 BufferedReader (java.io.BufferedReader)4 AddDocTask (org.apache.lucene.benchmark.byTask.tasks.AddDocTask)3 CloseIndexTask (org.apache.lucene.benchmark.byTask.tasks.CloseIndexTask)3 CreateIndexTask (org.apache.lucene.benchmark.byTask.tasks.CreateIndexTask)3 TaskSequence (org.apache.lucene.benchmark.byTask.tasks.TaskSequence)3 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 WhitespaceAnalyzer (org.apache.lucene.analysis.core.WhitespaceAnalyzer)2 DirectoryTaxonomyWriter (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter)2 IndexReader (org.apache.lucene.index.IndexReader)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 Term (org.apache.lucene.index.Term)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 TermQuery (org.apache.lucene.search.TermQuery)2 TopDocs (org.apache.lucene.search.TopDocs)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1