1 package org.apache.lucene.benchmark.byTask.tasks;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.ByteArrayOutputStream;
22 import java.io.PrintStream;
23 import java.util.Properties;
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;
34 /** Tests the functionality of {@link CreateIndexTask}. */
35 public class CreateIndexTaskTest extends BenchmarkTestCase {
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);
45 Config config = new Config(props);
46 return new PerfRunData(config);
49 public void testInfoStream_SystemOutErr() throws Exception {
51 PrintStream curOut = System.out;
52 ByteArrayOutputStream baos = new ByteArrayOutputStream();
53 System.setOut(new PrintStream(baos));
55 PerfRunData runData = createPerfRunData("SystemOut");
56 CreateIndexTask cit = new CreateIndexTask(runData);
58 new CloseIndexTask(runData).doLogic();
59 assertTrue(baos.size() > 0);
61 System.setOut(curOut);
64 PrintStream curErr = System.err;
66 System.setErr(new PrintStream(baos));
68 PerfRunData runData = createPerfRunData("SystemErr");
69 CreateIndexTask cit = new CreateIndexTask(runData);
71 new CloseIndexTask(runData).doLogic();
72 assertTrue(baos.size() > 0);
74 System.setErr(curErr);
79 public void testInfoStream_File() throws Exception {
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);
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();
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();
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();