apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.3k stars 2.09k forks source link

CSV Data Set Configuration does not resolve default delimiter for header parsing when variables field is empty #2586

Closed asfimport closed 13 years ago

asfimport commented 13 years ago

Roman Bargezi (Bug 51988): Build CSVDataSet.java 1091505 4/12/11

When not specifying a delimiter the default delimiter for data lines is ",". For the header lines, this default is not used which results in an StringIndexOutOfBoundsException

Version: Nightly Severity: minor OS: All

Duplicates:

asfimport commented 13 years ago

Roman Bargezi (migrated from Bugzilla): Created attachment Bug51988.patch: Proposed patch

Bug51988.patch ````diff Index: CSVDataSet.java =================================================================== --- CSVDataSet.java (revision 1179987) +++ CSVDataSet.java (working copy) @@ -100,74 +102,74 @@ public void iterationStart(LoopIterationEvent iterEvent) { FileServer server = FileServer.getFileServer(); final JMeterContext context = getThreadContext(); + String delim = getDelimiter(); + if (delim.startsWith("\\t")) { // $NON-NLS-1$ + delim = "\t";// Make it easier to enter a Tab // $NON-NLS-1$ + } else if (delim.length() == 0) { + log.warn("Empty delimiter converted to ','"); + delim = ","; + } if (vars == null) { String _fileName = getFilename(); String mode = getShareMode(); int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode); - switch(modeInt){ - case CSVDataSetBeanInfo.SHARE_ALL: - alias = _fileName; - break; - case CSVDataSetBeanInfo.SHARE_GROUP: - alias = _fileName+"@"+System.identityHashCode(context.getThreadGroup()); - break; - case CSVDataSetBeanInfo.SHARE_THREAD: - alias = _fileName+"@"+System.identityHashCode(context.getThread()); - break; - default: - alias = _fileName+"@"+mode; // user-specified key - break; + switch (modeInt) { + case CSVDataSetBeanInfo.SHARE_ALL: + alias = _fileName; + break; + case CSVDataSetBeanInfo.SHARE_GROUP: + alias = _fileName + "@" + System.identityHashCode(context.getThreadGroup()); + break; + case CSVDataSetBeanInfo.SHARE_THREAD: + alias = _fileName + "@" + System.identityHashCode(context.getThread()); + break; + default: + alias = _fileName + "@" + mode; // user-specified key + break; } final String names = getVariableNames(); - if (names == null || names.length()==0) { + if (names == null || names.length() == 0) { String header = server.reserveFile(_fileName, getFileEncoding(), alias, true); try { - vars = CSVSaveService.csvSplitString(header, getDelimiter().charAt(0)); + vars = CSVSaveService.csvSplitString(header, delim.charAt(0)); firstLineIsNames = true; } catch (IOException e) { - log.warn("Could not split CSV header line",e); + log.warn("Could not split CSV header line", e); } } else { server.reserveFile(_fileName, getFileEncoding(), alias); vars = JOrphanUtils.split(names, ","); // $NON-NLS-1$ } } - String delim = getDelimiter(); - if (delim.equals("\\t")) { // $NON-NLS-1$ - delim = "\t";// Make it easier to enter a Tab // $NON-NLS-1$ - } else if (delim.length()==0){ - log.warn("Empty delimiter converted to ','"); - delim=","; - } - // TODO: fetch this once as per vars above? - JMeterVariables threadVars = context.getVariables(); - String line = null; + // TODO: fetch this once as per vars above? + JMeterVariables threadVars = context.getVariables(); + String line = null; + try { + line = server.readLine(alias, getRecycle(), firstLineIsNames); + } catch (IOException e) { // treat the same as EOF + log.error(e.toString()); + } + if (line != null) {// i.e. not EOF try { - line = server.readLine(alias, getRecycle(), firstLineIsNames); - } 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)+"'"); + 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]); } - // TODO - report unused columns? - // TODO - provide option to set unused variables ? - } else { - if (getStopThread()) { - throw new JMeterStopThreadException("End of file detected"); - } - for (int a = 0; a < vars.length ; a++) { - threadVars.put(vars[a], EOFVALUE); - } + } 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 (getStopThread()) { + throw new JMeterStopThreadException("End of file detected"); + } + for (int a = 0; a < vars.length ; a++) { + threadVars.put(vars[a], EOFVALUE); + } + } } /** ````
asfimport commented 13 years ago

@pmouawad (migrated from Bugzilla): Created attachment BUG_51988.jmx: Test Plan

BUG_51988.jmx ````xml false false /data/jmeter/test.csv false true All threads false continue false 1 1 1 1317984849000 1317984849000 false www.ubik-ingenierie.com /toto=${toto} GET true false true false HttpClient4 false false saveConfig true true true true true true true false true true false false true false false false false false 0 true ````
asfimport commented 13 years ago

@pmouawad (migrated from Bugzilla): Will generate exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:686) at org.apache.jmeter.config.CSVDataSet.iterationStart(CSVDataSet.java:125) at org.apache.jmeter.control.GenericController.fireIterationStart(GenericController.java:373) at org.apache.jmeter.control.GenericController.fireIterEvents(GenericController.java:359) at org.apache.jmeter.control.GenericController.next(GenericController.java:131) at org.apache.jmeter.control.LoopController.next(LoopController.java:108) at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:75) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) at java.lang.Thread.run(Thread.java:680)

Created attachment test.csv: CSV file for Test plan

test.csv ```` column1,column2 1,2````
asfimport commented 13 years ago

@pmouawad (migrated from Bugzilla): Created attachment BUG_51988.jmx: Test plan

BUG_51988.jmx ````xml false false /data/jmeter/test.csv false true All threads false continue false 1 1 1 1317984849000 1317984849000 false Sleep_Time 100 = Sleep_Mask 0xFF = Label ${column1}-${column2} = ResponseCode = ResponseMessage = Status OK = SamplerData = ResultData = org.apache.jmeter.protocol.java.test.JavaTest false saveConfig true true true true true true true false true true false false true false false false false false 0 true ````
asfimport commented 13 years ago

@pmouawad (migrated from Bugzilla): Thanks, fix applied. Next time please submit a Test plan that illustrates the issue.

Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java jakarta/jmeter/trunk/xdocs/changes.xml

Regards. Philippe.