Author: milamber
Date: Mon Aug 16 18:55:55 2010
New Revision: 986094
URL: http://svn.apache.org/viewvc?rev=986094&view=rev
Log:
Bug 49666 - CSV Header read as data after EOF
Modified:
jakarta/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
jakarta/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
jakarta/jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java
jakarta/jmeter/trunk/xdocs/changes.xml
Modified:
jakarta/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java?rev=986094&r1=986093&r2=986094&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
(original)
+++
jakarta/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
Mon Aug 16 18:55:55 2010
@@ -86,6 +86,8 @@ public class CSVDataSet extends ConfigTe
private transient String alias;
private transient String shareMode;
+
+ private boolean firstLineIsNames = false;
private Object readResolve(){
recycle = true;
@@ -121,6 +123,7 @@ public class CSVDataSet extends ConfigTe
String header = server.reserveFile(_fileName,
getFileEncoding(), alias, true);
try {
vars = CSVSaveService.csvSplitString(header,
getDelimiter().charAt(0));
+ firstLineIsNames = true;
} catch (IOException e) {
log.warn("Could not split CSV header line",e);
}
@@ -139,7 +142,7 @@ public class CSVDataSet extends ConfigTe
}
// TODO: fetch this once as per vars above?
JMeterVariables threadVars = context.getVariables();
- String line = server.readLine(alias,getRecycle());
+ String line = server.readLine(alias, getRecycle(),
firstLineIsNames);
if (line!=null) {// i.e. not EOF
String[] lineValues = getQuotedData() ?
CSVSaveService.csvSplitString(line, delim.charAt(0))
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java?rev=986094&r1=986093&r2=986094&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
(original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
Mon Aug 16 18:55:55 2010
@@ -181,15 +181,28 @@ public class FileServer {
return readLine(filename, true);
}
+ /**
+ * Get the next line of the named file, first line is name to false
+ *
+ * @param filename
+ * @param recycle - should file be restarted at EOF?
+ * @return String containing the next line in the file (null if EOF
reached and not recycle)
+ * @throws IOException
+ */
+ public String readLine(String filename, boolean recycle) throws
IOException {
+ return readLine(filename, recycle, false);
+ }
/**
* Get the next line of the named file.
*
* @param filename
* @param recycle - should file be restarted at EOF?
+ * @param firstLineIsNames - 1st line is fields names
* @return String containing the next line in the file (null if EOF
reached and not recycle)
* @throws IOException
*/
- public synchronized String readLine(String filename, boolean recycle)
throws IOException {
+ public synchronized String readLine(String filename, boolean recycle,
+ boolean firstLineIsNames) throws IOException {
FileEntry fileEntry = files.get(filename);
if (fileEntry != null) {
if (fileEntry.inputOutputObject == null) {
@@ -203,6 +216,10 @@ public class FileServer {
reader.close();
reader = createBufferedReader(fileEntry, filename);
fileEntry.inputOutputObject = reader;
+ if (firstLineIsNames) {
+ // read first line and forget
+ reader.readLine();
+ }
line = reader.readLine();
}
if (log.isDebugEnabled()) { log.debug("Read:"+line); }
Modified:
jakarta/jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java?rev=986094&r1=986093&r2=986094&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java
(original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/config/TestCVSDataSet.java
Mon Aug 16 18:55:55 2010
@@ -112,7 +112,26 @@ public class TestCVSDataSet extends JMet
assertEquals("c2",threadVars.get("C"));
assertEquals("d2",threadVars.get("D|1"));
}
-
+
+ // Test CSV file with a header line and recycle is true
+ public void testHeaderOpenAndRecycle(){
+ CSVDataSet csv = new CSVDataSet();
+ csv.setFilename("testfiles/testheader.csv");
+ csv.setDelimiter("|");
+ csv.setRecycle(true);
+ assertNull(csv.getVariableNames()); // read 1st line
+ // read 5 lines + restart to file begin
+ csv.iterationStart(null); // line 2
+ csv.iterationStart(null); // line 3
+ csv.iterationStart(null); // line 4
+ csv.iterationStart(null); // line 5
+ csv.iterationStart(null); // return to 2nd line (first line is names)
+ assertEquals("a1",threadVars.get("A"));
+ assertEquals("b1",threadVars.get("B"));
+ assertEquals("c1",threadVars.get("C"));
+ assertEquals("d1",threadVars.get("D|1"));
+ }
+
private CSVDataSet initCSV(){
CSVDataSet csv = new CSVDataSet();
csv.setFilename("testfiles/test.csv");
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=986094&r1=986093&r2=986094&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Mon Aug 16 18:55:55 2010
@@ -97,6 +97,7 @@ To override the default local language f
<h3>General</h3>
<ul>
<li>Bug 49734 - Null pointer exception on stop Threads command (Run>Stop)</li>
+<li>Bug 49666 - CSV Header read as data after EOF</li>
</ul>
<!-- ==================================================== -->
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]