You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by do...@apache.org on 2011/03/21 11:48:08 UTC
svn commit: r1083726 - in
/lucene/dev/branches/branch_3x/lucene/contrib/benchmark: ./
src/java/org/apache/lucene/benchmark/byTask/
src/java/org/apache/lucene/benchmark/byTask/utils/
src/test/org/apache/lucene/benchmark/byTask/tasks/alt/
Author: doronc
Date: Mon Mar 21 10:48:08 2011
New Revision: 1083726
URL: http://svn.apache.org/viewvc?rev=1083726&view=rev
Log:
LUCENE-2964: Allow benchmark tasks from alternative packages.
Added:
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java
Modified:
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/CHANGES.txt
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
Modified: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/CHANGES.txt?rev=1083726&r1=1083725&r2=1083726&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/CHANGES.txt Mon Mar 21 10:48:08 2011
@@ -2,6 +2,11 @@ Lucene Benchmark Contrib Change Log
The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways.
+03/21/2011
+ LUCENE-2964: Allow benchmark tasks from alternative packages,
+ specified through a new property "alt.tasks.packages".
+ (Doron Cohen, Shai Erera)
+
03/20/2011
LUCENE-2963: Easier way to run benchmark, by calling Benmchmark.exec(alg-file).
(Doron Cohen)
Modified: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html?rev=1083726&r1=1083725&r2=1083726&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html Mon Mar 21 10:48:08 2011
@@ -170,6 +170,9 @@ with the benchmark.ext.classpath propert
<font color="#FF0000">-Dbenchmark.ext.classpath=/mydir/classes
</font> -Dtask.mem=512M</li>
</ul>
+<u>External tasks</u>: When writing your own tasks under a package other than
+<b>org.apache.lucene.benchmark.byTask.tasks</b> specify that package thru the
+<font color="#FF0000">alt.tasks.packages</font> property.
</p>
<a name="algorithm"></a>
@@ -590,6 +593,14 @@ Here is a list of currently defined prop
<ul><li>doc.delete.step
</li></ul>
</li>
+
+ <li><b>Task alternative packages</b>:
+ <ul><li>alt.tasks.packages
+ - comma separated list of additional packages where tasks classes will be looked for
+ when not found in the default package (that of PerfTask). If the same task class
+ appears in more than one package, the package indicated first in this list will be used.
+ </li></ul>
+ </li>
</ol>
Modified: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java?rev=1083726&r1=1083725&r2=1083726&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java Mon Mar 21 10:48:08 2011
@@ -21,6 +21,7 @@ import java.io.StreamTokenizer;
import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
+import java.util.Arrays;
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
@@ -33,15 +34,23 @@ import org.apache.lucene.benchmark.byTas
public class Algorithm {
private TaskSequence sequence;
+ private final String[] taskPackages;
/**
* Read algorithm from file
+ * Property examined: alt.tasks.packages == comma separated list of
+ * alternate package names where tasks would be searched for, when not found
+ * in the default package (that of {@link PerfTask}{@link #getClass()}).
+ * If the same task class appears in more than one package, the package
+ * indicated first in this list will be used.
* @param runData perf-run-data used at running the tasks.
* @throws Exception if errors while parsing the algorithm
*/
@SuppressWarnings("fallthrough")
public Algorithm (PerfRunData runData) throws Exception {
- String algTxt = runData.getConfig().getAlgorithmText();
+ Config config = runData.getConfig();
+ taskPackages = initTasksPackages(config);
+ String algTxt = config.getAlgorithmText();
sequence = new TaskSequence(runData,null,null,false);
TaskSequence currSequence = sequence;
PerfTask prevTask = null;
@@ -55,14 +64,13 @@ public class Algorithm {
boolean colonOk = false;
boolean isDisableCountNextTask = false; // only for primitive tasks
currSequence.setDepth(0);
- String taskPackage = PerfTask.class.getPackage().getName() + ".";
while (stok.nextToken() != StreamTokenizer.TT_EOF) {
switch(stok.ttype) {
case StreamTokenizer.TT_WORD:
String s = stok.sval;
- Constructor<? extends PerfTask> cnstr = Class.forName(taskPackage+s+"Task")
+ Constructor<? extends PerfTask> cnstr = taskClass(config,s)
.asSubclass(PerfTask.class).getConstructor(PerfRunData.class);
PerfTask task = cnstr.newInstance(runData);
task.setDisableCounting(isDisableCountNextTask);
@@ -248,9 +256,33 @@ public class Algorithm {
}
}
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
+ private String[] initTasksPackages(Config config) {
+ String alts = config.get("alt.tasks.packages", null);
+ String dfltPkg = PerfTask.class.getPackage().getName();
+ if (alts==null) {
+ return new String[]{ dfltPkg };
+ }
+ ArrayList<String> pkgs = new ArrayList<String>();
+ pkgs.add(dfltPkg);
+ for (String alt : alts.split(",")) {
+ pkgs.add(alt);
+ }
+ return pkgs.toArray(new String[0]);
+ }
+
+ private Class<?> taskClass(Config config, String taskName)
+ throws ClassNotFoundException {
+ for (String pkg : taskPackages) {
+ try {
+ return Class.forName(pkg+'.'+taskName+"Task");
+ } catch (ClassNotFoundException e) {
+ // failed in this package, might succeed in the next one...
+ }
+ }
+ // can only get here if failed to instantiate
+ throw new ClassNotFoundException(taskName+" not found in packages "+Arrays.toString(taskPackages));
+ }
+
@Override
public String toString() {
String newline = System.getProperty("line.separator");
Added: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java?rev=1083726&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java (added)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java Mon Mar 21 10:48:08 2011
@@ -0,0 +1,55 @@
+package org.apache.lucene.benchmark.byTask.tasks.alt;
+
+/**
+ * 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 org.apache.lucene.benchmark.BenchmarkTestCase;
+import org.apache.lucene.benchmark.byTask.Benchmark;
+
+/** Tests that tasks in alternate packages are found. */
+public class AltPackageTaskTest extends BenchmarkTestCase {
+
+ /** Benchmark should fail loading the algorithm when alt is not specified */
+ public void testWithoutAlt() throws Exception {
+ try {
+ execBenchmark(altAlg(false));
+ assertFalse("Should have failed to run the algorithm",true);
+ } catch(Exception e) {
+ // expected exception, do nothing
+ }
+ }
+
+ /** Benchmark should be able to load the algorithm when alt is specified */
+ public void testWithAlt() throws Exception {
+ Benchmark bm = execBenchmark(altAlg(true));
+ assertNotNull(bm);
+ assertNotNull(bm.getRunData().getPoints());
+ }
+
+ private String[] altAlg(boolean allowAlt) {
+ String altTask = "{ AltTest }";
+ if (allowAlt) {
+ return new String[] {
+ "alt.tasks.packages = " +this.getClass().getPackage().getName(),
+ altTask
+ };
+ }
+ return new String[] {
+ altTask
+ };
+ }
+}
Added: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java?rev=1083726&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java (added)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java Mon Mar 21 10:48:08 2011
@@ -0,0 +1,37 @@
+package org.apache.lucene.benchmark.byTask.tasks.alt;
+
+/**
+ * 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 org.apache.lucene.benchmark.byTask.PerfRunData;
+import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
+
+/**
+ * {@link PerfTask} which does nothing, but is in a different package
+ */
+public class AltTestTask extends PerfTask {
+
+ public AltTestTask(PerfRunData runData) {
+ super(runData);
+ }
+
+ @Override
+ public int doLogic() throws Exception {
+ return 0;
+ }
+
+}