sebb        2005/03/22 17:16:32

  Modified:    src/core/org/apache/jmeter/save OldSaveService.java
                        SaveServiceConstants.java
               src/core/org/apache/jmeter/samplers
                        SampleSaveConfiguration.java
               src/core/org/apache/jmeter/reporters ResultCollector.java
  Log:
  Move save configuration setup to SampleSaveConfiguration
  
  Revision  Changes    Path
  1.4       +71 -264   
jakarta-jmeter/src/core/org/apache/jmeter/save/OldSaveService.java
  
  Index: OldSaveService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/save/OldSaveService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OldSaveService.java       20 Sep 2004 23:08:40 -0000      1.3
  +++ OldSaveService.java       23 Mar 2005 01:16:32 -0000      1.4
  @@ -23,14 +23,12 @@
   import java.io.OutputStream;
   import java.io.UnsupportedEncodingException;
   import java.text.ParseException;
  -import java.text.SimpleDateFormat;
   import java.util.Collection;
   import java.util.Date;
   import java.util.Iterator;
   import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
  -import java.util.Properties;
   import java.util.StringTokenizer;
   
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -47,7 +45,6 @@
   import org.apache.jmeter.testelement.property.MapProperty;
   import org.apache.jmeter.testelement.property.StringProperty;
   import org.apache.jmeter.testelement.property.TestElementProperty;
  -import org.apache.jmeter.util.JMeterUtils;
   import org.apache.jmeter.util.NameUpdater;
   import org.apache.jorphan.collections.HashTree;
   import org.apache.jorphan.collections.ListedHashTree;
  @@ -67,82 +64,12 @@
   {
       transient private static final Logger log = 
LoggingManager.getLoggerForClass();
   
  -    private static final int SAVE_NO_ASSERTIONS = 0;
  -    private static final int SAVE_FIRST_ASSERTION = SAVE_NO_ASSERTIONS + 1;
  -    private static final int SAVE_ALL_ASSERTIONS = SAVE_FIRST_ASSERTION + 1;
  -
  -    /** A formatter for the time stamp. */
  -    private static SimpleDateFormat formatter = null;
  -
  -    /** A flag to indicate which output format to use for results. */
  -    private static int outputFormat = SAVE_AS_XML;
  -
  -    /** A flag to indicate whether to print the field names for delimited
  -        result files. */
  -    private static boolean printFieldNames = false;
  -
  -    /** A flag to indicate whether the data type should
  -        be saved to the test results. */
  -    private static boolean saveDataType = true;
  -
  -    /** A flag to indicate whether the assertion result's failure message
  -        should be saved to the test results. */
  -    private static boolean saveAssertionResultsFailureMessage = false;
  -
  -    /** A flag to indicate whether the label should be saved to the test
  -        results. */
  -    private static boolean saveLabel = true;
  -
  -    /** A flag to indicate whether the response code should be saved to the
  -        test results. */
  -    private static boolean saveResponseCode = false;
  -
  -    /** A flag to indicate whether the response data should be saved to the
  -        test results. */
  -    private static boolean saveResponseData = false;
  -
  -    /** A flag to indicate whether the response message should be saved to 
the
  -        test results. */
  -    private static boolean saveResponseMessage = false;
  -
  -    /** A flag to indicate whether the success indicator should be saved to 
the
  -        test results. */
  -    private static boolean saveSuccessful = true;
  -
  -    /** A flag to indicate whether the thread name should be saved to the 
test
  -        results. */
  -    private static boolean saveThreadName = true;
  -
  -    /** A flag to indicate whether the time should be saved to the test
  -        results. */
  -    private static boolean saveTime = true;
  -
  -    /** A flag to indicate the format of the time stamp within the test
  -        results. */
  -    private static String timeStampFormat = MILLISECONDS;
  -
  -    /** A flag to indicate whether the time stamp should be printed in
  -        milliseconds. */
  -    private static boolean printMilliseconds = true;
  -
  -    /** A flag to indicate which assertion results should be saved to the 
test
  -        results.  Legitimate values include none, first, all. */
  -    private static String whichAssertionResults = FIRST;
  -
  -    private static int assertionsResultsToSave = SAVE_NO_ASSERTIONS;
  -
  -    /** The string used to separate fields when stored to disk, for example,
  -        the comma for CSV files. */
  -    private static String defaultDelimiter = ",";
  -
  +     // Initial config from properties
  +     static private final SampleSaveConfiguration _saveConfig = 
SampleSaveConfiguration.staticConfig();
  +     
       private static DefaultConfigurationBuilder builder =
           new DefaultConfigurationBuilder();
   
  -    // Initialize various variables based on properties.
  -    static {
  -        readProperties();
  -    } // static initialization
  -
       /**
        * Private constructor to prevent instantiation.
        */
  @@ -151,125 +78,6 @@
       }
   
       /**
  -     * Read in the properties having to do with saving from a properties 
file.
  -     */
  -    private static void readProperties()
  -    {
  -        Properties systemProps = System.getProperties();
  -        Properties props = new Properties(systemProps);
  -
  -        try
  -        {
  -            props = JMeterUtils.getJMeterProperties();
  -        }
  -        catch (Exception e)
  -        {
  -            log.error(
  -                "SaveService.readProperties: Problem loading properties 
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));
  -
  -        saveResponseCode =
  -            TRUE.equalsIgnoreCase(
  -                props.getProperty(SAVE_RESPONSE_CODE_PROP, TRUE));
  -
  -        saveResponseData =
  -            TRUE.equalsIgnoreCase(
  -                props.getProperty(SAVE_RESPONSE_DATA_PROP, FALSE));
  -
  -        saveResponseMessage =
  -            TRUE.equalsIgnoreCase(
  -                props.getProperty(SAVE_RESPONSE_MESSAGE_PROP, TRUE));
  -
  -        saveSuccessful =
  -            TRUE.equalsIgnoreCase(
  -                props.getProperty(SAVE_SUCCESSFUL_PROP, TRUE));
  -
  -        saveThreadName =
  -            TRUE.equalsIgnoreCase(
  -                props.getProperty(SAVE_THREAD_NAME_PROP, TRUE));
  -
  -        saveTime =
  -            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))
  -        {
  -            formatter = new SimpleDateFormat(timeStampFormat);
  -        }
  -
  -        whichAssertionResults = props.getProperty(ASSERTION_RESULTS_PROP, 
NONE);
  -        saveAssertionResultsFailureMessage =
  -            TRUE.equalsIgnoreCase(
  -                props.getProperty(
  -                    ASSERTION_RESULTS_FAILURE_MESSAGE_PROP,
  -                    FALSE));
  -
  -        if (NONE.equals(whichAssertionResults))
  -        {
  -            assertionsResultsToSave = SAVE_NO_ASSERTIONS;
  -        }
  -        else if (FIRST.equals(whichAssertionResults))
  -        {
  -            assertionsResultsToSave = SAVE_FIRST_ASSERTION;
  -        }
  -        else if (ALL.equals(whichAssertionResults))
  -        {
  -            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;
  -    }
  -    
  -    /**
        * Make a SampleResult given a delimited string.
        * @param delim
        * @return
  @@ -280,23 +88,23 @@
           SampleResult result = null;
           long timeStamp = 0;
           long elapsed = 0;
  -        StringTokenizer splitter = new 
StringTokenizer(delim,defaultDelimiter);
  +        StringTokenizer splitter = new 
StringTokenizer(delim,_saveConfig.getDelimiter());
           String text = null;
           
           try {
  -                             if (printMilliseconds)
  +                             if (_saveConfig.printMilliseconds())
                                {
                                    text = splitter.nextToken();
                                    timeStamp = Long.parseLong(text);
                                }
  -                        else if (formatter != null)
  +                        else if (_saveConfig.formatter() != null)
                           {
                                text = splitter.nextToken();
  -                             Date stamp = formatter.parse(text);
  +                             Date stamp = 
_saveConfig.formatter().parse(text);
                                        timeStamp = stamp.getTime();
                           }
                        
  -                        if (saveTime)
  +                        if (_saveConfig.saveTime())
                           {
                               text = splitter.nextToken();
                               elapsed = Long.parseLong(text);
  @@ -304,42 +112,42 @@
                        
                           result = new SampleResult(timeStamp,elapsed);
                           
  -                        if (saveLabel)
  +                        if (_saveConfig.saveLabel())
                           {
                               text = splitter.nextToken();
                               result.setSampleLabel(text);  
                           }
  -                        if (saveResponseCode)
  +                        if (_saveConfig.saveCode())
                           {
                               text = splitter.nextToken();
                               result.setResponseCode(text);
                           }
                        
  -                        if (saveResponseMessage)
  +                        if (_saveConfig.saveMessage())
                           {
                               text = splitter.nextToken();
                               result.setResponseMessage(text);
                           }
                        
  -                        if (saveThreadName)
  +                        if (_saveConfig.saveThreadName())
                           {
                               text = splitter.nextToken();
                               result.setThreadName(text);
                           }
                        
  -                        if (saveDataType)
  +                        if (_saveConfig.saveDataType())
                           {
                               text = splitter.nextToken();
                               result.setDataType(text);
                           }
                        
  -                        if (saveSuccessful)
  +                        if (_saveConfig.saveSuccess())
                           {
                               text = splitter.nextToken();
                               
result.setSuccessful(Boolean.valueOf(text).booleanValue());
                           }
                        
  -                        if (saveAssertionResultsFailureMessage)
  +                        if (_saveConfig.saveAssertionResultsFailureMessage())
                           {
                               text = splitter.nextToken();
                           }
  @@ -361,63 +169,63 @@
       {
           StringBuffer text = new StringBuffer();
   
  -        if (printMilliseconds || (formatter != null))
  +        if (_saveConfig.printMilliseconds() || (_saveConfig.formatter() != 
null))
           {
               text.append(SaveServiceConstants.TIME_STAMP);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveTime)
  +        if (_saveConfig.saveTime())
           {
               text.append(SaveServiceConstants.TIME);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveLabel)
  +        if (_saveConfig.saveLabel())
           {
               text.append(SaveServiceConstants.LABEL);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveResponseCode)
  +        if (_saveConfig.saveCode())
           {
               text.append(SaveServiceConstants.RESPONSE_CODE);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveResponseMessage)
  +        if (_saveConfig.saveMessage())
           {
               text.append(SaveServiceConstants.RESPONSE_MESSAGE);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveThreadName)
  +        if (_saveConfig.saveThreadName())
           {
               text.append(SaveServiceConstants.THREAD_NAME);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveDataType)
  +        if (_saveConfig.saveDataType())
           {
               text.append(SaveServiceConstants.DATA_TYPE);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveSuccessful)
  +        if (_saveConfig.saveSuccess())
           {
               text.append(SaveServiceConstants.SUCCESSFUL);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
  -        if (saveAssertionResultsFailureMessage)
  +        if (_saveConfig.saveAssertionResultsFailureMessage())
           {
               text.append(SaveServiceConstants.FAILURE_MESSAGE);
  -            text.append(defaultDelimiter);
  +            text.append(_saveConfig.getDelimiter());
           }
   
           String resultString = null;
           int size = text.length();
  -        int delSize = defaultDelimiter.length();
  +        int delSize = _saveConfig.getDelimiter().length();
   
           // Strip off the trailing delimiter
           if (size >= delSize)
  @@ -584,43 +392,43 @@
                   SAMPLE_RESULT_TAG_NAME,
                   "JMeter Save Service");
   
  -        if (saveTime)
  +        if (_saveConfig.saveTime())
           {
               config.setAttribute(TIME, "" + result.getTime());
           }
  -        if (saveLabel)
  +        if (_saveConfig.saveLabel())
           {
               config.setAttribute(LABEL, result.getSampleLabel());
           }
  -        if (saveResponseCode)
  +        if (_saveConfig.saveCode())
           {
               config.setAttribute(RESPONSE_CODE, result.getResponseCode());
           }
  -        if (saveResponseMessage)
  +        if (_saveConfig.saveMessage())
           {
               config.setAttribute(RESPONSE_MESSAGE, 
result.getResponseMessage());
           }
  -        if (saveThreadName)
  +        if (_saveConfig.saveThreadName())
           {
               config.setAttribute(THREAD_NAME, result.getThreadName());
           }
  -        if (saveDataType)
  +        if (_saveConfig.saveDataType())
           {
               config.setAttribute(DATA_TYPE, result.getDataType());
           }
   
  -        if (printMilliseconds)
  +        if (_saveConfig.printMilliseconds())
           {
               config.setAttribute(TIME_STAMP, "" + result.getTimeStamp());
           }
  -        else if (formatter != null)
  +        else if (_saveConfig.formatter() != null)
           {
  -            String stamp = formatter.format(new Date(result.getTimeStamp()));
  +            String stamp = _saveConfig.formatter().format(new 
Date(result.getTimeStamp()));
   
               config.setAttribute(TIME_STAMP, stamp);
           }
   
  -        if (saveSuccessful)
  +        if (_saveConfig.saveSuccess())
           {
               config.setAttribute(
                   SUCCESSFUL,
  @@ -656,7 +464,7 @@
           // whether to save the response data
           else
           {
  -            if (assertionsResultsToSave == SAVE_ALL_ASSERTIONS)
  +            if (_saveConfig.assertionsResultsToSave() == 
SampleSaveConfiguration.SAVE_ALL_ASSERTIONS)
               {
                   config.addChild(
                       createConfigForString(
  @@ -671,14 +479,14 @@
                   }
               }
               else if (
  -                (assertionsResultsToSave == SAVE_FIRST_ASSERTION)
  +                (_saveConfig.assertionsResultsToSave() == 
SampleSaveConfiguration.SAVE_FIRST_ASSERTION)
                       && assResults != null
                       && assResults.length > 0)
               {
                   config.addChild(getConfiguration(assResults[0]));
               }
   
  -            if (saveResponseData)
  +            if (_saveConfig.saveResponseData())
               {
                   config.addChild(getConfiguration(result.getResponseData()));
               }
  @@ -693,9 +501,9 @@
        * @param sample the test result to be converted
        * @return       the separated value representation of the result
        */
  -    public static String resultToDelimitedString(SampleResult 
sample,SampleSaveConfiguration saveConfig)
  +    public static String resultToDelimitedString(SampleResult sample)
       {
  -        return resultToDelimitedString(sample, defaultDelimiter);
  +        return resultToDelimitedString(sample, 
sample.getSaveConfig().getDelimiter());
       }
   
       /**
  @@ -711,62 +519,63 @@
           String delimiter)
       {
           StringBuffer text = new StringBuffer();
  +             SampleSaveConfiguration saveConfig=sample.getSaveConfig();
   
  -        if (printMilliseconds)
  +        if (saveConfig.saveTimestamp())
           {
  -            text.append("" + sample.getTimeStamp());
  +            text.append(sample.getTimeStamp());
               text.append(delimiter);
           }
  -        else if (formatter != null)
  +        else if (saveConfig.formatter() != null)
           {
  -            String stamp = formatter.format(new Date(sample.getTimeStamp()));
  +            String stamp = _saveConfig.formatter().format(new 
Date(sample.getTimeStamp()));
               text.append(stamp);
               text.append(delimiter);
           }
   
  -        if (saveTime)
  +        if (saveConfig.saveTime())
           {
  -            text.append("" + sample.getTime());
  +            text.append(sample.getTime());
               text.append(delimiter);
           }
   
  -        if (saveLabel)
  +        if (saveConfig.saveLabel())
           {
               text.append(sample.getSampleLabel());
               text.append(delimiter);
           }
   
  -        if (saveResponseCode)
  +        if (saveConfig.saveCode())
           {
               text.append(sample.getResponseCode());
               text.append(delimiter);
           }
   
  -        if (saveResponseMessage)
  +        if (saveConfig.saveMessage())
           {
               text.append(sample.getResponseMessage());
               text.append(delimiter);
           }
   
  -        if (saveThreadName)
  +        if (saveConfig.saveThreadName())
           {
               text.append(sample.getThreadName());
               text.append(delimiter);
           }
   
  -        if (saveDataType)
  +        if (saveConfig.saveDataType())
           {
               text.append(sample.getDataType());
               text.append(delimiter);
           }
   
  -        if (saveSuccessful)
  +        if (saveConfig.saveSuccess())
           {
  -            text.append("" + sample.isSuccessful());
  +            text.append(sample.isSuccessful());
               text.append(delimiter);
           }
   
  -        if (saveAssertionResultsFailureMessage)
  +        if (saveConfig.saveAssertionResultsFailureMessage())
           {
               String message = null;
               AssertionResult[] results = sample.getAssertionResults();
  @@ -776,11 +585,10 @@
                   message = results[0].getFailureMessage();
               }
   
  -            if (message == null)
  +            if (message != null)
               {
  -                message = "";
  +                 text.append(message);
               }
  -            text.append(message);
               text.append(delimiter);
           }
           // text.append(sample.getSamplerData().toString());
  @@ -955,7 +763,7 @@
       {
           TestElement element = null;
   
  -             String testClass= (String) config.getAttribute("class");
  +             String testClass= config.getAttribute("class");
           element = (TestElement) Class.forName(
                NameUpdater.getCurrentName(testClass)).newInstance();
           Configuration[] children = config.getChildren();
  @@ -1009,7 +817,7 @@
       {
           Collection coll =
               (Collection) Class
  -                .forName((String) config.getAttribute("class"))
  +                .forName(config.getAttribute("class"))
                   .newInstance();
           Configuration[] items = config.getChildren();
   
  @@ -1050,7 +858,6 @@
   
       private static JMeterProperty createProperty(Configuration config, 
String testClass)
           throws
  -            ConfigurationException,
               IllegalAccessException,
               ClassNotFoundException,
               InstantiationException
  @@ -1087,7 +894,7 @@
       {
           Map map =
               (Map) Class
  -                .forName((String) config.getAttribute("class"))
  +                .forName(config.getAttribute("class"))
                   .newInstance();
           Configuration[] items = config.getChildren();
   
  
  
  
  1.8       +2 -110    
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SaveServiceConstants.java 13 Feb 2004 02:40:54 -0000      1.7
  +++ SaveServiceConstants.java 23 Mar 2005 01:16:32 -0000      1.8
  @@ -33,114 +33,6 @@
   public interface SaveServiceConstants
   {
       // ---------------------------------------------------------------------
  -    // PROPERTY FILE CONSTANTS
  -    // ---------------------------------------------------------------------
  -
  -    /** Indicates that the results file should be in XML format.  **/
  -    public static final String XML = "xml";
  -
  -    /** Indicates that the results file should be in CSV format.  **/
  -    public static final String CSV = "csv";
  -
  -    /** Indicates that the results should be stored in a database.  **/
  -    public static final String DATABASE = "db";
  -
  -    /** A properties file indicator for true.  **/
  -    public static final String TRUE = "true";
  -
  -    /** A properties file indicator for false.  **/
  -    public static final String FALSE = "false";
  -
  -    /** A properties file indicator for milliseconds.  **/
  -    public static final String MILLISECONDS = "ms";
  -
  -    /** A properties file indicator for none.  **/
  -    public static final String NONE = "none";
  -
  -    /** A properties file indicator for the first of a series.  **/
  -    public static final String FIRST = "first";
  -
  -    /** A properties file indicator for all of a series.  **/
  -    public static final String ALL = "all";
  -
  -    /** The name of the property indicating which assertion results
  -     should be saved.  **/
  -    public static final String ASSERTION_RESULTS_FAILURE_MESSAGE_PROP
  -            = "jmeter.save.saveservice.assertion_results_failure_message";
  -
  -    /** The name of the property indicating which assertion results
  -     should be saved.  **/
  -    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
  -            = "jmeter.save.saveservice.data_type";
  -
  -    /** The name of the property indicating whether the label
  -     should be saved.  **/
  -    public static final String SAVE_LABEL_PROP
  -            = "jmeter.save.saveservice.label";
  -
  -    /** The name of the property indicating whether the response code
  -     should be saved.  **/
  -    public static final String SAVE_RESPONSE_CODE_PROP
  -            = "jmeter.save.saveservice.response_code";
  -
  -    /** The name of the property indicating whether the response data
  -     should be saved.  **/
  -    public static final String SAVE_RESPONSE_DATA_PROP
  -            = "jmeter.save.saveservice.response_data";
  -
  -    /** The name of the property indicating whether the response message
  -     should be saved.  **/
  -    public static final String SAVE_RESPONSE_MESSAGE_PROP
  -            = "jmeter.save.saveservice.response_message";
  -
  -    /** The name of the property indicating whether the success indicator
  -     should be saved.  **/
  -    public static final String SAVE_SUCCESSFUL_PROP
  -            = "jmeter.save.saveservice.successful";
  -
  -    /** The name of the property indicating whether the thread name
  -     should be saved.  **/
  -    public static final String SAVE_THREAD_NAME_PROP
  -            = "jmeter.save.saveservice.thread_name";
  -
  -    /** The name of the property indicating whether the time
  -     should be saved.  **/
  -    public static final String SAVE_TIME_PROP
  -            = "jmeter.save.saveservice.time";
  -
  -    /** The name of the property indicating whether the time stamp
  -     should be saved.  **/
  -    public static final String TIME_STAMP_FORMAT_PROP
  -            = "jmeter.save.saveservice.timestamp_format";
  -
  -    // ---------------------------------------------------------------------
       // XML RESULT FILE CONSTANTS AND FIELD NAME CONSTANTS
       // ---------------------------------------------------------------------
   
  
  
  
  1.2       +302 -6    
jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
  
  Index: SampleSaveConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SampleSaveConfiguration.java      20 Sep 2004 23:08:40 -0000      1.1
  +++ SampleSaveConfiguration.java      23 Mar 2005 01:16:32 -0000      1.2
  @@ -7,6 +7,10 @@
   package org.apache.jmeter.samplers;
   
   import java.io.Serializable;
  +import java.text.SimpleDateFormat;
  +import java.util.Properties;
  +
  +import org.apache.jmeter.util.JMeterUtils;
   
   /**
    * @author mstover
  @@ -17,11 +21,273 @@
   public class SampleSaveConfiguration implements Cloneable,Serializable
   {
      static final long serialVersionUID = 1;
  -   boolean time = true, latency = true, timestamp = true, success = true,
  -         label = true, code = true, message = true, threadName = false,
  -         dataType = true, encoding = true, assertions = false,
  -         subresults = false, responseData = false, samplerData = false,xml = 
true,
  -         fieldNames = true,responseHeaders = false,requestHeaders = false;
  +   
  +   
  +   // ---------------------------------------------------------------------
  +   // PROPERTY FILE CONSTANTS
  +   // ---------------------------------------------------------------------
  +
  +   /** Indicates that the results file should be in XML format.  **/
  +   public static final String XML = "xml";
  +
  +   /** Indicates that the results file should be in CSV format.  **/
  +   public static final String CSV = "csv";
  +
  +   /** Indicates that the results should be stored in a database.  **/
  +   public static final String DATABASE = "db";
  +
  +   /** A properties file indicator for true.  **/
  +   public static final String TRUE = "true";
  +
  +   /** A properties file indicator for false.  **/
  +   public static final String FALSE = "false";
  +
  +   /** A properties file indicator for milliseconds.  **/
  +   public static final String MILLISECONDS = "ms";
  +
  +   /** A properties file indicator for none.  **/
  +   public static final String NONE = "none";
  +
  +   /** A properties file indicator for the first of a series.  **/
  +   public static final String FIRST = "first";
  +
  +   /** A properties file indicator for all of a series.  **/
  +   public static final String ALL = "all";
  +
  +   /** The name of the property indicating which assertion results
  +    should be saved.  **/
  +   public static final String ASSERTION_RESULTS_FAILURE_MESSAGE_PROP
  +           = "jmeter.save.saveservice.assertion_results_failure_message";
  +
  +   /** The name of the property indicating which assertion results
  +    should be saved.  **/
  +   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";
  +
  +   /** The name of the property indicating whether the data type
  +    should be saved.  **/
  +   public static final String SAVE_DATA_TYPE_PROP
  +           = "jmeter.save.saveservice.data_type";
  +
  +   /** The name of the property indicating whether the label
  +    should be saved.  **/
  +   public static final String SAVE_LABEL_PROP
  +           = "jmeter.save.saveservice.label";
  +
  +   /** The name of the property indicating whether the response code
  +    should be saved.  **/
  +   public static final String SAVE_RESPONSE_CODE_PROP
  +           = "jmeter.save.saveservice.response_code";
  +
  +   /** The name of the property indicating whether the response data
  +    should be saved.  **/
  +   public static final String SAVE_RESPONSE_DATA_PROP
  +           = "jmeter.save.saveservice.response_data";
  +
  +   /** The name of the property indicating whether the response message
  +    should be saved.  **/
  +   public static final String SAVE_RESPONSE_MESSAGE_PROP
  +           = "jmeter.save.saveservice.response_message";
  +
  +   /** The name of the property indicating whether the success indicator
  +    should be saved.  **/
  +   public static final String SAVE_SUCCESSFUL_PROP
  +           = "jmeter.save.saveservice.successful";
  +
  +   /** The name of the property indicating whether the thread name
  +    should be saved.  **/
  +   public static final String SAVE_THREAD_NAME_PROP
  +           = "jmeter.save.saveservice.thread_name";
  +
  +   /** The name of the property indicating whether the time
  +    should be saved.  **/
  +   public static final String SAVE_TIME_PROP
  +           = "jmeter.save.saveservice.time";
  +
  +   /** The name of the property indicating whether the time stamp
  +    should be saved.  **/
  +   public static final String TIME_STAMP_FORMAT_PROP
  +           = "jmeter.save.saveservice.timestamp_format";
  +
  +   // ---------------------------------------------------------------------
  +   // XML RESULT FILE CONSTANTS AND FIELD NAME CONSTANTS
  +   // ---------------------------------------------------------------------
  +
  +   public final static String PRESERVE = "preserve";
  +   public final static String XML_SPACE = "xml:space";
  +   public static final String ASSERTION_RESULT_TAG_NAME = "assertionResult";
  +   public static final String BINARY = "binary";
  +   public static final String DATA_TYPE = "dataType";
  +   public static final String ERROR = "error";
  +   public static final String FAILURE = "failure";
  +   public static final String FAILURE_MESSAGE = "failureMessage";
  +   public static final String LABEL = "label";
  +   public static final String RESPONSE_CODE = "responseCode";
  +   public static final String RESPONSE_MESSAGE = "responseMessage";
  +   public static final String SAMPLE_RESULT_TAG_NAME = "sampleResult";
  +   public static final String SUCCESSFUL = "success";
  +   public static final String THREAD_NAME = "threadName";
  +   public static final String TIME = "time";
  +   public static final String TIME_STAMP = "timeStamp";
  +
  +   // Initialise values from properties
  +   private boolean time = _time, latency = _latency, timestamp = _timestamp, 
