Skip to content

Commit

Permalink
Fixed file creation issue. Now plugin creates CSV file when there is …
Browse files Browse the repository at this point in the history
…data to write.
  • Loading branch information
Mikhail.Derevyanko authored and Mikhail.Derevyanko committed Feb 16, 2022
1 parent a858524 commit 37b98e0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
}

sourceCompatibility = 11
version = '1.0'
version = '1.1'
def title = 'JMeterCSVListener'
def archiveName = 'jmeter-plugin-csv-listener'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void handleSampleResults(List<SampleResult> sampleResults, BackendListene
Result resultToWrite = ResultController.process(this.resultContext, result);

if (resultToWrite != null) {
String separator = this.resultContext.getBackendListenerContext().getParameter(KEY_SEPARATOR);

String resultRow = ResultRow.getRow(this.resultContext, result);
Writer.getInstance(this.resultContext, LOGGER).collectData(resultRow);
}
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/org/md/jmeter/csv/results/writer/csv/Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,20 @@ public synchronized void close() {
*/
public synchronized void writeData() {

if (!this.isHeaderWritten)
{
this.writeHeader();
this.isHeaderWritten = true;
}

if (this.results.size() != 0) {
if (this.results.size() != 0) {
try {

long start = System.currentTimeMillis();
// Write header and setup the file while the first things writing - one time.
if (!this.isHeaderWritten)
{
this.writeHeader();
this.isHeaderWritten = true;
}

String results = getString(this.results);
this.writeStrings(Objects.requireNonNull(results));

long start = System.currentTimeMillis();
this.writeStrings(Objects.requireNonNull(results));
long end = System.currentTimeMillis();

LOGGER.info("Data has been written successfully, batch with size is --> " + this.results.size() + ", elapsed time is --> " + (end - start) + " ms");
Expand All @@ -119,9 +120,7 @@ public synchronized void writeData() {
LOGGER.debug("Results have been cleaned");

} catch (Exception e) {

LOGGER.error("Error has occurred, batch with size " + this.results.size() + " was not imported, see the details --> " + e.getMessage());

}
}
}
Expand All @@ -135,7 +134,6 @@ public synchronized void setupClient() {
LOGGER.info("The Path : " + path + " is going to be used.");

this.csvFile = new File(path);

}

/**
Expand All @@ -151,7 +149,6 @@ private synchronized void writeHeader()
this.writeStrings(header);
}


/**
* Checks the batch size.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setBody(String body) {

/**
* Gets the assertion error message in case of error.
* @return theassertion error message in case of error.
* @return the assertion error message in case of error.
*/
public String getAssertionError() {
return this.assertionError;
Expand Down

0 comments on commit 37b98e0

Please # to comment.