You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/06/27 01:36:36 UTC

svn commit: r672057 - in /jakarta/jmeter/trunk: docs/images/screenshots/ src/core/org/apache/jmeter/reporters/ src/core/org/apache/jmeter/reporters/gui/ src/core/org/apache/jmeter/resources/ xdocs/ xdocs/images/screenshots/ xdocs/usermanual/

Author: sebb
Date: Thu Jun 26 16:36:35 2008
New Revision: 672057

URL: http://svn.apache.org/viewvc?rev=672057&view=rev
Log:
Save Responses to a file can save the generated filename(s) to variables

Modified:
    jakarta/jmeter/trunk/docs/images/screenshots/savetofile.png
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/gui/ResultSaverGui.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/images/screenshots/savetofile.png
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/docs/images/screenshots/savetofile.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/docs/images/screenshots/savetofile.png?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java Thu Jun 26 16:36:35 2008
@@ -24,11 +24,13 @@
 import java.io.IOException;
 import java.io.Serializable;
 
+import org.apache.commons.lang.text.StrBuilder;
 import org.apache.jmeter.samplers.Clearable;
 import org.apache.jmeter.samplers.SampleEvent;
 import org.apache.jmeter.samplers.SampleListener;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.jorphan.util.JOrphanUtils;
 import org.apache.log.Logger;
@@ -50,7 +52,9 @@
 
 	public static final String FILENAME = "FileSaver.filename"; // $NON-NLS-1$
 
-	public static final String ERRORS_ONLY = "FileSaver.errorsonly"; // $NON-NLS-1$
+    public static final String VARIABLE_NAME = "FileSaver.variablename"; // $NON-NLS-1$
+
+    public static final String ERRORS_ONLY = "FileSaver.errorsonly"; // $NON-NLS-1$
 
     public static final String SUCCESS_ONLY = "FileSaver.successonly"; // $NON-NLS-1$
 
@@ -105,27 +109,28 @@
 	 * @see org.apache.jmeter.samplers.SampleListener#sampleOccurred(org.apache.jmeter.samplers.SampleEvent)
 	 */
 	public void sampleOccurred(SampleEvent e) {
-      processSample(e.getResult());
+      processSample(e.getResult(), new Counter());
    }
 
    /**
     * Recurse the whole (sub)result hierarchy.
     *
     * @param s Sample result
+    * @param c sample counter
     */