success = _success,
  +         label = _label, code = _code, message = _message, threadName = 
_threadName,
  +         dataType = _dataType, encoding = _encoding, assertions = 
_assertions,
  +         subresults = _subresults, responseData = _responseData, samplerData 
= _samplerData,
  +         xml = _xml, fieldNames = _fieldNames, responseHeaders = 
_responseHeaders,
  +         requestHeaders = _requestHeaders;
  +   
  +   private boolean 
saveAssertionResultsFailureMessage=_saveAssertionResultsFailureMessage;
  +   private int assertionsResultsToSave =_assertionsResultsToSave;
  +   private String delimiter = _delimiter;
  +   private boolean printMilliseconds = _printMilliseconds;
  +   
  +   /** A formatter for the time stamp. */
  +   private SimpleDateFormat formatter = _formatter;
  +   
  +   // Defaults from properties:
  +   private static final boolean _time,  _timestamp, _success,
  +   _label, _code, _message, _threadName, _xml, _responseData,
  +   _dataType, _encoding, _assertions, _latency,
  +   _subresults,  _samplerData, _fieldNames, _responseHeaders, 
_requestHeaders;
  +   
  +   private static final boolean _saveAssertionResultsFailureMessage;
  +   private static final String _timeStampFormat;
  +   private static int _assertionsResultsToSave;
  +   // TODO turn into method?
  +   public static final int SAVE_NO_ASSERTIONS = 0;
  +   public static final int SAVE_FIRST_ASSERTION = SAVE_NO_ASSERTIONS + 1;
  +   public static final int SAVE_ALL_ASSERTIONS = SAVE_FIRST_ASSERTION + 1;
  +   private static final boolean _printMilliseconds;
  +   private static final SimpleDateFormat _formatter;
  +   
  +   /** The string used to separate fields when stored to disk, for example,
  +   the comma for CSV files. */
  +   private static final String _delimiter;
  +   private static final String DEFAULT_DELIMITER = ",";
  +
  +   /**
  +    * Read in the properties having to do with saving from a properties file.
  +    */
  +   static
  +   {
  +        // TODO - get from properties?
  +        _subresults = _encoding = _assertions= _latency = _samplerData = 
true;
  +        _responseHeaders = _requestHeaders = true;
  +        
  +        
  +             Properties props = JMeterUtils.getJMeterProperties();
  +
  +             
_delimiter=props.getProperty(DEFAULT_DELIMITER_PROP,DEFAULT_DELIMITER);
  +             
  +       _fieldNames =
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(PRINT_FIELD_NAMES_PROP, FALSE));
  +
  +       _dataType =
  +           TRUE.equalsIgnoreCase(props.getProperty(SAVE_DATA_TYPE_PROP, 
TRUE));
  +
  +       _label =
  +           TRUE.equalsIgnoreCase(props.getProperty(SAVE_LABEL_PROP, TRUE));
  +
  +       _code = // TODO is this correct?
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(SAVE_RESPONSE_CODE_PROP, TRUE));
  +
  +       _responseData =
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(SAVE_RESPONSE_DATA_PROP, FALSE));
  +
  +       _message =
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(SAVE_RESPONSE_MESSAGE_PROP, TRUE));
  +
  +       _success =
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(SAVE_SUCCESSFUL_PROP, TRUE));
  +
  +       _threadName =
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(SAVE_THREAD_NAME_PROP, TRUE));
  +
  +       _time =
  +           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))
  +       {
  +           _formatter = new SimpleDateFormat(_timeStampFormat);
  +       } else {
  +                _formatter = null;
  +       }
  +
  +        _timestamp = !_timeStampFormat.equalsIgnoreCase(NONE);
  +        
  +       _saveAssertionResultsFailureMessage =
  +           TRUE.equalsIgnoreCase(
  +               props.getProperty(
  +                   ASSERTION_RESULTS_FAILURE_MESSAGE_PROP,
  +                   FALSE));
  +
  +       String whichAssertionResults = 
