Return-Path:
Delivered-To: apmail-lucene-commits-archive@www.apache.org
Received: (qmail 51995 invoked from network); 21 Mar 2011 11:24:11 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3)
by minotaur.apache.org with SMTP; 21 Mar 2011 11:24:11 -0000
Received: (qmail 58702 invoked by uid 500); 21 Mar 2011 11:24:11 -0000
Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@lucene.apache.org
Delivered-To: mailing list commits@lucene.apache.org
Received: (qmail 58695 invoked by uid 99); 21 Mar 2011 11:24:11 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Mar 2011 11:24:11 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Mar 2011 11:24:10 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id 44F0623888EA; Mon, 21 Mar 2011 11:23:38 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1083731 - in /lucene/dev/trunk: ./ lucene/
modules/benchmark/
modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/
modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/
modules/benchmark/src/test/org/apache/lucene/...
Date: Mon, 21 Mar 2011 11:23:38 -0000
To: commits@lucene.apache.org
From: doronc@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20110321112338.44F0623888EA@eris.apache.org>
Author: doronc
Date: Mon Mar 21 11:23:37 2011
New Revision: 1083731
URL: http://svn.apache.org/viewvc?rev=1083731&view=rev
Log:
LUCENE-2964: Allow benchmark tasks from alternative packages - merge/port from 3x.
Added:
lucene/dev/trunk/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/
- copied from r1083726, lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/
lucene/dev/trunk/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
- copied unchanged from r1083726, lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltPackageTaskTest.java
lucene/dev/trunk/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java
- copied unchanged from r1083726, lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/alt/AltTestTask.java
Modified:
lucene/dev/trunk/ (props changed)
lucene/dev/trunk/lucene/ (props changed)
lucene/dev/trunk/modules/benchmark/CHANGES.txt
lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
Modified: lucene/dev/trunk/modules/benchmark/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/CHANGES.txt?rev=1083731&r1=1083730&r2=1083731&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/CHANGES.txt (original)
+++ lucene/dev/trunk/modules/benchmark/CHANGES.txt Mon Mar 21 11:23:37 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/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html?rev=1083731&r1=1083730&r2=1083731&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html (original)
+++ lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/package.html Mon Mar 21 11:23:37 2011
@@ -170,6 +170,9 @@ with the benchmark.ext.classpath propert
-Dbenchmark.ext.classpath=/mydir/classes
-Dtask.mem=512M
+External tasks: When writing your own tasks under a package other than
+org.apache.lucene.benchmark.byTask.tasks specify that package thru the
+alt.tasks.packages property.
@@ -590,6 +593,14 @@ Here is a list of currently defined prop
+
+ Task alternative packages:
+ - 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.
+
+
Modified: lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java?rev=1083731&r1=1083730&r2=1083731&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java (original)
+++ lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Algorithm.java Mon Mar 21 11:23:37 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 pkgs = new ArrayList();
+ 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");