Search in sources :

Example 1 with Algorithm

use of org.apache.lucene.benchmark.byTask.utils.Algorithm in project lucene-solr by apache.

the class TestPerfTasksParse method testParseParallelTaskSequenceRepetition.

/** Test the repetiotion parsing for parallel tasks */
public void testParseParallelTaskSequenceRepetition() throws Exception {
    String taskStr = "AddDoc";
    String parsedTasks = "[ " + taskStr + " ] : 1000";
    Benchmark benchmark = new Benchmark(new StringReader(propPart + parsedTasks));
    Algorithm alg = benchmark.getAlgorithm();
    ArrayList<PerfTask> algTasks = alg.extractTasks();
    boolean foundAdd = false;
    for (final PerfTask task : algTasks) {
        if (task.toString().indexOf(taskStr) >= 0) {
            foundAdd = true;
        }
        if (task instanceof TaskSequence) {
            assertEquals("repetions should be 1000 for " + parsedTasks, 1000, ((TaskSequence) task).getRepetitions());
            assertTrue("sequence for " + parsedTasks + " should be parallel!", ((TaskSequence) task).isParallel());
        }
        assertTrue("Task " + taskStr + " was not found in " + alg.toString(), foundAdd);
    }
}
Also used : TaskSequence(org.apache.lucene.benchmark.byTask.tasks.TaskSequence) StringReader(java.io.StringReader) Algorithm(org.apache.lucene.benchmark.byTask.utils.Algorithm) PerfTask(org.apache.lucene.benchmark.byTask.tasks.PerfTask)

Example 2 with Algorithm

use of org.apache.lucene.benchmark.byTask.utils.Algorithm in project lucene-solr by apache.

the class TestPerfTasksParse method testParseExamples.

/** Test the parsing of example scripts **/
@SuppressWarnings("try")
public void testParseExamples() throws Exception {
    // hackedy-hack-hack
    boolean foundFiles = false;
    final Path examplesDir = Paths.get(ConfLoader.class.getResource(".").toURI());
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(examplesDir, "*.alg")) {
        for (Path path : stream) {
            Config config = new Config(Files.newBufferedReader(path, StandardCharsets.UTF_8));
            String contentSource = config.get("content.source", null);
            if (contentSource != null) {
                Class.forName(contentSource);
            }
            config.set("work.dir", createTempDir(LuceneTestCase.getTestClass().getSimpleName()).toAbsolutePath().toString());
            config.set("content.source", MockContentSource.class.getName());
            String dir = config.get("content.source", null);
            if (dir != null) {
                Class.forName(dir);
            }
            config.set("directory", RAMDirectory.class.getName());
            if (config.get("line.file.out", null) != null) {
                config.set("line.file.out", createTempFile("linefile", ".txt").toAbsolutePath().toString());
            }
            if (config.get("query.maker", null) != null) {
                Class.forName(config.get("query.maker", null));
                config.set("query.maker", MockQueryMaker.class.getName());
            }
            PerfRunData data = new PerfRunData(config);
            try (Algorithm algo = new Algorithm(data)) {
            }
            foundFiles = true;
        }
    }
    if (!foundFiles) {
        fail("could not find any .alg files!");
    }
}
Also used : Path(java.nio.file.Path) Config(org.apache.lucene.benchmark.byTask.utils.Config) Algorithm(org.apache.lucene.benchmark.byTask.utils.Algorithm) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 3 with Algorithm

use of org.apache.lucene.benchmark.byTask.utils.Algorithm in project lucene-solr by apache.

the class TestPerfTasksParse method testParseTaskSequenceRepetition.

/** Test the repetiotion parsing for sequential  tasks */
public void testParseTaskSequenceRepetition() throws Exception {
    String taskStr = "AddDoc";
    String parsedTasks = "{ " + taskStr + " } : 1000";
    Benchmark benchmark = new Benchmark(new StringReader(propPart + parsedTasks));
    Algorithm alg = benchmark.getAlgorithm();
    ArrayList<PerfTask> algTasks = alg.extractTasks();
    boolean foundAdd = false;
    for (final PerfTask task : algTasks) {
        if (task.toString().indexOf(taskStr) >= 0) {
            foundAdd = true;
        }
        if (task instanceof TaskSequence) {
            assertEquals("repetions should be 1000 for " + parsedTasks, 1000, ((TaskSequence) task).getRepetitions());
            assertFalse("sequence for " + parsedTasks + " should be sequential!", ((TaskSequence) task).isParallel());
        }
        assertTrue("Task " + taskStr + " was not found in " + alg.toString(), foundAdd);
    }
}
Also used : TaskSequence(org.apache.lucene.benchmark.byTask.tasks.TaskSequence) StringReader(java.io.StringReader) Algorithm(org.apache.lucene.benchmark.byTask.utils.Algorithm) PerfTask(org.apache.lucene.benchmark.byTask.tasks.PerfTask)

Aggregations

Algorithm (org.apache.lucene.benchmark.byTask.utils.Algorithm)3 StringReader (java.io.StringReader)2 PerfTask (org.apache.lucene.benchmark.byTask.tasks.PerfTask)2 TaskSequence (org.apache.lucene.benchmark.byTask.tasks.TaskSequence)2 Path (java.nio.file.Path)1 Config (org.apache.lucene.benchmark.byTask.utils.Config)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1