props.getProperty(ASSERTION_RESULTS_PROP, NONE);
  +       if (NONE.equals(whichAssertionResults))
  +       {
  +           _assertionsResultsToSave = SAVE_NO_ASSERTIONS;
  +       }
  +       else if (FIRST.equals(whichAssertionResults))
  +       {
  +           _assertionsResultsToSave = SAVE_FIRST_ASSERTION;
  +       }
  +       else if (ALL.equals(whichAssertionResults))
  +       {
  +           _assertionsResultsToSave = SAVE_ALL_ASSERTIONS;
  +       }
  +
  +       String howToSave = props.getProperty(OUTPUT_FORMAT_PROP, XML);
  +
  +       if (XML.equals(howToSave))
  +       {
  +           _xml=true;
  +       }
  +       else
  +       {
  +           _xml=false;
  +       }
  +
  +   }
  +
  +   private static final SampleSaveConfiguration _static = new 
SampleSaveConfiguration();
  +
  +   // Give access to initial configuration
  +   public static SampleSaveConfiguration staticConfig(){
  +        return _static;
  +   }
  +   
  +   public SampleSaveConfiguration(){
  +   }
      
      public Object clone()
      {
  @@ -44,6 +310,11 @@
         s.fieldNames = fieldNames;
         s.responseHeaders = responseHeaders;
         s.requestHeaders = requestHeaders;
  +       s.formatter = formatter;
  +       s.assertionsResultsToSave = assertionsResultsToSave;
  +       s.saveAssertionResultsFailureMessage = 
saveAssertionResultsFailureMessage;
  +       s.delimiter = delimiter;
  +       s.printMilliseconds = printMilliseconds;
         return s;
      }
      
  @@ -325,11 +596,36 @@
      {
         return fieldNames;
      }
  +   
      /**
  -    * @param printFieldNames The printFieldNames to set.
  +    * @param printFieldNames - should field names be printed?
       */
      public void setFieldNames(boolean printFieldNames)
      {
         this.fieldNames = printFieldNames;
      }
  +
  +   public boolean printMilliseconds() {
  +             return printMilliseconds;
  +    }
  +
  +     public SimpleDateFormat formatter() {
  +             return formatter;
  +     }
  +     
  +     public boolean saveAssertionResultsFailureMessage() {
  +             return saveAssertionResultsFailureMessage;
  +     }
  +     
  +     public void setAssertionResultsFailureMessage(boolean b) {
  +             saveAssertionResultsFailureMessage=b;
  +     }
  +     
  +     public int assertionsResultsToSave() {
  +             return assertionsResultsToSave;
  +     }
  +     
  +     public String getDelimiter() {
  +             return delimiter;
  +     }
   }
  \ No newline at end of file
  
  
  
  1.45      +29 -29    
