You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/08/12 17:23:08 UTC
svn commit: r232310 [65/92] - in /beehive/trunk/controls/test: common/
infra/gtlf/ infra/gtlf/xsl/ infra/mantis/ infra/tch/ infra/tch/messages/
infra/tch/runtime/ infra/tch/schema/ perf/ perf/bin/ perf/cases/
perf/ctlsrc/org/apache/beehive/controls/per...
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/TimeoutResultHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/TimeoutResultHandler.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/TimeoutResultHandler.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/TimeoutResultHandler.java Fri Aug 12 08:12:28 2005
@@ -1,240 +1,240 @@
-package org.apache.beehive.test.tools.tch.core.test;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Stack;
-
-import org.apache.beehive.test.tools.tch.util.TchConstants;
-import org.apache.beehive.test.tools.tch.util.TestResult;
-import org.apache.beehive.test.tools.tch.util.TestResultAdapter;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-
-/**
- * TimeoutResultHandler adds functionality to ResultHandler by providing methods to
- * help deal with test timeout situations. Specifically, when a test times out, all subtests
- * which have not run yet need to log a skip. The test which is currently running needs to
- * log a timeout.
- */
-public class TimeoutResultHandler implements ResultHandler
-{
- private boolean timedOut = false;
- private int testTimeoutSeconds = -1;
- private ResultHandler resultHandler = null;
- private Collection subtestNamesLeftToRun = null;
- /**
- * Note: the Stack implementation here creates an
- * implicit restriction that tests run and log results in a discrete order.. basically we are
- * assuming that the top of the stack is what we want to log a timeout against. This is probably
- * fine in most cases, but may need to be careful..
- * For example, subtests could be running in different threads and logging
- * results asynchronously which could cause problems.. - echu
- */
- private Stack currentSubtestNameStack = null;
- private boolean willRunSubtests = false;
-
- /**
- * Constructor.
- * Create a TimeoutResultHandler by using an existing ResultHandler object and specifying the
- * number of seconds used as the test timeout.
- *
- * @param inResultHandler the original result handler
- * @param inTestTimeoutSeconds test timeout setting
- */
- public TimeoutResultHandler(
- ResultHandler inResultHandler,
- int inTestTimeoutSeconds)
- {
- this(inResultHandler, inTestTimeoutSeconds, null, false);
- }
-
- /**
- * Constructor.
- * Create a TimeoutResultHandler by using an existing ResultHandler object and specifying the
- * number of seconds used as the test timeout. Allows a set of subtests to be specified, which
- * will log a skip if the test times out.
- *
- * @param inResultHandler the original result handler
- * @param inTestTimeoutSeconds test timeout setting
- * @param inSubtestNames collection of all subtest names that will run
- * @param inWillRunSubtests indicates whether the test type actually uses subtests (e.g. this is
- * true for javatest)
- */
- public TimeoutResultHandler(
- ResultHandler inResultHandler,
- int inTestTimeoutSeconds,
- Collection inSubtestNames,
- boolean inWillRunSubtests)
- {
- resultHandler = inResultHandler;
- testTimeoutSeconds = inTestTimeoutSeconds;
- currentSubtestNameStack = new Stack();
- willRunSubtests = inWillRunSubtests;
-
- if (inSubtestNames != null)
- subtestNamesLeftToRun = new ArrayList(inSubtestNames);
- else
- subtestNamesLeftToRun = new ArrayList();
- }
-
- /**
- * Submit a result. We make the assumption that before a test/subtest starts, it will log a
- * BEGIN result. This is used to determine if the test needs to log a timeout vs. skip. If a subtest
- * has not started running yet, it would just log a skip in the event that a timeout result is
- * submitted via TimeoutResultHandler. When a test finishes, it logs an outcome result, and we no
- * longer need to consider it.
- * <p>
- * Multiple subtests might be running at the same time. For example, in javatest
- * this can happen if one test method "requires" another method. In this case, we only
- * log a timeout against the method on the top of the stack. The rest will log skips.
- *
- * @param tr the test result being submitted
- */
- public synchronized void submitResult(TestResultBean tr)
- {
- if (isBeginResult(tr))
- {
- currentSubtestNameStack.push(tr.getName());
- }
- else if (isOutcomeResult(tr))
- {
- subtestNamesLeftToRun.remove(tr.getName());
- if (!currentSubtestNameStack.isEmpty())
- currentSubtestNameStack.pop();
- }
- if (!timedOut)
- resultHandler.submitResult(tr);
- }
-
- /**
- * Submit a result. Allows a result name to be specified.
- *
- * @param tr the test result being submitted
- * @param resultName result name is usually the name of the subtest
- */
- public synchronized void submitResult(TestResultBean tr, String resultName)
- {
- if (isBeginResult(tr))
- {
- currentSubtestNameStack.push(resultName);
- }
- else if (isOutcomeResult(tr))
- {
- subtestNamesLeftToRun.remove(resultName);
- if (!currentSubtestNameStack.isEmpty())
- currentSubtestNameStack.pop();
- }
- if (!timedOut)
- resultHandler.submitResult(tr, resultName);
- }
-
- /**
- * Method called to indicate that the test has timed out. This will set off the skip and timeout
- * logging logic.
- */
- public synchronized void setTimedOut()
- {
- // there might be a problem here if the test that is running
- // manages to log a result right before this gets called.
- // its unlikely, but possible
-
- timedOut = true;
- submitTimeoutResult();
- if (AntProperties.isVerboseOn())
- System.out.println(
- "Should SKIP these: " + subtestNamesLeftToRun.toString());
- skipRemainingTests();
- }
-
- /**
- * Internal method used to log skips against all subtests which have not run yet
- */
- private void skipRemainingTests()
- {
- for (Iterator iter = subtestNamesLeftToRun.iterator(); iter.hasNext();)
- {
- TestResultAdapter result =
- new TestResultAdapter(
- TchConstants.SKIP_LEVEL_INT,
- null,
- "Previous test timed out");
- String name = (String)iter.next();
- result.setSubtestName(name);
- resultHandler.submitResult(result, name);
- }
- }
-
- // do we need more synchronization here? It seems
-
- /**
- * Internal method used to log a timeout result. If subtests are used, will log a timeout
- * against the top subtest in the currently running stack.
- */
- private void submitTimeoutResult()
- {
- if (!currentSubtestNameStack.isEmpty())
- {
- // log a timeout if we've already received a BEGIN from a test
- // (currentSubtestNameStack will not be empty)
- // AND if the test hasn't logged an outcome already
- // (subtestNamesLeftToRun still contains the test)
- // This filters out timeouts from the constructor since no BEGINs
- // have been logged
- // This will only apply to javatest
- String resultName = (String)currentSubtestNameStack.pop();
- // this check is mainly introduced to deal with timeouts in wstest
- // additional filtering is also done in AbstractTestTask, but might as well check here
- // since it's easy
- if (subtestNamesLeftToRun.contains(resultName))
- {
- TestResultAdapter result =
- new TestResultAdapter(
- TchConstants.TIMEOUT_LEVEL_INT,
- null,
- "Timed out after " + testTimeoutSeconds + " seconds");
- result.setSubtestName(resultName);
- resultHandler.submitResult(result, resultName);
- subtestNamesLeftToRun.remove(resultName);
- }
- }
- else if (!willRunSubtests)
- {
- // this applies to all non-javatest tests since
- // willRunSubtests will be false
- TestResultAdapter result =
- new TestResultAdapter(
- TchConstants.TIMEOUT_LEVEL_INT,
- null,
- "Timed out after " + testTimeoutSeconds + " seconds");
- // the stack can be empty if there are no subtests (e.g. ant-task)
- result.setSubtestName(null);
- resultHandler.submitResult(result);
- }
- else
- {
- // this will be the case for javatest since willRunSubtests == true
- // However, since the subtest stack is empty, it means the timeout
- // probably happened in the test constructor, so we log a SCRATCH
- // instead of a TIMEOUT
- TestResultAdapter result =
- new TestResultAdapter(
- TchConstants.SCRATCH_LEVEL_INT,
- null,
- "Timed out after " + testTimeoutSeconds + " seconds");
- resultHandler.submitResult(result);
- }
- }
-
- private boolean isBeginResult(TestResult tr)
- {
- return (tr.getType() == TchConstants.BEGIN_LEVEL_INT);
- }
-
- private boolean isOutcomeResult(TestResult tr)
- {
- // hack. we should fix the whole outcome/adding-command-line-to-result
- // story
- return (tr.isOutcome());
- }
-}
+package org.apache.beehive.test.tools.tch.core.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Stack;
+
+import org.apache.beehive.test.tools.tch.util.TchConstants;
+import org.apache.beehive.test.tools.tch.util.TestResult;
+import org.apache.beehive.test.tools.tch.util.TestResultAdapter;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+
+/**
+ * TimeoutResultHandler adds functionality to ResultHandler by providing methods to
+ * help deal with test timeout situations. Specifically, when a test times out, all subtests
+ * which have not run yet need to log a skip. The test which is currently running needs to
+ * log a timeout.
+ */
+public class TimeoutResultHandler implements ResultHandler
+{
+ private boolean timedOut = false;
+ private int testTimeoutSeconds = -1;
+ private ResultHandler resultHandler = null;
+ private Collection subtestNamesLeftToRun = null;
+ /**
+ * Note: the Stack implementation here creates an
+ * implicit restriction that tests run and log results in a discrete order.. basically we are
+ * assuming that the top of the stack is what we want to log a timeout against. This is probably
+ * fine in most cases, but may need to be careful..
+ * For example, subtests could be running in different threads and logging
+ * results asynchronously which could cause problems.. - echu
+ */
+ private Stack currentSubtestNameStack = null;
+ private boolean willRunSubtests = false;
+
+ /**
+ * Constructor.
+ * Create a TimeoutResultHandler by using an existing ResultHandler object and specifying the
+ * number of seconds used as the test timeout.
+ *
+ * @param inResultHandler the original result handler
+ * @param inTestTimeoutSeconds test timeout setting
+ */
+ public TimeoutResultHandler(
+ ResultHandler inResultHandler,
+ int inTestTimeoutSeconds)
+ {
+ this(inResultHandler, inTestTimeoutSeconds, null, false);
+ }
+
+ /**
+ * Constructor.
+ * Create a TimeoutResultHandler by using an existing ResultHandler object and specifying the
+ * number of seconds used as the test timeout. Allows a set of subtests to be specified, which
+ * will log a skip if the test times out.
+ *
+ * @param inResultHandler the original result handler
+ * @param inTestTimeoutSeconds test timeout setting
+ * @param inSubtestNames collection of all subtest names that will run
+ * @param inWillRunSubtests indicates whether the test type actually uses subtests (e.g. this is
+ * true for javatest)
+ */
+ public TimeoutResultHandler(
+ ResultHandler inResultHandler,
+ int inTestTimeoutSeconds,
+ Collection inSubtestNames,
+ boolean inWillRunSubtests)
+ {
+ resultHandler = inResultHandler;
+ testTimeoutSeconds = inTestTimeoutSeconds;
+ currentSubtestNameStack = new Stack();
+ willRunSubtests = inWillRunSubtests;
+
+ if (inSubtestNames != null)
+ subtestNamesLeftToRun = new ArrayList(inSubtestNames);
+ else
+ subtestNamesLeftToRun = new ArrayList();
+ }
+
+ /**
+ * Submit a result. We make the assumption that before a test/subtest starts, it will log a
+ * BEGIN result. This is used to determine if the test needs to log a timeout vs. skip. If a subtest
+ * has not started running yet, it would just log a skip in the event that a timeout result is
+ * submitted via TimeoutResultHandler. When a test finishes, it logs an outcome result, and we no
+ * longer need to consider it.
+ * <p>
+ * Multiple subtests might be running at the same time. For example, in javatest
+ * this can happen if one test method "requires" another method. In this case, we only
+ * log a timeout against the method on the top of the stack. The rest will log skips.
+ *
+ * @param tr the test result being submitted
+ */
+ public synchronized void submitResult(TestResultBean tr)
+ {
+ if (isBeginResult(tr))
+ {
+ currentSubtestNameStack.push(tr.getName());
+ }
+ else if (isOutcomeResult(tr))
+ {
+ subtestNamesLeftToRun.remove(tr.getName());
+ if (!currentSubtestNameStack.isEmpty())
+ currentSubtestNameStack.pop();
+ }
+ if (!timedOut)
+ resultHandler.submitResult(tr);
+ }
+
+ /**
+ * Submit a result. Allows a result name to be specified.
+ *
+ * @param tr the test result being submitted
+ * @param resultName result name is usually the name of the subtest
+ */
+ public synchronized void submitResult(TestResultBean tr, String resultName)
+ {
+ if (isBeginResult(tr))
+ {
+ currentSubtestNameStack.push(resultName);
+ }
+ else if (isOutcomeResult(tr))
+ {
+ subtestNamesLeftToRun.remove(resultName);
+ if (!currentSubtestNameStack.isEmpty())
+ currentSubtestNameStack.pop();
+ }
+ if (!timedOut)
+ resultHandler.submitResult(tr, resultName);
+ }
+
+ /**
+ * Method called to indicate that the test has timed out. This will set off the skip and timeout
+ * logging logic.
+ */
+ public synchronized void setTimedOut()
+ {
+ // there might be a problem here if the test that is running
+ // manages to log a result right before this gets called.
+ // its unlikely, but possible
+
+ timedOut = true;
+ submitTimeoutResult();
+ if (AntProperties.isVerboseOn())
+ System.out.println(
+ "Should SKIP these: " + subtestNamesLeftToRun.toString());
+ skipRemainingTests();
+ }
+
+ /**
+ * Internal method used to log skips against all subtests which have not run yet
+ */
+ private void skipRemainingTests()
+ {
+ for (Iterator iter = subtestNamesLeftToRun.iterator(); iter.hasNext();)
+ {
+ TestResultAdapter result =
+ new TestResultAdapter(
+ TchConstants.SKIP_LEVEL_INT,
+ null,
+ "Previous test timed out");
+ String name = (String)iter.next();
+ result.setSubtestName(name);
+ resultHandler.submitResult(result, name);
+ }
+ }
+
+ // do we need more synchronization here? It seems
+
+ /**
+ * Internal method used to log a timeout result. If subtests are used, will log a timeout
+ * against the top subtest in the currently running stack.
+ */
+ private void submitTimeoutResult()
+ {
+ if (!currentSubtestNameStack.isEmpty())
+ {
+ // log a timeout if we've already received a BEGIN from a test
+ // (currentSubtestNameStack will not be empty)
+ // AND if the test hasn't logged an outcome already
+ // (subtestNamesLeftToRun still contains the test)
+ // This filters out timeouts from the constructor since no BEGINs
+ // have been logged
+ // This will only apply to javatest
+ String resultName = (String)currentSubtestNameStack.pop();
+ // this check is mainly introduced to deal with timeouts in wstest
+ // additional filtering is also done in AbstractTestTask, but might as well check here
+ // since it's easy
+ if (subtestNamesLeftToRun.contains(resultName))
+ {
+ TestResultAdapter result =
+ new TestResultAdapter(
+ TchConstants.TIMEOUT_LEVEL_INT,
+ null,
+ "Timed out after " + testTimeoutSeconds + " seconds");
+ result.setSubtestName(resultName);
+ resultHandler.submitResult(result, resultName);
+ subtestNamesLeftToRun.remove(resultName);
+ }
+ }
+ else if (!willRunSubtests)
+ {
+ // this applies to all non-javatest tests since
+ // willRunSubtests will be false
+ TestResultAdapter result =
+ new TestResultAdapter(
+ TchConstants.TIMEOUT_LEVEL_INT,
+ null,
+ "Timed out after " + testTimeoutSeconds + " seconds");
+ // the stack can be empty if there are no subtests (e.g. ant-task)
+ result.setSubtestName(null);
+ resultHandler.submitResult(result);
+ }
+ else
+ {
+ // this will be the case for javatest since willRunSubtests == true
+ // However, since the subtest stack is empty, it means the timeout
+ // probably happened in the test constructor, so we log a SCRATCH
+ // instead of a TIMEOUT
+ TestResultAdapter result =
+ new TestResultAdapter(
+ TchConstants.SCRATCH_LEVEL_INT,
+ null,
+ "Timed out after " + testTimeoutSeconds + " seconds");
+ resultHandler.submitResult(result);
+ }
+ }
+
+ private boolean isBeginResult(TestResult tr)
+ {
+ return (tr.getType() == TchConstants.BEGIN_LEVEL_INT);
+ }
+
+ private boolean isOutcomeResult(TestResult tr)
+ {
+ // hack. we should fix the whole outcome/adding-command-line-to-result
+ // story
+ return (tr.isOutcome());
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/TimeoutResultHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/UsedParameterAdderResultHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/UsedParameterAdderResultHandler.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/UsedParameterAdderResultHandler.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/UsedParameterAdderResultHandler.java Fri Aug 12 08:12:28 2005
@@ -1,51 +1,51 @@
-/*
- * Created on Jul 18, 2003
- */
-package org.apache.beehive.test.tools.tch.core.test;
-
-import java.util.TreeMap;
-
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- * Result handler that is used when the result needs to store information
- * about which parameters have been used by the test.
- */
-public class UsedParameterAdderResultHandler implements ResultHandler
-{
- private InternalParameters parameters = null;
- private ResultHandler resultHandler = null;
-
- /**
- * Constructor for a UsedParameterAdderResultHandler.
- *
- * @param inResultHandler original result handler
- * @param inParameters parameters which are mapped to the test. This should also contain information
- * about which parameters have actually been used
- */
- public UsedParameterAdderResultHandler(
- ResultHandler inResultHandler,
- InternalParameters inParameters)
- {
- resultHandler = inResultHandler;
- parameters = inParameters;
- }
-
- public void submitResult(TestResultBean tr)
- {
- if (tr.getParameters() == null || tr.getParameters().isEmpty())
- {
- tr.setParameters(new TreeMap(parameters.getUsedParams()));
- }
- resultHandler.submitResult(tr);
- }
-
- public void submitResult(TestResultBean tr, String resultName)
- {
- if (tr.getParameters() == null || tr.getParameters().isEmpty())
- {
- tr.setParameters(new TreeMap(parameters.getUsedParams()));
- }
- resultHandler.submitResult(tr, resultName);
- }
-}
+/*
+ * Created on Jul 18, 2003
+ */
+package org.apache.beehive.test.tools.tch.core.test;
+
+import java.util.TreeMap;
+
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ * Result handler that is used when the result needs to store information
+ * about which parameters have been used by the test.
+ */
+public class UsedParameterAdderResultHandler implements ResultHandler
+{
+ private InternalParameters parameters = null;
+ private ResultHandler resultHandler = null;
+
+ /**
+ * Constructor for a UsedParameterAdderResultHandler.
+ *
+ * @param inResultHandler original result handler
+ * @param inParameters parameters which are mapped to the test. This should also contain information
+ * about which parameters have actually been used
+ */
+ public UsedParameterAdderResultHandler(
+ ResultHandler inResultHandler,
+ InternalParameters inParameters)
+ {
+ resultHandler = inResultHandler;
+ parameters = inParameters;
+ }
+
+ public void submitResult(TestResultBean tr)
+ {
+ if (tr.getParameters() == null || tr.getParameters().isEmpty())
+ {
+ tr.setParameters(new TreeMap(parameters.getUsedParams()));
+ }
+ resultHandler.submitResult(tr);
+ }
+
+ public void submitResult(TestResultBean tr, String resultName)
+ {
+ if (tr.getParameters() == null || tr.getParameters().isEmpty())
+ {
+ tr.setParameters(new TreeMap(parameters.getUsedParams()));
+ }
+ resultHandler.submitResult(tr, resultName);
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/UsedParameterAdderResultHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractRMITestVehicle.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractRMITestVehicle.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractRMITestVehicle.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractRMITestVehicle.java Fri Aug 12 08:12:28 2005
@@ -1,85 +1,85 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.rmi.RemoteException;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
-import org.apache.beehive.test.tools.tch.core.remote.RemoteResultHandlerAdapter;
-import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
-import org.apache.beehive.test.tools.tch.core.test.ResultHandlerAdapter;
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-import org.apache.beehive.test.tools.tch.task.TaskException;
-import org.apache.beehive.test.tools.tch.task.TaskTransportException;
-
-/**
- */
-
-public abstract class AbstractRMITestVehicle extends AbstractTestVehicle
-{
- private Set resultHandlerAddedTasks;
-
- // used to indicate problems in remote test
- private ProblemIndicatorResultHandler problemIndicator;
-
- // used to indicate problems in infra (exceptions)
- private boolean isProblem = false;
- public boolean isProblem(){
- return isProblem|problemIndicator.isProblem();
- }
-
- // uset to report problems (e.g. exceptions)
- protected void isProblem(boolean inProblem){
- isProblem|=inProblem;
- }
-
- public AbstractRMITestVehicle(String inName)
- {
- super(inName);
- resultHandlerAddedTasks = new HashSet();
- }
-
- public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
- throws TaskTransportException, TaskException
- {
- prepareForRun(inTask);
- runTestLogic(inProcessHandler, inTask);
- }
-
- /**
- * Implement this method in the non-abstract Test Vehicle implementation.
- */
- protected abstract void runTestLogic(
- ProcessHandler inProcessHandler,
- TestLogicTask inTask)
- throws TaskTransportException, TaskException;
-
- private final void prepareForRun(TestLogicTask inTask)
-
- {
- try
- {
- // Keep track of tasks which we've already added a remote result handler for
- // so that we don't readd
- if (!resultHandlerAddedTasks.contains(inTask))
- {
- // create problem indicator based on current result handler
- problemIndicator=new ProblemIndicatorResultHandler(inTask.getResultHandler());
-
- // since we are using a test-vehicle, decorate the current result handler
- // with RemoteResultHandlerAdapter.. This enables the test-vehicle to
- // submit results back to the Tch VM
- inTask.setResultHandler(
- new ResultHandlerAdapter(
- new RemoteResultHandlerAdapter(problemIndicator)));
- resultHandlerAddedTasks.add(inTask);
- }
- }
- catch (RemoteException ex)
- {
- // This will not happen since instantiating the Object is not a remote
- // call.
- ex.printStackTrace();
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.rmi.RemoteException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
+import org.apache.beehive.test.tools.tch.core.remote.RemoteResultHandlerAdapter;
+import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
+import org.apache.beehive.test.tools.tch.core.test.ResultHandlerAdapter;
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+import org.apache.beehive.test.tools.tch.task.TaskException;
+import org.apache.beehive.test.tools.tch.task.TaskTransportException;
+
+/**
+ */
+
+public abstract class AbstractRMITestVehicle extends AbstractTestVehicle
+{
+ private Set resultHandlerAddedTasks;
+
+ // used to indicate problems in remote test
+ private ProblemIndicatorResultHandler problemIndicator;
+
+ // used to indicate problems in infra (exceptions)
+ private boolean isProblem = false;
+ public boolean isProblem(){
+ return isProblem|problemIndicator.isProblem();
+ }
+
+ // uset to report problems (e.g. exceptions)
+ protected void isProblem(boolean inProblem){
+ isProblem|=inProblem;
+ }
+
+ public AbstractRMITestVehicle(String inName)
+ {
+ super(inName);
+ resultHandlerAddedTasks = new HashSet();
+ }
+
+ public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
+ throws TaskTransportException, TaskException
+ {
+ prepareForRun(inTask);
+ runTestLogic(inProcessHandler, inTask);
+ }
+
+ /**
+ * Implement this method in the non-abstract Test Vehicle implementation.
+ */
+ protected abstract void runTestLogic(
+ ProcessHandler inProcessHandler,
+ TestLogicTask inTask)
+ throws TaskTransportException, TaskException;
+
+ private final void prepareForRun(TestLogicTask inTask)
+
+ {
+ try
+ {
+ // Keep track of tasks which we've already added a remote result handler for
+ // so that we don't readd
+ if (!resultHandlerAddedTasks.contains(inTask))
+ {
+ // create problem indicator based on current result handler
+ problemIndicator=new ProblemIndicatorResultHandler(inTask.getResultHandler());
+
+ // since we are using a test-vehicle, decorate the current result handler
+ // with RemoteResultHandlerAdapter.. This enables the test-vehicle to
+ // submit results back to the Tch VM
+ inTask.setResultHandler(
+ new ResultHandlerAdapter(
+ new RemoteResultHandlerAdapter(problemIndicator)));
+ resultHandlerAddedTasks.add(inTask);
+ }
+ }
+ catch (RemoteException ex)
+ {
+ // This will not happen since instantiating the Object is not a remote
+ // call.
+ ex.printStackTrace();
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractRMITestVehicle.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractTestVehicle.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractTestVehicle.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractTestVehicle.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractTestVehicle.java Fri Aug 12 08:12:28 2005
@@ -1,44 +1,44 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-
-/**
- */
-
-public abstract class AbstractTestVehicle
- implements TestVehicle
-{
- private String type = null;
-
- public AbstractTestVehicle(String inType)
- {
- type = inType;
- }
-
- /**
- * By default, don't know how to deal with a timeout.
- */
- public void notifyTimeout(TestLogicTask inTask)
- {
- return;
- }
-
- public String getType()
- {
- return type;
- }
-
- public boolean isLocal()
- {
- return false;
- }
-
- public String toString()
- {
- return type;
- }
-}
-
-
-
-
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+
+/**
+ */
+
+public abstract class AbstractTestVehicle
+ implements TestVehicle
+{
+ private String type = null;
+
+ public AbstractTestVehicle(String inType)
+ {
+ type = inType;
+ }
+
+ /**
+ * By default, don't know how to deal with a timeout.
+ */
+ public void notifyTimeout(TestLogicTask inTask)
+ {
+ return;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public boolean isLocal()
+ {
+ return false;
+ }
+
+ public String toString()
+ {
+ return type;
+ }
+}
+
+
+
+
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/AbstractTestVehicle.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/LocalTestVehicle.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/LocalTestVehicle.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/LocalTestVehicle.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/LocalTestVehicle.java Fri Aug 12 08:12:28 2005
@@ -1,66 +1,66 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-import org.apache.beehive.test.tools.tch.task.BasicTaskContext;
-import org.apache.beehive.test.tools.tch.task.Task;
-import org.apache.beehive.test.tools.tch.task.TaskContext;
-import org.apache.beehive.test.tools.tch.task.TaskException;
-import org.apache.beehive.test.tools.tch.task.TaskRunner;
-
-/**
- * This test-vehicle runs the test in-process. This is the default behavior
- * for all any test that does not explicitly specify a test-vehicle.
- *
- */
-public class LocalTestVehicle extends AbstractTestVehicle implements TaskRunner
-{
-
- //Note to self: No state in TestVehicle, as they are shared by all tests!!!
-
- public LocalTestVehicle(String inType)
- {
- super(inType);
- }
-
- // TestVehicle implementation
- // ==========================
-
- /**
- * Main method for launching a test via this test vehicle
- *
- * @param inProcessHandler the process handler representing the test vehicle
- * @param inTask the actual task to run
- */
- public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
- throws TaskException
- {
- // since we are running locally, we don't use inProcessHandler.
- runTask(inTask);
- }
-
- public boolean isLocal()
- {
- return true;
- }
-
- public void notifyTimeout(TestLogicTask inTask)
- {
- //System.out.println("LocalTestVehicle.notifyTimeout()");
- inTask.notifyTimeout();
- }
-
- // TaskRunner implementation
- // =========================
-
- public TaskContext runTask(Task inTask) throws TaskException
- {
- return runTask(inTask, new BasicTaskContext());
- }
-
- public TaskContext runTask(Task inTask, TaskContext inContext)
- throws TaskException
- {
- return inTask.runtask(inContext);
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+import org.apache.beehive.test.tools.tch.task.BasicTaskContext;
+import org.apache.beehive.test.tools.tch.task.Task;
+import org.apache.beehive.test.tools.tch.task.TaskContext;
+import org.apache.beehive.test.tools.tch.task.TaskException;
+import org.apache.beehive.test.tools.tch.task.TaskRunner;
+
+/**
+ * This test-vehicle runs the test in-process. This is the default behavior
+ * for all any test that does not explicitly specify a test-vehicle.
+ *
+ */
+public class LocalTestVehicle extends AbstractTestVehicle implements TaskRunner
+{
+
+ //Note to self: No state in TestVehicle, as they are shared by all tests!!!
+
+ public LocalTestVehicle(String inType)
+ {
+ super(inType);
+ }
+
+ // TestVehicle implementation
+ // ==========================
+
+ /**
+ * Main method for launching a test via this test vehicle
+ *
+ * @param inProcessHandler the process handler representing the test vehicle
+ * @param inTask the actual task to run
+ */
+ public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
+ throws TaskException
+ {
+ // since we are running locally, we don't use inProcessHandler.
+ runTask(inTask);
+ }
+
+ public boolean isLocal()
+ {
+ return true;
+ }
+
+ public void notifyTimeout(TestLogicTask inTask)
+ {
+ //System.out.println("LocalTestVehicle.notifyTimeout()");
+ inTask.notifyTimeout();
+ }
+
+ // TaskRunner implementation
+ // =========================
+
+ public TaskContext runTask(Task inTask) throws TaskException
+ {
+ return runTask(inTask, new BasicTaskContext());
+ }
+
+ public TaskContext runTask(Task inTask, TaskContext inContext)
+ throws TaskException
+ {
+ return inTask.runtask(inContext);
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/LocalTestVehicle.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ProblemIndicatorResultHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ProblemIndicatorResultHandler.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ProblemIndicatorResultHandler.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ProblemIndicatorResultHandler.java Fri Aug 12 08:12:28 2005
@@ -1,52 +1,52 @@
-/*
- * Created on May 24, 2004
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- *
- * Decorator.
- * Indicates wheather a multi-result test had a problem.
- * Used in RemoteListenerTestVehicle to shutdown test-vehicle based on overall test result.
- */
-public final class ProblemIndicatorResultHandler implements ResultHandler
-{
- private ResultHandler resultHandler;
-
- public ProblemIndicatorResultHandler(ResultHandler in)
- {
- resultHandler = in;
- }
-
- private boolean isProblem = false;
- public boolean isProblem()
- {
- return isProblem;
- }
-
- /* (non-Javadoc)
- * @see org.apache.beehive.test.tools.tch.core.test.ResultHandler#submitResult(org.apache.beehive.test.tools.tch.util.TestResultBean)
- */
- public void submitResult(TestResultBean tr)
- {
- isProblem |= tr.isOrContainsProblems();
- resultHandler.submitResult(tr);
-
- }
-
- /* (non-Javadoc)
- * @see org.apache.beehive.test.tools.tch.core.test.ResultHandler#submitResult(org.apache.beehive.test.tools.tch.util.TestResultBean, java.lang.String)
- */
- public void submitResult(TestResultBean tr, String resultName)
- {
- isProblem |= tr.isOrContainsProblems();
- resultHandler.submitResult(tr, resultName);
- }
-
-}
+/*
+ * Created on May 24, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ *
+ * Decorator.
+ * Indicates wheather a multi-result test had a problem.
+ * Used in RemoteListenerTestVehicle to shutdown test-vehicle based on overall test result.
+ */
+public final class ProblemIndicatorResultHandler implements ResultHandler
+{
+ private ResultHandler resultHandler;
+
+ public ProblemIndicatorResultHandler(ResultHandler in)
+ {
+ resultHandler = in;
+ }
+
+ private boolean isProblem = false;
+ public boolean isProblem()
+ {
+ return isProblem;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.beehive.test.tools.tch.core.test.ResultHandler#submitResult(org.apache.beehive.test.tools.tch.util.TestResultBean)
+ */
+ public void submitResult(TestResultBean tr)
+ {
+ isProblem |= tr.isOrContainsProblems();
+ resultHandler.submitResult(tr);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.beehive.test.tools.tch.core.test.ResultHandler#submitResult(org.apache.beehive.test.tools.tch.util.TestResultBean, java.lang.String)
+ */
+ public void submitResult(TestResultBean tr, String resultName)
+ {
+ isProblem |= tr.isOrContainsProblems();
+ resultHandler.submitResult(tr, resultName);
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ProblemIndicatorResultHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ResultXMLLogger.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ResultXMLLogger.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ResultXMLLogger.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ResultXMLLogger.java Fri Aug 12 08:12:28 2005
@@ -1,206 +1,206 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.beehive.test.tools.tch.logger.PrintWriterLoggerAdapter;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.TestResult;
-import org.apache.beehive.test.tools.tch.util.xml.XMLUtil;
-
-public class ResultXMLLogger extends PrintWriterLoggerAdapter
-{
- public static String sep = System.getProperty("line.separator");
-
- private static final String XML_INFO =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
-
- // ============================================================
- // Variables
-
- private boolean debug = false;
- private boolean logAllResults = false;
- private int xmlIndent = 0;
-
- private final static SimpleDateFormat DEFAULT_DATEFORMAT =
- new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
-
- private PrintWriter mWriter;
- private SimpleDateFormat mDateFormat = DEFAULT_DATEFORMAT;
-
- // ============================================================
- // Logger implementation
-
- ResultXMLLogger(PrintWriter in)
- {
- mWriter = in;
- }
-
- public void open()
- {
-
- String mFormattedDate = mDateFormat.format(new Date());
-
- //start writing
- println(XML_INFO);
- println("");
- println(getIndent() + "<" + XMLLogParser.ROOT_ELEMENT);
- xmlIndent += 2;
- String indent = getIndent();
- println(indent + ">");
- println("");
- }
-
- public void close()
- {
- xmlIndent -= 2;
- println(getIndent() + "</" + XMLLogParser.ROOT_ELEMENT + ">");
- flush();
- //mWriter.close();
- }
-
- public void logIndividualRes(TestResult inResult)
- {
- synchronized (mWriter)
- {
- String resultType = inResult.getTypeAsString();
- String subtestName = inResult.getName();
- String time = getTime(inResult);
- String indent = getIndent();
-
- println(indent + "<" + XMLLogParser.TEST_RESULT_ELEMENT);
- if (subtestName != null)
- {
- println(
- indent
- + " "
- + XMLLogParser.SUBTEST_NAME
- + "=\""
- + subtestName
- + "\"");
- }
- println(
- indent + " " + XMLLogParser.RESULT_TYPE + "=\"" + resultType + "\"");
- println(indent + " " + XMLLogParser.TIME + "=\"" + time + "\"");
- println(indent + " >");
-
- xmlIndent += 2;
-
- printMessageElement(inResult);
- printUsedParamElement(inResult);
- printExceptionElement(inResult);
- xmlIndent -= 2;
- println(indent + "</" + XMLLogParser.TEST_RESULT_ELEMENT + ">");
- println("");
- flush();
- }
- }
-
- public void log(List inResults)
- {
- Iterator results = inResults.iterator();
- while (results.hasNext())
- {
- logIndividualRes((TestResult)results.next());
- }
- }
-
- // ============================================================
- // Private methods
-
- private void print(String inMsg)
- {
- mWriter.print(inMsg);
- }
-
- private void println(String inMsg)
- {
- mWriter.println(inMsg);
- }
-
- private void flush()
- {
- mWriter.flush();
- }
-
- private String getIndent()
- {
- StringBuffer indent = new StringBuffer("");
- for (int i = 0; i < xmlIndent; i++)
- indent.append(" ");
- return indent.toString();
- }
-
- private String getTime(TestResult inResult)
- {
- String time = mDateFormat.format(inResult.getTimeStamp());
- return time;
- }
-
- private void printMessageElement(TestResult inResult)
- {
- String message = inResult.getOutputMessage();
- String indent = getIndent();
- if (message != null)
- {
- println(indent + "<" + XMLLogParser.MESSAGE_ELEMENT + ">");
- println(indent + XMLUtil.escape(message));
- println(indent + "</" + XMLLogParser.MESSAGE_ELEMENT + ">");
- }
- }
-
- private void printUsedParamElement(TestResult inResult)
- {
- String indent = getIndent();
- Map parameters = inResult.getParameters();
- if (parameters != null)
- {
- Set entryset = parameters.entrySet();
- Iterator iter = entryset.iterator();
- while (iter.hasNext())
- {
- Map.Entry entry = (Map.Entry)iter.next();
- String paramname = (String)entry.getKey();
- String paramvalue = (String)entry.getValue();
- println(indent + "<" + XMLLogParser.USED_PARAMS + ">");
- println(
- indent
- + "<"
- + XMLLogParser.USED_PARAMNAME
- + ">"
- + paramname
- + "</"
- + XMLLogParser.USED_PARAMNAME
- + ">");
- println(
- indent
- + "<"
- + XMLLogParser.USED_PARAMVALUE
- + ">"
- + paramvalue
- + "</"
- + XMLLogParser.USED_PARAMVALUE
- + ">");
- println(indent + "</" + XMLLogParser.USED_PARAMS + ">");
- }
- }
- }
-
- private void printExceptionElement(TestResult inResult)
- {
- if (inResult.getThrowable() != null)
- {
- String indent = getIndent();
- println(indent + "<" + XMLLogParser.EXCEPTION_ELEMENT + ">");
- String stacktrace =
- TchUtils.throwable2StackTrace(inResult.getThrowable());
- println(XMLUtil.escape(stacktrace));
- println(indent + "</" + XMLLogParser.EXCEPTION_ELEMENT + ">");
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.beehive.test.tools.tch.logger.PrintWriterLoggerAdapter;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.TestResult;
+import org.apache.beehive.test.tools.tch.util.xml.XMLUtil;
+
+public class ResultXMLLogger extends PrintWriterLoggerAdapter
+{
+ public static String sep = System.getProperty("line.separator");
+
+ private static final String XML_INFO =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+
+ // ============================================================
+ // Variables
+
+ private boolean debug = false;
+ private boolean logAllResults = false;
+ private int xmlIndent = 0;
+
+ private final static SimpleDateFormat DEFAULT_DATEFORMAT =
+ new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+
+ private PrintWriter mWriter;
+ private SimpleDateFormat mDateFormat = DEFAULT_DATEFORMAT;
+
+ // ============================================================
+ // Logger implementation
+
+ ResultXMLLogger(PrintWriter in)
+ {
+ mWriter = in;
+ }
+
+ public void open()
+ {
+
+ String mFormattedDate = mDateFormat.format(new Date());
+
+ //start writing
+ println(XML_INFO);
+ println("");
+ println(getIndent() + "<" + XMLLogParser.ROOT_ELEMENT);
+ xmlIndent += 2;
+ String indent = getIndent();
+ println(indent + ">");
+ println("");
+ }
+
+ public void close()
+ {
+ xmlIndent -= 2;
+ println(getIndent() + "</" + XMLLogParser.ROOT_ELEMENT + ">");
+ flush();
+ //mWriter.close();
+ }
+
+ public void logIndividualRes(TestResult inResult)
+ {
+ synchronized (mWriter)
+ {
+ String resultType = inResult.getTypeAsString();
+ String subtestName = inResult.getName();
+ String time = getTime(inResult);
+ String indent = getIndent();
+
+ println(indent + "<" + XMLLogParser.TEST_RESULT_ELEMENT);
+ if (subtestName != null)
+ {
+ println(
+ indent
+ + " "
+ + XMLLogParser.SUBTEST_NAME
+ + "=\""
+ + subtestName
+ + "\"");
+ }
+ println(
+ indent + " " + XMLLogParser.RESULT_TYPE + "=\"" + resultType + "\"");
+ println(indent + " " + XMLLogParser.TIME + "=\"" + time + "\"");
+ println(indent + " >");
+
+ xmlIndent += 2;
+
+ printMessageElement(inResult);
+ printUsedParamElement(inResult);
+ printExceptionElement(inResult);
+ xmlIndent -= 2;
+ println(indent + "</" + XMLLogParser.TEST_RESULT_ELEMENT + ">");
+ println("");
+ flush();
+ }
+ }
+
+ public void log(List inResults)
+ {
+ Iterator results = inResults.iterator();
+ while (results.hasNext())
+ {
+ logIndividualRes((TestResult)results.next());
+ }
+ }
+
+ // ============================================================
+ // Private methods
+
+ private void print(String inMsg)
+ {
+ mWriter.print(inMsg);
+ }
+
+ private void println(String inMsg)
+ {
+ mWriter.println(inMsg);
+ }
+
+ private void flush()
+ {
+ mWriter.flush();
+ }
+
+ private String getIndent()
+ {
+ StringBuffer indent = new StringBuffer("");
+ for (int i = 0; i < xmlIndent; i++)
+ indent.append(" ");
+ return indent.toString();
+ }
+
+ private String getTime(TestResult inResult)
+ {
+ String time = mDateFormat.format(inResult.getTimeStamp());
+ return time;
+ }
+
+ private void printMessageElement(TestResult inResult)
+ {
+ String message = inResult.getOutputMessage();
+ String indent = getIndent();
+ if (message != null)
+ {
+ println(indent + "<" + XMLLogParser.MESSAGE_ELEMENT + ">");
+ println(indent + XMLUtil.escape(message));
+ println(indent + "</" + XMLLogParser.MESSAGE_ELEMENT + ">");
+ }
+ }
+
+ private void printUsedParamElement(TestResult inResult)
+ {
+ String indent = getIndent();
+ Map parameters = inResult.getParameters();
+ if (parameters != null)
+ {
+ Set entryset = parameters.entrySet();
+ Iterator iter = entryset.iterator();
+ while (iter.hasNext())
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ String paramname = (String)entry.getKey();
+ String paramvalue = (String)entry.getValue();
+ println(indent + "<" + XMLLogParser.USED_PARAMS + ">");
+ println(
+ indent
+ + "<"
+ + XMLLogParser.USED_PARAMNAME
+ + ">"
+ + paramname
+ + "</"
+ + XMLLogParser.USED_PARAMNAME
+ + ">");
+ println(
+ indent
+ + "<"
+ + XMLLogParser.USED_PARAMVALUE
+ + ">"
+ + paramvalue
+ + "</"
+ + XMLLogParser.USED_PARAMVALUE
+ + ">");
+ println(indent + "</" + XMLLogParser.USED_PARAMS + ">");
+ }
+ }
+ }
+
+ private void printExceptionElement(TestResult inResult)
+ {
+ if (inResult.getThrowable() != null)
+ {
+ String indent = getIndent();
+ println(indent + "<" + XMLLogParser.EXCEPTION_ELEMENT + ">");
+ String stacktrace =
+ TchUtils.throwable2StackTrace(inResult.getThrowable());
+ println(XMLUtil.escape(stacktrace));
+ println(indent + "</" + XMLLogParser.EXCEPTION_ELEMENT + ">");
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ResultXMLLogger.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ServletTestVehicle.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ServletTestVehicle.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ServletTestVehicle.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ServletTestVehicle.java Fri Aug 12 08:12:28 2005
@@ -1,263 +1,263 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.rmi.registry.LocateRegistry;
-import java.rmi.registry.Registry;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.xml.sax.InputSource;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.PropertyNames;
-import org.apache.beehive.test.tools.tch.core.process.HttpServerHandler;
-import org.apache.beehive.test.tools.tch.core.process.ProcessEngine;
-import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
-import org.apache.beehive.test.tools.tch.core.remote.RemoteProcessEngineWrapperImpl;
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-import org.apache.beehive.test.tools.tch.extension.exectask.javatest.JavatestTestLogicTask;
-import org.apache.beehive.test.tools.tch.extension.process.listener.RemoteListener;
-import org.apache.beehive.test.tools.tch.task.TaskException;
-import org.apache.beehive.test.tools.tch.task.TaskTransportException;
-import org.apache.beehive.test.tools.tch.util.DebugLogger;
-
-/**
- * ServletTestVehicle is the test vehicle class used when a test is run using
- * the Tch servlet test vehicle plugin. This can theoretically be used to
- * run tests in any web container.
- * An instance of this exists on the client-side and facilitates the running
- * of the test on the remote task runner.
- *
- * Only compatible with javatest execution tasks.
- */
-public class ServletTestVehicle extends AbstractTestVehicle
-{
- public final static String JAVATEST_PARAM =
- PropertyNames.TCH_PREFIX + "interactive",
- CLASS_PARAM = PropertyNames.TCH_PREFIX + "class",
- SERVER_SIDE_LOGGING_PARAM =
- PropertyNames.TCH_PREFIX + "log-server-side",
- METHOD_PARAM = PropertyNames.TCH_PREFIX + "method",
- DEBUG_PARAM =
- PropertyNames.TCH_PREFIX + PropertyNames.TCH_DEBUG_PROPERTY,
- PROCESS_ENGINE_BINDNAME = PropertyNames.TCH_PREFIX + "process-engine",
- PROCESS_ENGINE_WRAPPER_LOOKUP_URL_PARAM =
- PropertyNames.TCH_PREFIX + "process-engine-lookup-url",
- sep = System.getProperty("line.separator");
-
- private String processEngineURL = null;
- private RemoteProcessEngineWrapperImpl processEngineWrapper = null;
-
- public ServletTestVehicle(String inName)
- {
- super(inName);
- }
-
- /**
- * Main method for launching a test via this test vehicle
- *
- * @param inProcessHandler the process handler representing the test vehicle
- * @param inTask the actual task to run
- */
- public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
- throws TaskTransportException, TaskException
- {
- HttpServerHandler handler = getHttpServerHandler(inProcessHandler);
- JavatestTestLogicTask testLogic = getJavatestTestLogicTask(inTask);
-
- // need to bind wrapper into rmi registry.
- // FIXME - this won't work correctly is tests that use a different process engine *run in parallel*
- if (testLogic.getProcessEngine() != null)
- {
- getRemoteProcessEngineWrapper().setProcessEngine(
- testLogic.getProcessEngine());
- }
-
- if (!handler.isAlive())
- {
- throw new TaskTransportException(
- "Server "
- + handler.getName()
- + " is not alive to run server-side test (servlet)");
- }
-
- StringBuffer paramString = new StringBuffer();
- paramString
- .append(
- buildCoreParamString(testLogic.getClassName(), testLogic.getMethods()))
- .append(buildExtraParamString(testLogic.getParametersAsMap()));
-
- //System.out.println("PARAMS " + paramString);
-
- HttpURLConnection con = null;
- try
- {
- con = handler.getHttpURLConnection("tchtestrunner/JavatestServlet");
- con.setRequestProperty(
- "Content-Length",
- String.valueOf(paramString.length()));
- con.setDoOutput(true);
- PrintWriter writer = null;
- writer =
- new PrintWriter(
- new BufferedWriter(new OutputStreamWriter(con.getOutputStream())));
- writer.print(paramString);
- writer.flush();
- writer.close();
-
- BufferedReader br = null;
- br = new BufferedReader(new InputStreamReader(con.getInputStream()));
-
- // first read the stuff the servlet is sending in case we want
- // to look at it...
- String line = "";
- StringBuffer servletOutput = new StringBuffer();
- while ((line = br.readLine()) != null)
- {
- servletOutput.append(line).append(sep);
- }
-
- DebugLogger.log("SERVELT OUTPUT\n" + servletOutput.toString());
-
- InputSource is =
- new InputSource(new StringReader(servletOutput.toString()));
- XMLResultFactory fac = new XMLResultFactory(is);
-
- // this logs the results
- fac.XMLToResult(testLogic.getResultHandler());
- }
- catch (Throwable th)
- {
- throw new TaskTransportException(th, "Unable to read servlet response");
- }
- }
-
- private JavatestTestLogicTask getJavatestTestLogicTask(TestLogicTask inTestLogicTask)
- throws TaskTransportException
- {
- try
- {
- return (JavatestTestLogicTask)inTestLogicTask;
- }
- catch (ClassCastException ex)
- {
- throw new TaskTransportException(
- ex,
- "Got instance of "
- + inTestLogicTask.getClass().getName()
- + " instead of "
- + JavatestTestLogicTask.class.getName()
- + " as expected");
- }
- }
-
- private HttpServerHandler getHttpServerHandler(ProcessHandler inProcessHandler)
- throws TaskTransportException
- {
- try
- {
- return (HttpServerHandler)inProcessHandler;
- }
- catch (ClassCastException ex)
- {
- throw new TaskTransportException(
- ex,
- "Process "
- + inProcessHandler.getName()
- + " is not an instance of "
- + HttpServerHandler.class.getName()
- + " as expected");
- }
- }
-
- private String buildCoreParamString(String classname, Collection methods)
- {
- StringBuffer internalParamsSB = new StringBuffer();
- internalParamsSB
- .append(JAVATEST_PARAM)
- .append("=false&")
- .append(CLASS_PARAM)
- .append("=")
- .append(classname)
- .append("&")
- .append(DEBUG_PARAM)
- .append("=")
- .append(AntProperties.isDebugOn())
- .append("&")
- .append(PROCESS_ENGINE_WRAPPER_LOOKUP_URL_PARAM)
- .append("=")
- .append(processEngineURL);
-
- if (methods != null && !methods.isEmpty())
- {
- internalParamsSB.append("&");
- internalParamsSB.append(METHOD_PARAM).append("=");
- for (Iterator iter = methods.iterator(); iter.hasNext();)
- {
- internalParamsSB.append(iter.next());
- if (iter.hasNext())
- {
- internalParamsSB.append(",");
- }
- }
- }
- return internalParamsSB.toString();
- }
-
- private String buildExtraParamString(Map params)
- {
- StringBuffer myParams = new StringBuffer();
- for (Iterator iter = params.entrySet().iterator(); iter.hasNext();)
- {
- myParams.append("&");
- Map.Entry entry = (Map.Entry)iter.next();
- String key = (String)entry.getKey();
- String value = (String)entry.getValue();
- myParams.append(key).append("=").append(value.replace(' ', '+'));
- }
- return myParams.toString();
- }
-
- private synchronized RemoteProcessEngineWrapperImpl getRemoteProcessEngineWrapper()
- throws TaskTransportException
- {
- if (processEngineWrapper == null)
- {
- try
- {
- String host = InetAddress.getLocalHost().getHostName();
- // TODO: FIXME. Ugly listener port usage
- // terrible, this needs to be fixed also, making way to many assumptions
- // what if we don't use a local listener?
- // what if the local listener port has changed?
- // this needs one more layer of abstraction, I don't want to know about the local listener
- // at all at this level
- // also don't want to have to start rmi reg myself here
- int rmiPort = AntProperties.getLocalListenerPort();
-
- // this start the rmi reg
- RemoteListener.main(
- new String[] { RemoteListener.PORT_PARAM, "" + rmiPort });
-
- processEngineWrapper = new RemoteProcessEngineWrapperImpl();
- Registry reg = LocateRegistry.getRegistry(rmiPort);
- reg.rebind(PROCESS_ENGINE_BINDNAME, processEngineWrapper);
- processEngineURL =
- "rmi://" + host + ":" + rmiPort + "/" + PROCESS_ENGINE_BINDNAME;
- }
- catch (Throwable th)
- {
- throw new TaskTransportException(th);
- }
- }
- return processEngineWrapper;
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.xml.sax.InputSource;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.PropertyNames;
+import org.apache.beehive.test.tools.tch.core.process.HttpServerHandler;
+import org.apache.beehive.test.tools.tch.core.process.ProcessEngine;
+import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
+import org.apache.beehive.test.tools.tch.core.remote.RemoteProcessEngineWrapperImpl;
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+import org.apache.beehive.test.tools.tch.extension.exectask.javatest.JavatestTestLogicTask;
+import org.apache.beehive.test.tools.tch.extension.process.listener.RemoteListener;
+import org.apache.beehive.test.tools.tch.task.TaskException;
+import org.apache.beehive.test.tools.tch.task.TaskTransportException;
+import org.apache.beehive.test.tools.tch.util.DebugLogger;
+
+/**
+ * ServletTestVehicle is the test vehicle class used when a test is run using
+ * the Tch servlet test vehicle plugin. This can theoretically be used to
+ * run tests in any web container.
+ * An instance of this exists on the client-side and facilitates the running
+ * of the test on the remote task runner.
+ *
+ * Only compatible with javatest execution tasks.
+ */
+public class ServletTestVehicle extends AbstractTestVehicle
+{
+ public final static String JAVATEST_PARAM =
+ PropertyNames.TCH_PREFIX + "interactive",
+ CLASS_PARAM = PropertyNames.TCH_PREFIX + "class",
+ SERVER_SIDE_LOGGING_PARAM =
+ PropertyNames.TCH_PREFIX + "log-server-side",
+ METHOD_PARAM = PropertyNames.TCH_PREFIX + "method",
+ DEBUG_PARAM =
+ PropertyNames.TCH_PREFIX + PropertyNames.TCH_DEBUG_PROPERTY,
+ PROCESS_ENGINE_BINDNAME = PropertyNames.TCH_PREFIX + "process-engine",
+ PROCESS_ENGINE_WRAPPER_LOOKUP_URL_PARAM =
+ PropertyNames.TCH_PREFIX + "process-engine-lookup-url",
+ sep = System.getProperty("line.separator");
+
+ private String processEngineURL = null;
+ private RemoteProcessEngineWrapperImpl processEngineWrapper = null;
+
+ public ServletTestVehicle(String inName)
+ {
+ super(inName);
+ }
+
+ /**
+ * Main method for launching a test via this test vehicle
+ *
+ * @param inProcessHandler the process handler representing the test vehicle
+ * @param inTask the actual task to run
+ */
+ public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
+ throws TaskTransportException, TaskException
+ {
+ HttpServerHandler handler = getHttpServerHandler(inProcessHandler);
+ JavatestTestLogicTask testLogic = getJavatestTestLogicTask(inTask);
+
+ // need to bind wrapper into rmi registry.
+ // FIXME - this won't work correctly is tests that use a different process engine *run in parallel*
+ if (testLogic.getProcessEngine() != null)
+ {
+ getRemoteProcessEngineWrapper().setProcessEngine(
+ testLogic.getProcessEngine());
+ }
+
+ if (!handler.isAlive())
+ {
+ throw new TaskTransportException(
+ "Server "
+ + handler.getName()
+ + " is not alive to run server-side test (servlet)");
+ }
+
+ StringBuffer paramString = new StringBuffer();
+ paramString
+ .append(
+ buildCoreParamString(testLogic.getClassName(), testLogic.getMethods()))
+ .append(buildExtraParamString(testLogic.getParametersAsMap()));
+
+ //System.out.println("PARAMS " + paramString);
+
+ HttpURLConnection con = null;
+ try
+ {
+ con = handler.getHttpURLConnection("tchtestrunner/JavatestServlet");
+ con.setRequestProperty(
+ "Content-Length",
+ String.valueOf(paramString.length()));
+ con.setDoOutput(true);
+ PrintWriter writer = null;
+ writer =
+ new PrintWriter(
+ new BufferedWriter(new OutputStreamWriter(con.getOutputStream())));
+ writer.print(paramString);
+ writer.flush();
+ writer.close();
+
+ BufferedReader br = null;
+ br = new BufferedReader(new InputStreamReader(con.getInputStream()));
+
+ // first read the stuff the servlet is sending in case we want
+ // to look at it...
+ String line = "";
+ StringBuffer servletOutput = new StringBuffer();
+ while ((line = br.readLine()) != null)
+ {
+ servletOutput.append(line).append(sep);
+ }
+
+ DebugLogger.log("SERVELT OUTPUT\n" + servletOutput.toString());
+
+ InputSource is =
+ new InputSource(new StringReader(servletOutput.toString()));
+ XMLResultFactory fac = new XMLResultFactory(is);
+
+ // this logs the results
+ fac.XMLToResult(testLogic.getResultHandler());
+ }
+ catch (Throwable th)
+ {
+ throw new TaskTransportException(th, "Unable to read servlet response");
+ }
+ }
+
+ private JavatestTestLogicTask getJavatestTestLogicTask(TestLogicTask inTestLogicTask)
+ throws TaskTransportException
+ {
+ try
+ {
+ return (JavatestTestLogicTask)inTestLogicTask;
+ }
+ catch (ClassCastException ex)
+ {
+ throw new TaskTransportException(
+ ex,
+ "Got instance of "
+ + inTestLogicTask.getClass().getName()
+ + " instead of "
+ + JavatestTestLogicTask.class.getName()
+ + " as expected");
+ }
+ }
+
+ private HttpServerHandler getHttpServerHandler(ProcessHandler inProcessHandler)
+ throws TaskTransportException
+ {
+ try
+ {
+ return (HttpServerHandler)inProcessHandler;
+ }
+ catch (ClassCastException ex)
+ {
+ throw new TaskTransportException(
+ ex,
+ "Process "
+ + inProcessHandler.getName()
+ + " is not an instance of "
+ + HttpServerHandler.class.getName()
+ + " as expected");
+ }
+ }
+
+ private String buildCoreParamString(String classname, Collection methods)
+ {
+ StringBuffer internalParamsSB = new StringBuffer();
+ internalParamsSB
+ .append(JAVATEST_PARAM)
+ .append("=false&")
+ .append(CLASS_PARAM)
+ .append("=")
+ .append(classname)
+ .append("&")
+ .append(DEBUG_PARAM)
+ .append("=")
+ .append(AntProperties.isDebugOn())
+ .append("&")
+ .append(PROCESS_ENGINE_WRAPPER_LOOKUP_URL_PARAM)
+ .append("=")
+ .append(processEngineURL);
+
+ if (methods != null && !methods.isEmpty())
+ {
+ internalParamsSB.append("&");
+ internalParamsSB.append(METHOD_PARAM).append("=");
+ for (Iterator iter = methods.iterator(); iter.hasNext();)
+ {
+ internalParamsSB.append(iter.next());
+ if (iter.hasNext())
+ {
+ internalParamsSB.append(",");
+ }
+ }
+ }
+ return internalParamsSB.toString();
+ }
+
+ private String buildExtraParamString(Map params)
+ {
+ StringBuffer myParams = new StringBuffer();
+ for (Iterator iter = params.entrySet().iterator(); iter.hasNext();)
+ {
+ myParams.append("&");
+ Map.Entry entry = (Map.Entry)iter.next();
+ String key = (String)entry.getKey();
+ String value = (String)entry.getValue();
+ myParams.append(key).append("=").append(value.replace(' ', '+'));
+ }
+ return myParams.toString();
+ }
+
+ private synchronized RemoteProcessEngineWrapperImpl getRemoteProcessEngineWrapper()
+ throws TaskTransportException
+ {
+ if (processEngineWrapper == null)
+ {
+ try
+ {
+ String host = InetAddress.getLocalHost().getHostName();
+ // TODO: FIXME. Ugly listener port usage
+ // terrible, this needs to be fixed also, making way to many assumptions
+ // what if we don't use a local listener?
+ // what if the local listener port has changed?
+ // this needs one more layer of abstraction, I don't want to know about the local listener
+ // at all at this level
+ // also don't want to have to start rmi reg myself here
+ int rmiPort = AntProperties.getLocalListenerPort();
+
+ // this start the rmi reg
+ RemoteListener.main(
+ new String[] { RemoteListener.PORT_PARAM, "" + rmiPort });
+
+ processEngineWrapper = new RemoteProcessEngineWrapperImpl();
+ Registry reg = LocateRegistry.getRegistry(rmiPort);
+ reg.rebind(PROCESS_ENGINE_BINDNAME, processEngineWrapper);
+ processEngineURL =
+ "rmi://" + host + ":" + rmiPort + "/" + PROCESS_ENGINE_BINDNAME;
+ }
+ catch (Throwable th)
+ {
+ throw new TaskTransportException(th);
+ }
+ }
+ return processEngineWrapper;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/ServletTestVehicle.java
------------------------------------------------------------------------------
svn:eol-style = native