add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / test / org / apache / lucene / benchmark / byTask / TestPerfTasksParse.java
1 /**
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.apache.lucene.benchmark.byTask;
19
20 import java.io.StringReader;
21 import java.util.ArrayList;
22
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;
27
28 /** Test very simply that perf tasks are parses as expected. */
29 public class TestPerfTasksParse extends LuceneTestCase {
30
31   static final String NEW_LINE = System.getProperty("line.separator");
32   static final String INDENT = "  ";
33
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
38   ;
39
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) {
50           foundAdd = true;
51        }
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());
55        }
56        assertTrue("Task "+taskStr+" was not found in "+alg.toString(),foundAdd);
57     }
58   }
59
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) {
70           foundAdd = true;
71        }
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());
75        }
76        assertTrue("Task "+taskStr+" was not found in "+alg.toString(),foundAdd);
77     }
78   }
79
80 }