jakarta-jmeter/src/core/org/apache/jmeter/reporters/ResultCollector.java
  
  Index: ResultCollector.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/reporters/ResultCollector.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- ResultCollector.java      11 Jan 2005 04:29:32 -0000      1.44
  +++ ResultCollector.java      23 Mar 2005 01:16:32 -0000      1.45
  @@ -20,7 +20,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;
  @@ -41,7 +40,7 @@
   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.avalon.framework.configuration.DefaultConfigurationSerializer;
   import org.apache.jmeter.engine.event.LoopIterationEvent;
   import org.apache.jmeter.engine.util.NoThreadClone;
   import org.apache.jmeter.samplers.Clearable;
  @@ -80,7 +79,7 @@
      public static final String ERROR_LOGGING = 
"ResultCollector.error_logging";
      // protected List results = Collections.synchronizedList(new ArrayList());
      //private int current;
  -   transient private DefaultConfigurationSerializer serializer;
  +   //transient private DefaultConfigurationSerializer serializer;
      //private boolean inLoading = false;
      transient private volatile PrintWriter out;
      private boolean inTest = false;
  @@ -94,7 +93,7 @@
      public ResultCollector()
      {
         //current = -1;
  -      serializer = new DefaultConfigurationSerializer();
  +      //serializer = new DefaultConfigurationSerializer();
         setErrorLogging(false);
         setProperty(new ObjectProperty(SAVE_CONFIG,new 
SampleSaveConfiguration()));
      }
  @@ -168,8 +167,7 @@
         testStarted("local");
      }
   
  -   public void loadExistingFile() throws SAXException, IOException,
  -         ConfigurationException
  +   public void loadExistingFile() throws IOException
      {
         //inLoading = true;
         boolean parsedOK = false;
  @@ -185,7 +183,7 @@
            }
            catch (Exception e)
            {
  -            log.warn("File load failure, trying old data format.",e);
  +            log.warn("File load failure, trying old data format.");
               try
               {
                  Configuration savedSamples = getConfiguration(getFilename());
  @@ -344,18 +342,19 @@
       *           description of the Parameter
       * @return the serializedSampleResult value
       */
  -   private String getSerializedSampleResult(SampleResult result)
  -         throws SAXException, IOException, ConfigurationException
  -   {
  -      ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
  -
  -      serializer.serialize(tempOut, OldSaveService.getConfiguration(result,
  -            getFunctionalMode()));
  -      String serVer = tempOut.toString();
  -
  -      return serVer.substring(serVer.indexOf(System
  -            .getProperty("line.separator")));
  -   }
  +   //NOTUSED
  +//   private String getSerializedSampleResult(SampleResult result)
  +//         throws SAXException, IOException, ConfigurationException
  +//   {
  +//      ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
  +//
  +//      serializer.serialize(tempOut, OldSaveService.getConfiguration(result,
  +//            getFunctionalMode()));
  +//      String serVer = tempOut.toString();
  +//
  +//      return serVer.substring(serVer.indexOf(System
  +//            .getProperty("line.separator")));
  +//   }
   
      private void readSamples(TestResultWrapper testResults) throws Exception
      {
  @@ -391,9 +390,9 @@
         finalizeFileOutput();
      }
   
  -   public void setListener(Object l)
  -   {
  -   }
  +//   public void setListener(Object l)
  +//   {
  +//   }
   
      public void sampleStarted(SampleEvent e)
      {
  @@ -416,14 +415,17 @@
         if (!isErrorLogging() || !result.isSuccessful())
         {
            sendToVisualizer(result);
  -
  -         try
  +              
  +              SampleSaveConfiguration config = getSaveConfig();
  +              result.setSaveConfig(config);
  +              
  +              try
            {
  -            if (!getSaveConfig().saveAsXml())
  +            if (!config.saveAsXml())
               {
                  if (out != null)
                  {
  -                  String savee = 
OldSaveService.resultToDelimitedString(result,getSaveConfig());
  +                  String savee = 
OldSaveService.resultToDelimitedString(result);
                     out.println(savee);
                  }
               }
  @@ -454,7 +456,6 @@
         {
            if (!isResultMarked(result) && !this.isStats)
            {
  -            result.setSaveConfig(getSaveConfig());
               SaveService.saveSampleResult(result, out);
            }
         }
  @@ -488,8 +489,7 @@
         return marked;
      }
   
  -   private void initializeFileOutput() throws IOException,
  -         ConfigurationException, SAXException
  +   private void initializeFileOutput() throws IOException
      {
   
         String filename = getFilename();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to