You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2012/09/14 01:00:47 UTC
svn commit: r1384594 - in /jmeter/trunk: bin/testfiles/testquoted.csv
src/components/org/apache/jmeter/config/CSVDataSet.java
test/src/org/apache/jmeter/config/TestCVSDataSet.java xdocs/changes.xml
xdocs/usermanual/component_reference.xml
Author: sebb
Date: Thu Sep 13 23:00:47 2012
New Revision: 1384594
URL: http://svn.apache.org/viewvc?rev=1384594&view=rev
Log:
CSV Dataset does not handle embedded new lines in quoted data
Bugzilla Id: 53807
Added:
jmeter/trunk/bin/testfiles/testquoted.csv
Modified:
jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java
jmeter/trunk/xdocs/changes.xml
jmeter/trunk/xdocs/usermanual/component_reference.xml
Added: jmeter/trunk/bin/testfiles/testquoted.csv
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/testfiles/testquoted.csv?rev=1384594&view=auto
==============================================================================
--- jmeter/trunk/bin/testfiles/testquoted.csv (added)
+++ jmeter/trunk/bin/testfiles/testquoted.csv Thu Sep 13 23:00:47 2012
@@ -0,0 +1,6 @@
+A|B|C|"D|1"
+a1|b1|"c1"|d1
+a2|b2|c2|d2
+a3|b3|c3|"d3"
+a4|b4|c4|"d4
+Previous line is malformed
\ No newline at end of file
Modified: jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java?rev=1384594&r1=1384593&r2=1384594&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java Thu Sep 13 23:00:47 2012
@@ -18,6 +18,7 @@
package org.apache.jmeter.config;
+import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
@@ -144,26 +145,24 @@ public class CSVDataSet extends ConfigTe
// TODO: fetch this once as per vars above?
JMeterVariables threadVars = context.getVariables();
- String line = null;
+ String[] lineValues = {};
try {
- line = server.readLine(alias, getRecycle(), firstLineIsNames);
+ if (getQuotedData()) {
+ synchronized(server) {
+ BufferedReader infile = server.getReader(alias, recycle, firstLineIsNames);
+ lineValues = CSVSaveService.csvReadFile(infile, delim.charAt(0));
+ }
+ } else {
+ String line = server.readLine(alias, recycle, firstLineIsNames);
+ lineValues = JOrphanUtils.split(line, delim, false);
+ }
+ for (int a = 0; a < vars.length && a < lineValues.length; a++) {
+ threadVars.put(vars[a], lineValues[a]);
+ }
} catch (IOException e) { // treat the same as EOF
log.error(e.toString());
}
- if (line!=null) {// i.e. not EOF
- try {
- String[] lineValues = getQuotedData() ?
- CSVSaveService.csvSplitString(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]);
- }
- } catch (IOException e) { // Should only happen for quoting errors
- log.error("Unexpected error splitting '"+line+"' on '"+delim.charAt(0)+"'");
- }
- // TODO - report unused columns?
- // TODO - provide option to set unused variables ?
- } else {
+ if (lineValues.length == 0) {// i.e. EOF
if (getStopThread()) {
throw new JMeterStopThreadException("End of file detected");
}
Modified: jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java?rev=1384594&r1=1384593&r2=1384594&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java Thu Sep 13 23:00:47 2012
@@ -29,6 +29,7 @@ import org.apache.jmeter.services.FileSe
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jorphan.util.JMeterStopThreadException;
public class TestCVSDataSet extends JMeterTestCase {
@@ -166,6 +167,41 @@ public class TestCVSDataSet extends JMet
assertEquals("d1",threadVars.get("D|1"));
}
+ // Test CSV file with a header line
+ public void testHeaderQuotes(){
+ CSVDataSet csv = new CSVDataSet();
+ csv.setFilename(findTestPath("testfiles/testquoted.csv"));
+ csv.setDelimiter("|");
+ csv.setQuotedData(true);
+ csv.setRecycle(false);
+ csv.setStopThread(true);
+ assertNull(csv.getVariableNames());
+ csv.iterationStart(null);
+ assertNull(threadVars.get("a"));
+ assertEquals("a1",threadVars.get("A"));
+ assertEquals("b1",threadVars.get("B"));
+ assertEquals("c1",threadVars.get("C"));
+ assertEquals("d1",threadVars.get("D|1"));
+ csv.iterationStart(null);
+ assertNull(threadVars.get("a"));
+ assertEquals("a2",threadVars.get("A"));
+ assertEquals("b2",threadVars.get("B"));
+ assertEquals("c2",threadVars.get("C"));
+ assertEquals("d2",threadVars.get("D|1"));
+ csv.iterationStart(null);
+ assertNull(threadVars.get("a"));
+ assertEquals("a3",threadVars.get("A"));
+ assertEquals("b3",threadVars.get("B"));
+ assertEquals("c3",threadVars.get("C"));
+ assertEquals("d3",threadVars.get("D|1"));
+ try {
+ csv.iterationStart(null);
+ fail("Expected JMeterStopThreadException");
+ } catch (JMeterStopThreadException expected) {
+
+ }
+ }
+
private CSVDataSet initCSV(){
CSVDataSet csv = new CSVDataSet();
csv.setFilename(findTestPath("testfiles/test.csv"));
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1384594&r1=1384593&r2=1384594&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Sep 13 23:00:47 2012
@@ -216,6 +216,7 @@ Cookie Manager has now the default HC3.1
<li>Add support for HeapDump to the JMeter non-GUI and GUI client</li>
<li><bugzilla>53862</bugzilla> - Would be nice to have the JMeter Version available as a property</li>
<li><bugzilla>53806</bugzilla> - FileServer should provide direct access to the BufferedReader</li>
+<li><bugzilla>53807</bugzilla> - CSV Dataset does not handle embedded new lines in quoted data</li>
</ul>
<h2>Non-functional changes</h2>
Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1384594&r1=1384593&r2=1384594&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Sep 13 23:00:47 2012
@@ -3141,6 +3141,9 @@ The Comparison Assertion Visualizer show
Versions of JMeter after 2.3.4 support CSV files which have a header line defining the column names.
To enable this, leave the "Variable Names" field empty. The correct delimiter must be provided.
</p>
+ <p>
+ Versions of JMeter after 2.7 support CSV files with quoted data that includes new-lines.
+ </p>
<p>
By default, the file is only opened once, and each thread will use a different line from the file.
However the order in which lines are passed to threads depends on the order in which they execute,