kcassell 2003/02/05 11:45:31
Modified: src/core/org/apache/jmeter/save SaveServiceConstants.java
SaveService.java
Log:
Added CSV support.
Revision Changes Path
1.3 +25 -3
jakarta-jmeter/src/core/org/apache/jmeter/save/SaveServiceConstants.java
Index: SaveServiceConstants.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/save/SaveServiceConstants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SaveServiceConstants.java 4 Feb 2003 21:02:13 -0000 1.2
+++ SaveServiceConstants.java 5 Feb 2003 19:45:31 -0000 1.3
@@ -110,6 +110,28 @@
public static final String ASSERTION_RESULTS_PROP
= "jmeter.save.saveservice.assertion_results";
+ /** The name of the property indicating which delimiter should be
+ used when saving in a delimited values format. **/
+ public static final String DEFAULT_DELIMITER_PROP
+ = "jmeter.save.saveservice.default_delimiter";
+
+ /** The name of the property indicating which format should be
+ used when saving the results, e.g., xml or csv. **/
+ public static final String OUTPUT_FORMAT_PROP
+ = "jmeter.save.saveservice.output_format";
+
+ /** The name of the property indicating whether field names should be
+ printed to a delimited file. **/
+ public static final String PRINT_FIELD_NAMES_PROP
+ = "jmeter.save.saveservice.print_field_names";
+
+ /** Indicates that results should be saved as XML. **/
+ public static final int SAVE_AS_XML = 0;
+
+ /** Indicates that results should be saved as comma-separated-values. **/
+ public static final int SAVE_AS_CSV = SAVE_AS_XML + 1;
+
+
/** The name of the property indicating whether the data type
should be saved. **/
public static final String SAVE_DATA_TYPE_PROP
@@ -156,7 +178,7 @@
= "jmeter.save.saveservice.timestamp_format";
// ---------------------------------------------------------------------
- // XML RESULT FILE CONSTANTS
+ // XML RESULT FILE CONSTANTS AND FIELD NAME CONSTANTS
// ---------------------------------------------------------------------
public final static String PRESERVE = "preserve";
1.14 +246 -11 jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java
Index: SaveService.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SaveService.java 5 Feb 2003 05:12:09 -0000 1.13
+++ SaveService.java 5 Feb 2003 19:45:31 -0000 1.14
@@ -2,7 +2,7 @@
* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -94,6 +94,7 @@
* storage mechanisms may also be used, for instance, CSV
* files or databases.
*
+ *@author Mike Stover
*@author <a href="mailto:kcassell@apache.org">Keith Cassell</a>
*@created $Date$
*@version $Revision$ $Date$
@@ -111,6 +112,13 @@
/** A formatter for the time stamp. **/
protected static SimpleDateFormat formatter = null;
+ /** A flag to indicate which output format to use for results. **/
+ protected static int outputFormat = SAVE_AS_XML;
+
+ /** A flag to indicate whether to print the field names for delimited
+ result files. **/
+ protected static boolean printFieldNames = false;
+
/** A flag to indicate whether the data type should
be saved to the test results. **/
protected static boolean saveDataType = true;
@@ -158,18 +166,30 @@
protected static int assertionsResultsToSave = SAVE_NO_ASSERTIONS;
+ /** The string used to separate fields when stored to disk, for example,
+ the comma for CSV files. **/
+ protected static String defaultDelimiter = ",";
+
+
private static DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
+
// Initialize various variables based on properties.
static
{
- readAndSetSaveProperties();
+ readProperties();
} // static initialization
+
public SaveService()
{}
- protected static void readAndSetSaveProperties()
+
+ /**
+ Read in the properties having to do with saving from a properties file.
+ **/
+
+ protected static void readProperties()
{
Properties systemProps = System.getProperties();
Properties props = new Properties(systemProps);
@@ -180,15 +200,17 @@
}
catch (Exception e)
{
- log.error("SaveService.readAndSetSaveProperties: Problem loading
properties file " + PROPS_FILE, e);
+ log.error("SaveService.readProperties: Problem loading properties file
" + PROPS_FILE, e);
}
+ printFieldNames =
+ TRUE.equalsIgnoreCase(props.getProperty(PRINT_FIELD_NAMES_PROP,
+ FALSE));
saveDataType =
TRUE.equalsIgnoreCase(props.getProperty(SAVE_DATA_TYPE_PROP,
TRUE));
saveLabel =
- TRUE.equalsIgnoreCase(props.getProperty(SAVE_LABEL_PROP,
- TRUE));
+ TRUE.equalsIgnoreCase(props.getProperty(SAVE_LABEL_PROP, TRUE));
saveResponseCode =
TRUE.equalsIgnoreCase(props.getProperty(SAVE_RESPONSE_CODE_PROP,
TRUE));
@@ -205,12 +227,12 @@
TRUE.equalsIgnoreCase(props.getProperty(SAVE_THREAD_NAME_PROP,
TRUE));
saveTime =
- TRUE.equalsIgnoreCase(props.getProperty(SAVE_TIME_PROP,
- TRUE));
+ TRUE.equalsIgnoreCase(props.getProperty(SAVE_TIME_PROP, TRUE));
timeStampFormat =
props.getProperty(TIME_STAMP_FORMAT_PROP, MILLISECONDS);
printMilliseconds = MILLISECONDS.equalsIgnoreCase(timeStampFormat);
- //
+
+ // Prepare for a pretty date
if (!printMilliseconds && !NONE.equalsIgnoreCase(timeStampFormat)
&& (timeStampFormat != null))
{
@@ -232,8 +254,122 @@
{
assertionsResultsToSave = SAVE_ALL_ASSERTIONS;
}
+
+ String howToSave = props.getProperty(OUTPUT_FORMAT_PROP, XML);
+
+ if (CSV.equals(howToSave))
+ {
+ outputFormat = SAVE_AS_CSV;
+ }
+ else
+ {
+ outputFormat = SAVE_AS_XML;
+ }
+
+
+ defaultDelimiter = props.getProperty(DEFAULT_DELIMITER_PROP, ",");
+ }
+
+
+ /**
+ Return the format for the saved results, e.g., csv or xml.
+ @return the format for the saved results
+ **/
+
+ public static int getOutputFormat()
+ {
+ return outputFormat;
+ }
+
+
+ /**
+ Return whether the field names should be printed to a delimited
+ results file
+ @return whether the field names should be printed
+ **/
+
+ public static boolean getPrintFieldNames()
+ {
+ return printFieldNames;
+ }
+
+
+ /**
+ Return whether the field names should be printed to the output file
+ @return whether the field names should be printed to the output file
+ **/
+
+ public static String printableFieldNamesToString()
+ {
+ StringBuffer text = new StringBuffer();
+
+ if (printMilliseconds || (formatter != null))
+ {
+ text.append(SaveServiceConstants.TIME_STAMP);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveTime)
+ {
+ text.append(SaveServiceConstants.TIME);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveLabel)
+ {
+ text.append(SaveServiceConstants.LABEL);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveResponseCode)
+ {
+ text.append(SaveServiceConstants.RESPONSE_CODE);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveResponseMessage)
+ {
+ text.append(SaveServiceConstants.RESPONSE_MESSAGE);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveThreadName)
+ {
+ text.append(SaveServiceConstants.THREAD_NAME);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveDataType)
+ {
+ text.append(SaveServiceConstants.DATA_TYPE);
+ text.append(defaultDelimiter);
+ }
+
+ if (saveSuccessful)
+ {
+ text.append(SaveServiceConstants.SUCCESSFUL);
+ text.append(defaultDelimiter);
+ }
+ // text.append(sample.getSamplerData().toString());
+ // text.append(getAssertionResult(sample));
+
+ String resultString = null;
+ int size = text.length();
+ int delSize = defaultDelimiter.length();
+
+ // Strip off the trailing delimiter
+ if (size >= delSize)
+ {
+ resultString = text.substring(0, size - delSize);
+ }
+ else
+ {
+ resultString = text.toString();
+ }
+ return resultString;
}
+
public static void saveSubTree(HashTree subTree, OutputStream writer) throws
IOException
{
@@ -454,6 +590,105 @@
}
return config;
}
+
+
+ /**
+ Convert a result into a string, where the fields of the result are
+ separated by the default delimiter.
+ @param sample the test result to be converted
+ @return the separated value representation of the result
+ **/
+
+ public static String resultToDelimitedString(SampleResult sample)
+ {
+ return resultToDelimitedString(sample, defaultDelimiter);
+ }
+
+
+ /**
+ Convert a result into a string, where the fields of the result are
+ separated by a specified String.
+ @param sample the test result to be converted
+ @param delimiter the separation string
+ @return the separated value representation of the result
+ **/
+
+ public static String resultToDelimitedString(SampleResult sample,
+ String delimiter)
+ {
+ StringBuffer text = new StringBuffer();
+
+ if (printMilliseconds)
+ {
+ text.append("" + sample.getTimeStamp());
+ text.append(delimiter);
+ }
+ else if (formatter != null)
+ {
+ String stamp = formatter.format(new Date(sample.getTimeStamp()));
+ text.append(stamp);
+ }
+
+ if (saveTime)
+ {
+ text.append("" + sample.getTime());
+ text.append(delimiter);
+ }
+
+ if (saveLabel)
+ {
+ text.append(sample.getSampleLabel());
+ text.append(delimiter);
+ }
+
+ if (saveResponseCode)
+ {
+ text.append(sample.getResponseCode());
+ text.append(delimiter);
+ }
+
+ if (saveResponseMessage)
+ {
+ text.append(sample.getResponseMessage());
+ text.append(delimiter);
+ }
+
+ if (saveThreadName)
+ {
+ text.append(sample.getThreadName());
+ text.append(delimiter);
+ }
+
+ if (saveDataType)
+ {
+ text.append(sample.getDataType());
+ text.append(delimiter);
+ }
+
+ if (saveSuccessful)
+ {
+ text.append("" + sample.isSuccessful());
+ text.append(delimiter);
+ }
+ // text.append(sample.getSamplerData().toString());
+ // text.append(getAssertionResult(sample));
+
+ String resultString = null;
+ int size = text.length();
+ int delSize = delimiter.length();
+
+ // Strip off the trailing delimiter
+ if (size >= delSize)
+ {
+ resultString = text.substring(0, size - delSize);
+ }
+ else
+ {
+ resultString = text.toString();
+ }
+ return resultString;
+ }
+
public static Configuration getConfigForTestElement(String named, TestElement
item)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]