Author: sebb
Date: Mon Nov 12 18:52:45 2007
New Revision: 594402
URL: http://svn.apache.org/viewvc?rev=594402&view=rev
Log:
Move most Avalon processing to OldSaveService
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultCollector.java
jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/OldSaveService.java
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultCollector.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultCollector.java?rev=594402&r1=594401&r2=594402&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultCollector.java
(original)
+++
jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultCollector.java
Mon Nov 12 18:52:45 2007
@@ -21,7 +21,6 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -39,9 +38,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import
org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.engine.util.NoThreadClone;
@@ -60,18 +56,21 @@
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.testelement.property.BooleanProperty;
import org.apache.jmeter.testelement.property.ObjectProperty;
+import org.apache.jmeter.visualizers.Visualizer;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JMeterError;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
-import org.xml.sax.SAXException;
public class ResultCollector extends AbstractListenerElement implements
SampleListener, Clearable, Serializable,
TestListener, Remoteable, NoThreadClone {
private static final Logger log = LoggingManager.getLoggerForClass();
- private static final long serialVersionUID = 23;
+ private static final long serialVersionUID = 231L;
+
+ // This string is used to identify local test runs, so must not be a
valid host name
+ private static final String TEST_IS_LOCAL = "*local*"; // $NON-NLS-1$
private static final String TESTRESULTS_START = "<testResults>"; //
$NON-NLS-1$
@@ -91,11 +90,8 @@
private static final String ERROR_LOGGING =
"ResultCollector.error_logging"; // $NON-NLS-1$
- // protected List results = Collections.synchronizedList(new
ArrayList());
- // private int current;
transient private DefaultConfigurationSerializer serializer;
- // private boolean inLoading = false;
transient private volatile PrintWriter out;
private boolean inTest = false;
@@ -174,11 +170,11 @@
}
public void testEnded() {
- testEnded("local"); // $NON-NLS-1$
+ testEnded(TEST_IS_LOCAL);
}
public void testStarted() {
- testStarted("local"); // $NON-NLS-1$
+ testStarted(TEST_IS_LOCAL);
}
/**
@@ -190,6 +186,10 @@
*
*/
public void loadExistingFile() {
+ final Visualizer visualizer = getVisualizer();
+ if (visualizer == null) {
+ return; // No point reading the file if there's no
visualiser
+ }
boolean parsedOK = false, errorDetected = false;
String filename = getFilename();
File file = new File(filename);
@@ -208,14 +208,16 @@
long lineNumber=1;
SampleSaveConfiguration saveConfig =
CSVSaveService.getSampleSaveConfiguration(line,filename);
if (saveConfig == null) {// not a valid header
- saveConfig = (SampleSaveConfiguration)
getSaveConfig().clone(); // OldSaveService may change the format
+ saveConfig = (SampleSaveConfiguration)
getSaveConfig().clone(); // CSVSaveService may change the format
} else { // header line has been processed, so read the
next
line = dataReader.readLine();
lineNumber++;
}
while (line != null) { // Already read 1st line
SampleEvent event =
CSVSaveService.makeResultFromDelimitedString(line,saveConfig,lineNumber);
- if (event != null) sendToVisualizer(event);
+ if (event != null){
+ visualizer.add(event.getResult());
+ }
line = dataReader.readLine();
lineNumber++;
}
@@ -223,17 +225,12 @@
} else { // We are processing XML
try { // Assume XStream
bufferedInputStream = new BufferedInputStream(new
FileInputStream(file));
-
readSamples(SaveService.loadTestResults(bufferedInputStream));
+
readSamples(SaveService.loadTestResults(bufferedInputStream), visualizer);
parsedOK = true;
} catch (Exception e) {
log.info("Failed to load "+filename+" using
XStream, trying old XML format. Error was: "+e);
try {
- Configuration savedSamples =
getConfiguration(filename);
- Configuration[] samples =
savedSamples.getChildren();
- for (int i = 0; i < samples.length; i++) {
- SampleResult result =
OldSaveService.getSampleResult(samples[i]);
- sendToVisualizer(result);
- }
+ OldSaveService.processSamples(filename,
visualizer);
parsedOK = true;
} catch (Exception e1) {
log.warn("Error parsing Avalon XML. " +
e1.getLocalizedMessage());
@@ -361,26 +358,16 @@
return true;
}
- private void readSamples(TestResultWrapper testResults) throws
Exception {
+ // Only called if visualizer is non-null
+ private void readSamples(TestResultWrapper testResults, Visualizer
visualizer) throws Exception {
Collection samples = testResults.getSampleResults();
Iterator iter = samples.iterator();
while (iter.hasNext()) {
SampleResult result = (SampleResult) iter.next();
- sendToVisualizer(result);
+ visualizer.add(result);
}
}
- /**
- * Gets the configuration attribute of the ResultCollector object.
- *
- * @return the configuration value
- */
- private Configuration getConfiguration(String filename) throws
SAXException, IOException, ConfigurationException {
- DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
-
- return builder.buildFromFile(filename);
- }
-
public void clearVisualizer() {
// current = -1;
if (getVisualizer() != null && getVisualizer() instanceof
Clearable) {
@@ -423,54 +410,25 @@
}
}
- protected void sendToVisualizer(SampleResult r) {
+ protected final void sendToVisualizer(SampleResult r) {
if (getVisualizer() != null) {
getVisualizer().add(r);
}
}
- private void sendToVisualizer(SampleEvent e) {
- if (getVisualizer() != null) {
- getVisualizer().add(e.getResult());
- }
- }
-
// Only called if out != null
private void recordResult(SampleEvent event) throws Exception {
SampleResult result = event.getResult();
if (!isResultMarked(result) && !this.isStats) {
if (SaveService.isSaveTestLogFormat20()) {
- if (serializer == null)
+ if (serializer == null) {
serializer = new
DefaultConfigurationSerializer();
- out.write(getSerializedSampleResult(result));
+ }
+
out.write(OldSaveService.getSerializedSampleResult(result, serializer,
getSaveConfig()));
} else {
SaveService.saveSampleResult(event, out);
}
}
- }
-
- private String getSerializedSampleResult(SampleResult result) throws
SAXException, IOException,
- ConfigurationException {
- ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
-
- serializer.serialize(tempOut,
OldSaveService.getConfiguration(result, getSaveConfig()));
- String serVer = tempOut.toString();
- String lineSep=System.getProperty("line.separator"); // $NON-NLS-1$
- /*
- * Remove the <?xml ... ?> prefix.
- * When using the x-jars (xakan etc) or Java 1.4, the serialised
output has a
- * newline after the prefix. However, when using Java 1.5 without the
x-jars, the output
- * has no newline at all.
- */
- int index = serVer.indexOf(lineSep); // Is there a new-line?
- if (index > -1) {// Yes, assume it follows the prefix
- return serVer.substring(index);
- }
- if (serVer.startsWith("<?xml")){ // $NON-NLS-1$
- index=serVer.indexOf("?>");// must exist // $NON-NLS-1$
- return lineSep + serVer.substring(index+2);// +2 for ?>
- }
- return serVer;
}
/**
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/OldSaveService.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/OldSaveService.java?rev=594402&r1=594401&r2=594402&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/OldSaveService.java
(original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/save/OldSaveService.java
Mon Nov 12 18:52:45 2007
@@ -18,6 +18,7 @@
package org.apache.jmeter.save;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -44,6 +45,7 @@
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jmeter.testelement.property.TestElementProperty;
import org.apache.jmeter.util.NameUpdater;
+import org.apache.jmeter.visualizers.Visualizer;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.ListedHashTree;
import org.apache.jorphan.logging.LoggingManager;
@@ -467,5 +469,45 @@
}
}
return subTree;
+ }
+
+ // Called by ResultCollector#loadExistingFile()
+ public static void processSamples(String filename, Visualizer
visualizer)
+ throws SAXException, IOException, ConfigurationException
+ {
+ DefaultConfigurationBuilder cfgbuilder = new
DefaultConfigurationBuilder();
+ Configuration savedSamples = cfgbuilder.buildFromFile(filename);
+ Configuration[] samples = savedSamples.getChildren();
+ for (int i = 0; i < samples.length; i++) {
+ SampleResult result =
OldSaveService.getSampleResult(samples[i]);
+ visualizer.add(result);
+ }
+ }
+
+ // Called by ResultCollector#recordResult()
+ public static String getSerializedSampleResult(
+ SampleResult result, DefaultConfigurationSerializer
slzr, SampleSaveConfiguration cfg)
+ throws SAXException, IOException,
+ ConfigurationException {
+ ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
+
+ slzr.serialize(tempOut, OldSaveService.getConfiguration(result,
cfg));
+ String serVer = tempOut.toString();
+ String lineSep=System.getProperty("line.separator"); // $NON-NLS-1$
+ /*
+ * Remove the <?xml ... ?> prefix.
+ * When using the x-jars (xakan etc) or Java 1.4, the serialised
output has a
+ * newline after the prefix. However, when using Java 1.5 without the
x-jars, the output
+ * has no newline at all.
+ */
+ int index = serVer.indexOf(lineSep); // Is there a new-line?
+ if (index > -1) {// Yes, assume it follows the prefix
+ return serVer.substring(index);
+ }
+ if (serVer.startsWith("<?xml")){ // $NON-NLS-1$
+ index=serVer.indexOf("?>");// must exist // $NON-NLS-1$
+ return lineSep + serVer.substring(index+2);// +2 for ?>
+ }
+ return serVer;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]