Bug 44650 - CSV Dataset now handles quoted column values

git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/trunk@640095 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 6b24c1c6a3
This commit is contained in:
Sebastian Bazley 2008-03-22 22:18:40 +00:00
parent 49c368d4f0
commit ebe63b0c7e
6 changed files with 31 additions and 9 deletions

View File

@ -19,10 +19,12 @@
package org.apache.jmeter.config;
import java.io.IOException;
import java.io.StringReader;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.engine.event.LoopIterationListener;
import org.apache.jmeter.save.CSVSaveService;
import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jmeter.threads.JMeterVariables;
@ -32,10 +34,6 @@ import org.apache.jorphan.util.JMeterStopThreadException;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
/**
* @author mstover
*
*/
public class CSVDataSet extends ConfigTestElement implements TestBean, LoopIterationListener {
private static final Logger log = LoggingManager.getLoggerForClass();
@ -52,6 +50,8 @@ public class CSVDataSet extends ConfigTestElement implements TestBean, LoopItera
private transient String delimiter;
private transient boolean quoted = false;
private transient boolean recycle = true;
private transient boolean stopThread = false;
@ -81,7 +81,9 @@ public class CSVDataSet extends ConfigTestElement implements TestBean, LoopItera
JMeterVariables threadVars = this.getThreadContext().getVariables();
String line = server.readLine(_fileName,getRecycle());
if (line!=null) {// i.e. not EOF
String[] lineValues = JOrphanUtils.split(line, delim,false);
String[] lineValues = getQuotedData() ?
CSVSaveService.csvReadFile(new StringReader(line), delim.charAt(0))
: JOrphanUtils.split(line, delim, false);
for (int a = 0; a < vars.length && a < lineValues.length; a++) {
threadVars.put(vars[a], lineValues[a]);
}
@ -152,6 +154,14 @@ public class CSVDataSet extends ConfigTestElement implements TestBean, LoopItera
this.delimiter = delimiter;
}
public boolean getQuotedData() {
return quoted;
}
public void setQuotedData(boolean quoted) {
this.quoted = quoted;
}
public boolean getRecycle() {
return recycle;
}

View File

@ -35,11 +35,12 @@ public class CSVDataSetBeanInfo extends BeanInfoSupport {
private static final String DELIMITER = "delimiter"; //$NON-NLS-1$
private static final String RECYCLE = "recycle"; //$NON-NLS-1$
private static final String STOPTHREAD = "stopThread"; //$NON-NLS-1$
private static final String QUOTED_DATA = "quotedData"; //$NON-NLS-1$
public CSVDataSetBeanInfo() {
super(CSVDataSet.class);
createPropertyGroup("csv_data", //$NON-NLS-1$
new String[] { FILENAME, FILE_ENCODING, VARIABLE_NAMES, DELIMITER, RECYCLE, STOPTHREAD });
new String[] { FILENAME, FILE_ENCODING, VARIABLE_NAMES, DELIMITER, QUOTED_DATA, RECYCLE, STOPTHREAD });
PropertyDescriptor p = property(FILENAME);
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
@ -61,6 +62,11 @@ public class CSVDataSetBeanInfo extends BeanInfoSupport {
p.setValue(DEFAULT, ","); //$NON-NLS-1$
p.setValue(NOT_EXPRESSION, Boolean.TRUE);
p = property(QUOTED_DATA);
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, Boolean.FALSE);
p.setValue(NOT_EXPRESSION, Boolean.TRUE);
p = property(RECYCLE);
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, Boolean.TRUE);

View File

@ -8,6 +8,8 @@ variableNames.displayName=Variable Names (comma-delimited)
variableNames.shortDescription=List your variable names in order to match the order of columns in your csv data. Separate by commas.
delimiter.displayName=Delimiter (use '\\t' for tab)
delimiter.shortDescription=Enter the delimiter ('\\t' for tab)
quotedData.displayName=Allow quoted data?
quotedData.shortDescription=Allow CSV data values to be quoted?
recycle.displayName=Recycle on EOF ?
recycle.shortDescription=Should the file be re-read from the start on reaching EOF ?
stopThread.displayName=Stop thread on EOF ?

View File

@ -121,6 +121,7 @@ Note __split() and __regex() cannot be used on the Test Plan.</li>
As a special case, if the HTTP Sampler path starts with "http://" or "https://" then this is used as the full URL.
</li>
<li>Bug 44575 - Result Saver can now save only successful results</li>
<li>Bug 44650 - CSV Dataset now handles quoted column values</li>
</ul>
<h4>Non-functional changes</h4>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -2084,11 +2084,13 @@ the Report.
<br></br>
</description>
<component name="CSV Data Set Config" index="&sect-num;.4.1" width="363" height="251" screenshot="csvdatasetconfig.png">
<component name="CSV Data Set Config" index="&sect-num;.4.1" width="308" height="278" screenshot="csvdatasetconfig.png">
<description>
<p>
<p>
CSV Data Set Config is used to read lines from a file, and split them into variables.
It is easier to use than the __CSVRead() and _StringFromFile() functions.
Versions of JMeter after 2.3.1 allow variables to be quoted; this allows the value to contain a delimiter.
Previously it was necessary to choose a delimiter that was not used in any values.
</p>
<p>
The file is only opened once, and each thread will use a different line from the file.
@ -2100,7 +2102,7 @@ the Report.
However the variables do work in the HTTP Auth Manager, as the username etc are processed at run-time.
</note>
<p>
As a special case, the string "\t" (without quotes) is treated as a Tab.
As a special case, the string "\t" (without quotes) in the delimiter field is treated as a Tab.
</p>
<p>
When the end of file (EOF) is reached, and the recycle option is true, reading starts again with the first line of the file.
@ -2125,6 +2127,7 @@ the Report.
<property name="Delimiter" required="Yes">Delimiter to be used to split the records in the file.
If there are fewer values on the line than there are variables the remaining variables are not updated -
so they will retain their previous value (if any).</property>
<property name="Allow quoted data?" required="Yes">Should the CSV file allow values to be quoted?</property>
<property name="Recycle on EOF?" required="Yes">Should the file be re-read from the beginning on reaching EOF? (default is true)</property>
<property name="Stop thread on EOF?" required="Yes">Should the thread be stopped on EOF, if Recycle is false? (default is false)</property>
</properties>