You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/12/23 21:31:40 UTC
svn commit: r1819182 - in /jmeter/trunk:
src/core/org/apache/jmeter/report/core/CsvSampleReader.java
test/src/org/apache/jmeter/report/core/CsvSampleReaderTest.java
xdocs/changes.xml
Author: pmouawad
Date: Sat Dec 23 21:31:39 2017
New Revision: 1819182
URL: http://svn.apache.org/viewvc?rev=1819182&view=rev
Log:
Bug 61925 - CsvSampleReader does not increment row in nextSample()
Contributed by Graham Russell
This closes #368
Bugzilla Id: 61925
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/core/CsvSampleReader.java
jmeter/trunk/test/src/org/apache/jmeter/report/core/CsvSampleReaderTest.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=1819182&r1=1819181&r2=1819182&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 Sat Dec 23 21:31:39 2017
@@ -41,48 +41,40 @@ import org.slf4j.LoggerFactory;
* Reader class for reading CSV files.
* <p>
* Handles {@link SampleMetadata} reading and sample extraction.
- * </p>
- *
+ *
* @since 3.0
*/
public class CsvSampleReader implements Closeable{
private static final Logger log = LoggerFactory.getLogger(CsvSampleReader.class);
- private static final int BUF_SIZE = 1024 * 1024;
+ private static final int BUF_SIZE = 1024 * 1024;
private static final String CHARSET = SaveService.getFileEncoding(StandardCharsets.UTF_8.displayName());
-
private static final char DEFAULT_SEPARATOR =
- // We cannot use JMeterUtils#getPropDefault as it applies a trim on value
+ // Cannot use JMeterUtils#getPropDefault as it trims the value
JMeterUtils.getDelimiter(
- JMeterUtils.getJMeterProperties().getProperty(SampleSaveConfiguration.DEFAULT_DELIMITER_PROP, SampleSaveConfiguration.DEFAULT_DELIMITER)).charAt(0);
+ JMeterUtils.getJMeterProperties().getProperty(
+ SampleSaveConfiguration.DEFAULT_DELIMITER_PROP,
+ SampleSaveConfiguration.DEFAULT_DELIMITER))
+ .charAt(0);
private File file;
-
private InputStream fis;
private Reader isr;
private BufferedReader reader;
-
private char separator;
-
private long row;
-
private SampleMetadata metadata;
-
private int columnCount;
-
private Sample lastSampleRead;
/**
* Instantiates a new csv sample reader.
*
- * @param inputFile
- * the input file (must not be {@code null})
- * @param separator
- * the separator
- * @param useSaveSampleCfg
- * indicates whether the reader uses jmeter
- * SampleSaveConfiguration to define metadata
+ * @param inputFile the input file (must not be {@code null})
+ * @param separator the separator
+ * @param useSaveSampleCfg indicates whether the reader uses jmeter
+ * SampleSaveConfiguration to define metadata
*/
public CsvSampleReader(File inputFile, char separator, boolean useSaveSampleCfg) {
this(inputFile, null, separator, useSaveSampleCfg);
@@ -91,10 +83,8 @@ public class CsvSampleReader implements
/**
* Instantiates a new csv sample reader.
*
- * @param inputFile
- * the input file (must not be {@code null})
- * @param metadata
- * the metadata
+ * @param inputFile the input file (must not be {@code null})
+ * @param metadata the metadata
*/
public CsvSampleReader(File inputFile, SampleMetadata metadata) {
this(inputFile, metadata, DEFAULT_SEPARATOR, false);
@@ -134,14 +124,13 @@ public class CsvSampleReader implements
SampleMetadata result;
// Read first line
String line = reader.readLine();
- if(line == null) {
+ if (line == null) {
throw new IllegalArgumentException("File is empty");
}
- // When we can use sample save config and there is no header in csv
- // file
+ // When we can use sample save config and there is no header in csv file
if (useSaveSampleCfg
- && CSVSaveService.getSampleSaveConfiguration(line,
- file.getAbsolutePath()) == null) {
+ && CSVSaveService.getSampleSaveConfiguration(
+ line, file.getAbsolutePath()) == null) {
// Build metadata from default save config
if (log.isWarnEnabled()) {
log.warn(
@@ -149,7 +138,7 @@ public class CsvSampleReader implements
+ "ensure the jmeter.save.saveservice.* properties are the same as when the CSV file was created or the file may be read incorrectly",
file.getAbsolutePath());
}
- System.err.println("File '"+file.getAbsolutePath()+"' does not contain the field names header, "
+ 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");
result = new SampleMetadata(
SampleSaveConfiguration.staticConfig());
@@ -164,11 +153,6 @@ public class CsvSampleReader implements
}
}
- /**
- * Gets the metadata.
- *
- * @return the metadata
- */
public SampleMetadata getMetadata() {
return metadata;
}
@@ -183,7 +167,7 @@ public class CsvSampleReader implements
throw new SampleException("Mismatch between expected number of columns:"+columnCount+" and columns in CSV file:"+data.length+
", check your jmeter.save.saveservice.* configuration");
}
- sample = new Sample(row, metadata, data);
+ sample = new Sample(row++, metadata, data);
}
return sample;
} catch (IOException e) {
@@ -193,8 +177,6 @@ public class CsvSampleReader implements
/**
* Gets next sample from the file.
- *
- * @return the sample
*/
public Sample readSample() {
Sample out = lastSampleRead;
@@ -204,8 +186,6 @@ public class CsvSampleReader implements
/**
* Gets next sample from file but keep the reading file position.
- *
- * @return the sample
*/
public Sample peek() {
return lastSampleRead;
@@ -213,16 +193,11 @@ public class CsvSampleReader implements
/**
* Indicates whether the file contains more samples
- *
- * @return true, if the file contains more samples
*/
public boolean hasNext() {
return lastSampleRead != null;
}
- /**
- * Close the reader.
- */
@Override
public void close() {
JOrphanUtils.closeQuietly(isr);
Modified: jmeter/trunk/test/src/org/apache/jmeter/report/core/CsvSampleReaderTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/core/CsvSampleReaderTest.java?rev=1819182&r1=1819181&r2=1819182&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/core/CsvSampleReaderTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/core/CsvSampleReaderTest.java Sat Dec 23 21:31:39 2017
@@ -23,14 +23,13 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
-import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jmeter.junit.JMeterTestCase;
import org.hamcrest.CoreMatchers;
-import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-public class CsvSampleReaderTest {
+public class CsvSampleReaderTest extends JMeterTestCase {
private static final int NR_ROWS = 100;
private File tempCsv;
@@ -38,29 +37,20 @@ public class CsvSampleReaderTest {
@Before
public void setUp() throws IOException {
- // We have to initialize JMeterUtils
- if (JMeterUtils.getJMeterHome() == null) {
- JMeterUtils.setJMeterHome(System.getenv("JMETER_HOME"));
- }
- JMeterUtils.loadJMeterProperties(
- JMeterUtils.getJMeterBinDir() + "/jmeter.properties");
tempCsv = File.createTempFile("samplecsv", ".csv");
+ tempCsv.deleteOnExit();
try (CsvSampleWriter writer = new CsvSampleWriter(tempCsv, metadata)) {
writer.setSeparator(',');
for (long i = 0; i < NR_ROWS; i++) {
- writer.write(new SampleBuilder(metadata).add(i).add("a" + i)
- .build());
+ final Sample sample = new SampleBuilder(metadata)
+ .add(i)
+ .add("a" + i)
+ .build();
+ writer.write(sample);
}
}
}
- @After
- public void tearDown() {
- if (tempCsv.exists()) {
- tempCsv.delete();
- }
- }
-
@Test(expected = IllegalArgumentException.class)
public void testConstructorWithInvalidFile() throws Exception {
try (CsvSampleReader csv = new CsvSampleReader(
@@ -103,11 +93,12 @@ public class CsvSampleReaderTest {
}
@Test
- public void testHasNext() {
+ public void testHasNextAndReadSample() {
try (CsvSampleReader reader = new CsvSampleReader(tempCsv, metadata)) {
for (long i = 0; i < NR_ROWS; i++) {
Assert.assertTrue(reader.hasNext());
- reader.readSample();
+ final Sample sample = reader.readSample();
+ Assert.assertEquals(i, sample.getSampleRow());
}
Assert.assertFalse(reader.hasNext());
}
@@ -120,7 +111,7 @@ public class CsvSampleReaderTest {
try {
reader.readSample();
fail("Stream should be closed.");
- } catch (SampleException e) {
+ } catch (SampleException expected) {
// All is well
}
}
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1819182&r1=1819181&r2=1819182&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Dec 23 21:31:39 2017
@@ -262,6 +262,7 @@ Summary
<ul>
<li><bug>61807</bug>Web Report : fix error in <code>getTop5ErrorMetrics</code>. Contributed by Graham Russell (graham at ham1.co.uk)</li>
<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>
</ul>
<h3>General</h3>