Index: lucene/benchmark/conf/addIndexes.alg =================================================================== --- lucene/benchmark/conf/addIndexes.alg (revision 0) +++ lucene/benchmark/conf/addIndexes.alg (working copy) @@ -0,0 +1,45 @@ +#/** +# * Licensed to the Apache Software Foundation (ASF) under one or more +# * contributor license agreements. See the NOTICE file distributed with +# * this work for additional information regarding copyright ownership. +# * The ASF licenses this file to You under the Apache License, Version 2.0 +# * (the "License"); you may not use this file except in compliance with +# * the License. You may obtain a copy of the License at +# * +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# */ + +writer.version=LUCENE_40 + +analyzer=org.apache.lucene.analysis.standard.StandardAnalyzer +directory=FSDirectory +work.dir=output + +# directory to add the target index +addindexes.input.dir=input/index + +# task at this depth or less would print when they start +task.max.depth.log=2 + +# ------------------------------------------------------------------------------------- + +# call addIndexes (Directory) +ResetSystemErase +CreateIndex +{ "AddIndexesDirectory" AddIndexes(true) > +CloseIndex + +# call addIndexes (IndexReader) +ResetSystemErase +CreateIndex +{ "AddIndexesReader" AddIndexes(false) > +CloseIndex + +RepSumByName +RepSumByPref AddIndexes \ No newline at end of file Property changes on: lucene/benchmark/conf/addIndexes.alg ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* Index: lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java =================================================================== --- lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java (revision 0) +++ lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java (working copy) @@ -0,0 +1,140 @@ +package org.apache.lucene.benchmark.byTask.tasks; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; +import java.util.Properties; + +import org.apache.lucene.benchmark.BenchmarkTestCase; +import org.apache.lucene.benchmark.byTask.PerfRunData; +import org.apache.lucene.benchmark.byTask.utils.Config; +import org.apache.lucene.document.Document; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.MockDirectoryWrapper; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util._TestUtil; +import org.junit.BeforeClass; + +/** Tests the functionality of {@link AddIndexesTask}. */ +public class AddIndexesTaskTest extends BenchmarkTestCase { + + private static File testDir, inputDir; + + @BeforeClass + public static void beforeClassAddIndexesTaskTest() throws Exception { + testDir = _TestUtil.getTempDir("addIndexesTask"); + + // create a dummy index under inputDir + inputDir = new File(testDir, "input"); + MockDirectoryWrapper tmpDir = newFSDirectory(inputDir); + try { + IndexWriter writer = new IndexWriter(tmpDir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)); + for (int i = 0; i < 10; i++) { + writer.addDocument(new Document()); + } + writer.close(); + } finally { + tmpDir.close(); + } + } + + private PerfRunData createPerfRunData() throws Exception { + Properties props = new Properties(); + props.setProperty("writer.version", TEST_VERSION_CURRENT.toString()); + props.setProperty("print.props", "false"); // don't print anything + props.setProperty("directory", "RAMDirectory"); + props.setProperty(AddIndexesTask.ADDINDEXES_INPUT_DIR, inputDir.getAbsolutePath()); + Config config = new Config(props); + return new PerfRunData(config); + } + + private void assertIndex(PerfRunData runData) throws Exception { + Directory taskDir = runData.getDirectory(); + assertSame(RAMDirectory.class, taskDir.getClass()); + IndexReader r = DirectoryReader.open(taskDir); + try { + assertEquals(10, r.numDocs()); + } finally { + r.close(); + } + } + + public void testAddIndexesDefault() throws Exception { + PerfRunData runData = createPerfRunData(); + // create the target index first + new CreateIndexTask(runData).doLogic(); + + AddIndexesTask task = new AddIndexesTask(runData); + task.setup(); + + // add the input index + task.doLogic(); + + // close the index + new CloseIndexTask(runData).doLogic(); + + assertIndex(runData); + + runData.close(); + } + + public void testAddIndexesDir() throws Exception { + PerfRunData runData = createPerfRunData(); + // create the target index first + new CreateIndexTask(runData).doLogic(); + + AddIndexesTask task = new AddIndexesTask(runData); + task.setup(); + + // add the input index + task.setParams("true"); + task.doLogic(); + + // close the index + new CloseIndexTask(runData).doLogic(); + + assertIndex(runData); + + runData.close(); + } + + public void testAddIndexesReader() throws Exception { + PerfRunData runData = createPerfRunData(); + // create the target index first + new CreateIndexTask(runData).doLogic(); + + AddIndexesTask task = new AddIndexesTask(runData); + task.setup(); + + // add the input index + task.setParams("false"); + task.doLogic(); + + // close the index + new CloseIndexTask(runData).doLogic(); + + assertIndex(runData); + + runData.close(); + } + +} Property changes on: lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* Added: svn:eol-style ## -0,0 +1 ## +native Index: lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTask.java =================================================================== --- lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTask.java (revision 0) +++ lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTask.java (working copy) @@ -0,0 +1,102 @@ +package org.apache.lucene.benchmark.byTask.tasks; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; + +import org.apache.lucene.benchmark.byTask.PerfRunData; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; + +/** + * Adds an input index to an existing index, using + * {@link IndexWriter#addIndexes(Directory...)} or + * {@link IndexWriter#addIndexes(IndexReader...)}. The location of the input + * index is specified by the parameter {@link #ADDINDEXES_INPUT_DIR} and is + * assumed to be a directory on the file system. + *
+ * Takes optional parameter {@code useAddIndexesDir} which specifies which + * addIndexes variant to use (defaults to true, to use addIndexes(Directory)). + */ +public class AddIndexesTask extends PerfTask { + + public static final String ADDINDEXES_INPUT_DIR = "addindexes.input.dir"; + + public AddIndexesTask(PerfRunData runData) { + super(runData); + } + + private boolean useAddIndexesDir = true; + private FSDirectory inputDir; + + @Override + public void setup() throws Exception { + super.setup(); + String inputDirProp = getRunData().getConfig().get(ADDINDEXES_INPUT_DIR, null); + if (inputDirProp == null) { + throw new IllegalArgumentException("config parameter " + ADDINDEXES_INPUT_DIR + " not specified in configuration"); + } + inputDir = FSDirectory.open(new File(inputDirProp)); + } + + @Override + public int doLogic() throws Exception { + IndexWriter writer = getRunData().getIndexWriter(); + if (useAddIndexesDir) { + writer.addIndexes(inputDir); + } else { + IndexReader r = DirectoryReader.open(inputDir); + try { + writer.addIndexes(r); + } finally { + r.close(); + } + } + return 1; + } + + /** + * Set the params (useAddIndexesDir only) + * + * @param params + * {@code useAddIndexesDir=true} for using + * {@link IndexWriter#addIndexes(Directory...)} or {@code false} for + * using {@link IndexWriter#addIndexes(IndexReader...)}. Defaults to + * {@code true}. + */ + @Override + public void setParams(String params) { + super.setParams(params); + useAddIndexesDir = Boolean.parseBoolean(params); + } + + @Override + public boolean supportsParams() { + return true; + } + + @Override + public void tearDown() throws Exception { + inputDir.close(); + super.tearDown(); + } + +} Property changes on: lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTask.java ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* Added: svn:eol-style ## -0,0 +1 ## +native