-   private void processSample(SampleResult s) {
-		saveSample(s);
+   private void processSample(SampleResult s, Counter c) {
+		saveSample(s, c.num++);
 		SampleResult[] sr = s.getSubResults();
 		for (int i = 0; i < sr.length; i++) {
-			processSample(sr[i]);
+			processSample(sr[i], c);
 		}
 	}
 
 	/**
-	 * @param s
-	 *            SampleResult to save
+	 * @param s SampleResult to save
+	 * @param num number to append to variable (if >0)
 	 */
-	private void saveSample(SampleResult s) {
+	private void saveSample(SampleResult s, int num) {
 		// Should we save the sample?
 		if (s.isSuccessful()){
 		    if (getErrorsOnly()){
@@ -140,6 +145,15 @@
 		String fileName = makeFileName(s.getContentType());
 		log.debug("Saving " + s.getSampleLabel() + " in " + fileName);
         s.setResultFileName(fileName);// Associate sample with file name
+        String variable = getVariableName();
+        if (variable.length()>0){
+            if (num > 0) {
+                StrBuilder sb = new StrBuilder(variable);
+                sb.append(num);
+                variable=sb.toString();
+            }
+            JMeterContextService.getContext().getVariables().put(variable, fileName);
+        }
 		File out = new File(fileName);
 		FileOutputStream pw = null;
 		try {
@@ -197,6 +211,10 @@
 		return getPropertyAsString(FILENAME);
 	}
 
+    private String getVariableName() {
+        return getPropertyAsString(VARIABLE_NAME,""); // $NON-NLS-1$
+    }
+
 	private boolean getErrorsOnly() {
 		return getPropertyAsBoolean(ERRORS_ONLY);
 	}
@@ -205,4 +223,8 @@
         return getPropertyAsBoolean(SUCCESS_ONLY);
     }
 
+    // Mutable int to keep track of sample count
+    private static class Counter{
+        int num;
+    }
 }

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/gui/ResultSaverGui.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/gui/ResultSaverGui.java?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/gui/ResultSaverGui.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/reporters/gui/ResultSaverGui.java Thu Jun 26 16:36:35 2008
@@ -28,6 +28,7 @@
 
 import org.apache.jmeter.reporters.ResultSaver;
 import org.apache.jmeter.samplers.Clearable;
+import org.apache.jmeter.testelement.AbstractTestElement;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jmeter.visualizers.gui.AbstractListenerGui;
@@ -41,7 +42,9 @@
 
 	private JTextField filename;
 
-	private JCheckBox errorsOnly;
+    private JTextField variableName;
+
+    private JCheckBox errorsOnly;
 
     private JCheckBox successOnly;
 
@@ -65,6 +68,7 @@
 		filename.setText(el.getPropertyAsString(ResultSaver.FILENAME));
 		errorsOnly.setSelected(el.getPropertyAsBoolean(ResultSaver.ERRORS_ONLY));
         successOnly.setSelected(el.getPropertyAsBoolean(ResultSaver.SUCCESS_ONLY));
+        variableName.setText(el.getPropertyAsString(ResultSaver.VARIABLE_NAME,""));
 	}
 
 	/**
@@ -86,6 +90,8 @@
 		te.setProperty(ResultSaver.FILENAME, filename.getText());
 		te.setProperty(ResultSaver.ERRORS_ONLY, errorsOnly.isSelected());
         te.setProperty(ResultSaver.SUCCESS_ONLY, successOnly.isSelected());
+        AbstractTestElement at = (AbstractTestElement) te;
+        at.setProperty(ResultSaver.VARIABLE_NAME, variableName.getText(),""); //$NON-NLS-1$
 	}
 
     /**
@@ -97,6 +103,7 @@
         filename.setText(""); //$NON-NLS-1$
         errorsOnly.setSelected(false);
         successOnly.setSelected(false);
+        variableName.setText(""); //$NON-NLS-1$
     }
 
 	private void init() {
@@ -105,6 +112,7 @@
 		Box box = Box.createVerticalBox();
 		box.add(makeTitlePanel());
 		box.add(createFilenamePrefixPanel());
+        box.add(createVariableNamePanel());
 		errorsOnly = new JCheckBox(JMeterUtils.getResString("resultsaver_errors")); // $NON-NLS-1$
 		box.add(errorsOnly);
         successOnly = new JCheckBox(JMeterUtils.getResString("resultsaver_success")); // $NON-NLS-1$
@@ -127,6 +135,21 @@
 	}
 
 
+    private JPanel createVariableNamePanel()
+    {
+        JLabel label = new JLabel(JMeterUtils.getResString("resultsaver_variable")); // $NON-NLS-1$
+
+        variableName = new JTextField(10);
+        variableName.setName(ResultSaver.VARIABLE_NAME);
+        label.setLabelFor(variableName);
+
+        JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
+        filenamePanel.add(label, BorderLayout.WEST);
+        filenamePanel.add(variableName, BorderLayout.CENTER);
+        return filenamePanel;
+    }
+
+
 	// Needed to avoid Class cast error in Clear.java
 	public void clearData() {
 	}

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Thu Jun 26 16:36:35 2008
@@ -639,6 +639,7 @@
 resultsaver_prefix=Filename prefix\:
 resultsaver_success=Save Successful Responses only
 resultsaver_title=Save Responses to a file
+resultsaver_variable=Variable Name:
 retobj=Return object
 reuseconnection=Re-use connection
 revert_project=Revert

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Thu Jun 26 16:36:35 2008
@@ -83,6 +83,7 @@
 <ul>
 <li>LDAP result data now formatted with line breaks</li>
 <li>Add OUT variable to jexl function</li>
+<li>Save Responses to a file can save the generated filename(s) to variables.</li>
 </ul>
 
 <h3>Non-functional changes</h3>

Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/savetofile.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/savetofile.png?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=672057&r1=672056&r2=672057&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Jun 26 16:36:35 2008
@@ -2143,7 +2143,7 @@
 </div>
 </component>
 
-<component name="Save Responses to a file" index="&sect-num;.3.16"  width="361" height="165" screenshot="savetofile.png">
+<component name="Save Responses to a file" index="&sect-num;.3.16"  width="361" height="178" screenshot="savetofile.png">
     <description>
         <p>
         This test element can be placed anywhere in the test plan.
@@ -2162,6 +2162,12 @@
  <properties>
  <property name="Name" required="No">Descriptive name for this element that is shown in the tree.</property>
  <property name="Filename Prefix" required="Yes">Prefix for the generated file names; this can include a directory name.</property>
+ <property name="Variable Name" required="No">
+ Name of a variable in which to save the generated file name (so it can be used later in the test plan).
+ If there are sub-samples then a numeric suffix is added to the variable name.
+ E.g. if the variable name is FILENAME, then the parent sample file name is saved in the variable FILENAME, 
+ and the filenames for the child samplers are saved in FILENAME1, FILENAME2 etc.
+ </property>
  <property name="Save Failed Responses only" required="Yes">If selected, then only failed responses are saved</property>
  <property name="Save Successful Responses only" required="Yes">If selected, then only successful responses are saved</property>
  </properties>



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org