2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.lucene.benchmark.byTask;
20
import java.io.StringReader;
21
import java.util.ArrayList;
23
import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
24
import org.apache.lucene.benchmark.byTask.tasks.TaskSequence;
25
import org.apache.lucene.benchmark.byTask.utils.Algorithm;
26
import org.apache.lucene.util.LuceneTestCase;
28
/** Test very simply that perf tasks are parses as expected. */
29
public class TestPerfTasksParse extends LuceneTestCase {
31
static final String NEW_LINE = System.getProperty("line.separator");
32
static final String INDENT = " ";
34
// properties in effect in all tests here
35
static final String propPart =
36
INDENT + "directory=RAMDirectory" + NEW_LINE +
37
INDENT + "print.props=false" + NEW_LINE
40
/** Test the repetiotion parsing for parallel tasks */
41
public void testParseParallelTaskSequenceRepetition() throws Exception {
42
String taskStr = "AddDoc";
43
String parsedTasks = "[ "+taskStr+" ] : 1000";
44
Benchmark benchmark = new Benchmark(new StringReader(propPart+parsedTasks));
45
Algorithm alg = benchmark.getAlgorithm();
46
ArrayList<PerfTask> algTasks = alg.extractTasks();
47
boolean foundAdd = false;
48
for (final PerfTask task : algTasks) {
49
if (task.toString().indexOf(taskStr)>=0) {
52
if (task instanceof TaskSequence) {
53
assertEquals("repetions should be 1000 for "+parsedTasks, 1000, ((TaskSequence) task).getRepetitions());
54
assertTrue("sequence for "+parsedTasks+" should be parallel!", ((TaskSequence) task).isParallel());
56
assertTrue("Task "+taskStr+" was not found in "+alg.toString(),foundAdd);
60
/** Test the repetiotion parsing for sequential tasks */
61
public void testParseTaskSequenceRepetition() throws Exception {
62
String taskStr = "AddDoc";
63
String parsedTasks = "{ "+taskStr+" } : 1000";
64
Benchmark benchmark = new Benchmark(new StringReader(propPart+parsedTasks));
65
Algorithm alg = benchmark.getAlgorithm();
66
ArrayList<PerfTask> algTasks = alg.extractTasks();
67
boolean foundAdd = false;
68
for (final PerfTask task : algTasks) {
69
if (task.toString().indexOf(taskStr)>=0) {
72
if (task instanceof TaskSequence) {
73
assertEquals("repetions should be 1000 for "+parsedTasks, 1000, ((TaskSequence) task).getRepetitions());
74
assertFalse("sequence for "+parsedTasks+" should be sequential!", ((TaskSequence) task).isParallel());
76
assertTrue("Task "+taskStr+" was not found in "+alg.toString(),foundAdd);