Author: pmouawad
Date: Thu May 12 19:13:17 2016
New Revision: 1743545
URL: http://svn.apache.org/viewvc?rev=1743545&view=rev
Log:
Bug 59523 - Report Generator : NormalizerSampleConsumer uses a different default format for
timestamp than JMeter default
Bugzilla Id: 59523
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java
jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java?rev=1743545&r1=1743544&r2=1743545&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java
(original)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java
Thu May 12 19:13:17 2016
@@ -23,28 +23,44 @@ import java.util.Date;
import org.apache.jmeter.report.core.Sample;
import org.apache.jmeter.report.core.SampleException;
import org.apache.jmeter.report.core.SampleMetadata;
-import org.apache.jmeter.report.processor.AbstractSampleConsumer;
+import org.apache.jmeter.samplers.SampleSaveConfiguration;
import org.apache.jmeter.save.CSVSaveService;
import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
/**
- * Consume samples using the JMeter timestamp property (defaulting to HH:mm:ss) and reproduce
them as a long
+ * Consume samples using the JMeter timestamp property (defaulting to {@link SampleSaveConfiguration#MILLISECONDS})
and reproduce them as a long
* value (for faster treatment later in the consuming chain).
*
* @since 3.0
*/
public class NormalizerSampleConsumer extends AbstractSampleConsumer {
- private static final String PARSE_TIMESTAMP_EXCEPTION_MESSAGE = "Could not parse timeStamp
<%s> on sample %s";
+ private static final Logger log = LoggingManager.getLoggerForClass();
- private static final String DEFAULT_DATE_FORMAT = "HH:mm:ss"; // $NON-NLS-1$
+ private static final String TIMESTAMP_FORMAT =
+ JMeterUtils.getPropDefault(
+ "jmeter.save.saveservice.timestamp_format", // $NON-NLS-1$
+ SampleSaveConfiguration.MILLISECONDS);
+ private static final String PARSE_TIMESTAMP_EXCEPTION_MESSAGE =
+ "Could not parse timeStamp <%s> using format defined by property jmeter.save.saveservice.timestamp_format=%s
on sample %s ";
+
+ /**
+ * index of the timeStamp column
+ */
private int timestamp;
- private final SimpleDateFormat df = new SimpleDateFormat(
- JMeterUtils.getPropDefault(
- "jmeter.save.saveservice.timestamp_format", // $NON-NLS-1$
- DEFAULT_DATE_FORMAT));
+ /**
+ * is format ms
+ */
+ private boolean isMillisFormat;
+
+ /**
+ * null if format is isMillisFormat is true
+ */
+ private final SimpleDateFormat dateFormat = createFormatter();
private SampleMetadata sampleMetadata;
@@ -56,21 +72,39 @@ public class NormalizerSampleConsumer ex
startProducing();
}
+ /**
+ * @return null if format is ms or a SimpleDateFormat
+ * @throws SampleException is format is none
+ */
+ private SimpleDateFormat createFormatter() {
+ if(SampleSaveConfiguration.NONE.equalsIgnoreCase(TIMESTAMP_FORMAT)) {
+ throw new SampleException("'none' format for 'jmeter.save.saveservice.timestamp_format'
property is not accepted for report generation");
+ }
+ log.info("Using format:"+TIMESTAMP_FORMAT+" to parse timeStamp field");
+
+ isMillisFormat = SampleSaveConfiguration.MILLISECONDS.equalsIgnoreCase(TIMESTAMP_FORMAT);
+ SimpleDateFormat formatter = null;
+ // Prepare for a pretty date
+ if (!isMillisFormat) {
+ formatter = new SimpleDateFormat(TIMESTAMP_FORMAT);
+ }
+ return formatter;
+ }
+
@Override
public void consume(Sample s, int channel) {
Date date = null;
try {
String tStr = s.getData(timestamp);
- try {
- // Try to parse the timestamp assuming is a long
+ if(isMillisFormat) {
date = new Date(Long.parseLong(tStr));
- } catch (NumberFormatException ex) {
- date = df.parse(tStr);
+ } else {
+ date = dateFormat.parse(tStr);
}
} catch (Exception e) {
throw new SampleException(String.format(
PARSE_TIMESTAMP_EXCEPTION_MESSAGE, s.getData(timestamp),
- s.toString()), e);
+ TIMESTAMP_FORMAT, s.toString()), e);
}
long time = date.getTime();
int cc = sampleMetadata.getColumnCount();
Modified: jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java?rev=1743545&r1=1743544&r2=1743545&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java Thu May
12 19:13:17 2016
@@ -93,10 +93,10 @@ public class SampleSaveConfiguration imp
private static final String FALSE = "false"; // $NON_NLS-1$
/** A properties file indicator for milliseconds. * */
- private static final String MILLISECONDS = "ms"; // $NON_NLS-1$
+ public static final String MILLISECONDS = "ms"; // $NON_NLS-1$
/** A properties file indicator for none. * */
- private static final String NONE = "none"; // $NON_NLS-1$
+ public static final String NONE = "none"; // $NON_NLS-1$
/** A properties file indicator for the first of a series. * */
private static final String FIRST = "first"; // $NON_NLS-1$
@@ -368,6 +368,7 @@ public class SampleSaveConfiguration imp
_printMilliseconds = MILLISECONDS.equalsIgnoreCase(_timeStampFormat);
// Prepare for a pretty date
+ // FIXME Can _timeStampFormat be null ? it does not appear to me .
if (!_printMilliseconds && !NONE.equalsIgnoreCase(_timeStampFormat) &&
(_timeStampFormat != null)) {
_formatter = new SimpleDateFormat(_timeStampFormat);
} else {
|