jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1820208 - in /jmeter/trunk: src/core/org/apache/jmeter/report/core/CsvSampleReader.java xdocs/changes.xml
Date Thu, 04 Jan 2018 20:45:49 GMT
Author: pmouawad
Date: Thu Jan  4 20:45:49 2018
New Revision: 1820208

URL: http://svn.apache.org/viewvc?rev=1820208&view=rev
Log:
Bug 61899 - Report Generation : When "jmeter.save.saveservice.print_field_names" is false
and sample_variables are set report generation fails
Contributed by UbikLoadPack
Bugzilla Id: 61899

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/report/core/CsvSampleReader.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/report/core/CsvSampleReader.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/core/CsvSampleReader.java?rev=1820208&r1=1820207&r2=1820208&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/core/CsvSampleReader.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/core/CsvSampleReader.java Thu Jan  4 20:45:49
2018
@@ -29,6 +29,8 @@ import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.jmeter.samplers.SampleEvent;
 import org.apache.jmeter.samplers.SampleSaveConfiguration;
 import org.apache.jmeter.save.CSVSaveService;
 import org.apache.jmeter.save.SaveService;
@@ -37,6 +39,7 @@ import org.apache.jorphan.util.JOrphanUt
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * Reader class for reading CSV files.
  * <p>
@@ -67,6 +70,10 @@ public class CsvSampleReader implements
     private SampleMetadata metadata;
     private int columnCount;
     private Sample lastSampleRead;
+    /**
+     * Number of sample_variables if csv file has no header
+     */
+    private int numberOfSampleVariablesInCsv;
 
     /**
      * Instantiates a new csv sample reader.
@@ -107,19 +114,28 @@ public class CsvSampleReader implements
             JOrphanUtils.closeQuietly(this.reader);
             throw new SampleException("Could not create file reader !", ex);
         }
-
+        boolean usingHeadersInCsv = true;
         if (metadata == null) {
-            this.metadata = readMetadata(separator, useSaveSampleCfg);
+            Pair<Boolean, SampleMetadata> localMd = readMetadata(separator, useSaveSampleCfg);
+            this.metadata = localMd.getRight();
+            usingHeadersInCsv = localMd.getLeft();
         } else {
             this.metadata = metadata;
         }
         this.columnCount = this.metadata.getColumnCount();
         this.separator = this.metadata.getSeparator();
         this.row = 0;
+        if(!usingHeadersInCsv) {
+            String vars = JMeterUtils.getProperty(SampleEvent.SAMPLE_VARIABLES);
+            String[] variableNames=vars != null ? vars.split(",") : new String[0];
+            this.numberOfSampleVariablesInCsv = variableNames.length;
+        } else {
+            this.numberOfSampleVariablesInCsv = 0;
+        }
         this.lastSampleRead = nextSample();
     }
 
-    private SampleMetadata readMetadata(char separator, boolean useSaveSampleCfg) {
+    private Pair<Boolean, SampleMetadata> readMetadata(char separator, boolean useSaveSampleCfg)
{
         try {
             SampleMetadata result;
             // Read first line
@@ -127,6 +143,7 @@ public class CsvSampleReader implements
             if (line == null) {
                 throw new IllegalArgumentException("File is empty");
             }
+            boolean hasHeaders = false;
             // When we can use sample save config and there is no header in csv file
             if (useSaveSampleCfg
                     && CSVSaveService.getSampleSaveConfiguration(
@@ -135,19 +152,24 @@ public class CsvSampleReader implements
                 if (log.isWarnEnabled()) {
                     log.warn(
                             "File '{}' does not contain the field names header, "
-                                    + "ensure the jmeter.save.saveservice.* properties are
the same as when the CSV file was created or the file may be read incorrectly",
+                                    + "ensure the jmeter.save.saveservice.* properties are
the same "
+                                    + "as when the CSV file was created or the file may be
read incorrectly "
+                                    + "when generating report",
                             file.getAbsolutePath());
                 }
                 System.out.println("File '"+file.getAbsolutePath()+"' does not contain the
field names header, "
-                        + "ensure the jmeter.save.saveservice.* properties are the same as
when the CSV file was created or the file may be read incorrectly");
+                        + "ensure the jmeter.save.saveservice.* properties are the same "
+                        + "as when the CSV file was created or the file may be read incorrectly
"
+                        + "when generating report");
                 result = new SampleMetadata(
                         SampleSaveConfiguration.staticConfig());
 
             } else {
                 // Build metadata from headers
                 result = new SampleMetaDataParser(separator).parse(line);
+                hasHeaders = true;
             }
-            return result;
+            return Pair.of(hasHeaders, result);
         } catch (Exception e) {
             throw new SampleException("Could not read metadata !", e);
         }
@@ -163,9 +185,9 @@ public class CsvSampleReader implements
             data = CSVSaveService.csvReadFile(reader, separator);
             Sample sample = null;
             if (data.length > 0) {
-                if (data.length != columnCount) {
+                if (data.length != columnCount+numberOfSampleVariablesInCsv) {
                     throw new SampleException("Mismatch between expected number of columns:"+columnCount+"
and columns in CSV file:"+data.length+
-                            ", check your jmeter.save.saveservice.* configuration");
+                            ", check your jmeter.save.saveservice.* configuration or check
line is complete");
                 }
                 sample = new Sample(row++, metadata, data);
             }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1820208&r1=1820207&r2=1820208&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Jan  4 20:45:49 2018
@@ -270,6 +270,7 @@ Summary
     <li><bug>61900</bug>Report Generator : Report generation fails if separator
is a regex reserved char like <code>|</code></li>
     <li><bug>61925</bug>CsvSampleReader does not increment row in nextSample().
Contributed by Graham Russell (graham at ham1.co.uk)</li>
     <li><bug>61956</bug>Report Generation : <code>-f</code>
of <code>-forceDeleteResultFile</code> option does not work. Contributed by Ubik
Load Pack (support at ubikloadpack.com)</li>
+    <li><bug>61899</bug>Report Generation : When <code>jmeter.save.saveservice.print_field_names</code>
is false and <code>sample_variables</code> are set report generation fails. Contributed
by Ubik Load Pack (support at ubikloadpack.com)</li>
 </ul>
 
 <h3>General</h3>



Mime
View raw message