pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / benchmark / src / test / org / apache / lucene / benchmark / byTask / tasks / CreateIndexTaskTest.java
1 package org.apache.lucene.benchmark.byTask.tasks;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.io.ByteArrayOutputStream;
21 import java.io.File;
22 import java.io.PrintStream;
23 import java.util.Properties;
24
25 import org.apache.lucene.benchmark.BenchmarkTestCase;
26 import org.apache.lucene.benchmark.byTask.PerfRunData;
27 import org.apache.lucene.benchmark.byTask.utils.Config;
28 import org.apache.lucene.index.NoDeletionPolicy;
29 import org.apache.lucene.index.NoMergePolicy;
30 import org.apache.lucene.index.NoMergeScheduler;
31 import org.apache.lucene.util.Version;
32
33
34 /** Tests the functionality of {@link CreateIndexTask}. */
35 public class CreateIndexTaskTest extends BenchmarkTestCase {
36
37   private PerfRunData createPerfRunData(String infoStreamValue) throws Exception {
38     Properties props = new Properties();
39     props.setProperty("writer.version", Version.LUCENE_31.toString());
40     props.setProperty("print.props", "false"); // don't print anything
41     props.setProperty("directory", "RAMDirectory");
42     if (infoStreamValue != null) {
43       props.setProperty("writer.info.stream", infoStreamValue);
44     }
45     Config config = new Config(props);
46     return new PerfRunData(config);
47   }
48
49   public void testInfoStream_SystemOutErr() throws Exception {
50  
51     PrintStream curOut = System.out;
52     ByteArrayOutputStream baos = new ByteArrayOutputStream();
53     System.setOut(new PrintStream(baos));
54     try {
55       PerfRunData runData = createPerfRunData("SystemOut");
56       CreateIndexTask cit = new CreateIndexTask(runData);
57       cit.doLogic();
58       new CloseIndexTask(runData).doLogic();
59       assertTrue(baos.size() > 0);
60     } finally {
61       System.setOut(curOut);
62     }
63     
64     PrintStream curErr = System.err;
65     baos.reset();
66     System.setErr(new PrintStream(baos));
67     try {
68       PerfRunData runData = createPerfRunData("SystemErr");
69       CreateIndexTask cit = new CreateIndexTask(runData);
70       cit.doLogic();
71       new CloseIndexTask(runData).doLogic();
72       assertTrue(baos.size() > 0);
73     } finally {
74       System.setErr(curErr);
75     }
76
77   }
78
79   public void testInfoStream_File() throws Exception {
80     
81     File outFile = new File(getWorkDir(), "infoStreamTest");
82     PerfRunData runData = createPerfRunData(outFile.getAbsolutePath());
83     new CreateIndexTask(runData).doLogic();
84     new CloseIndexTask(runData).doLogic();
85     assertTrue(outFile.length() > 0);
86   }
87
88   public void testNoMergePolicy() throws Exception {
89     PerfRunData runData = createPerfRunData(null);
90     runData.getConfig().set("merge.policy", NoMergePolicy.class.getName());
91     new CreateIndexTask(runData).doLogic();
92     new CloseIndexTask(runData).doLogic();
93   }
94   
95   public void testNoMergeScheduler() throws Exception {
96     PerfRunData runData = createPerfRunData(null);
97     runData.getConfig().set("merge.scheduler", NoMergeScheduler.class.getName());
98     new CreateIndexTask(runData).doLogic();
99     new CloseIndexTask(runData).doLogic();
100   }
101
102   public void testNoDeletionPolicy() throws Exception {
103     PerfRunData runData = createPerfRunData(null);
104     runData.getConfig().set("deletion.policy", NoDeletionPolicy.class.getName());
105     new CreateIndexTask(runData).doLogic();
106     new CloseIndexTask(runData).doLogic();
107   }
108 }