View | Details | Raw Unified | Return to bug 60830
Collapse All | Expand All

(-)src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java (-6 / +8 lines)
Lines 31-36 Link Here
31
import java.util.Properties;
31
import java.util.Properties;
32
32
33
import org.apache.commons.lang3.CharUtils;
33
import org.apache.commons.lang3.CharUtils;
34
import org.apache.commons.lang3.time.FastDateFormat;
34
import org.apache.jmeter.save.CSVSaveService;
35
import org.apache.jmeter.save.CSVSaveService;
35
import org.apache.jmeter.testelement.TestPlan;
36
import org.apache.jmeter.testelement.TestPlan;
36
import org.apache.jmeter.util.JMeterUtils;
37
import org.apache.jmeter.util.JMeterUtils;
Lines 276-282 Link Here
276
277
277
    private static final boolean SAMPLE_COUNT;
278
    private static final boolean SAMPLE_COUNT;
278
279
279
    private static final DateFormat DATE_FORMATTER;
280
    private static final FastDateFormat DATE_FORMATTER;
280
281
281
    /**
282
    /**
282
     * The string used to separate fields when stored to disk, for example, the
283
     * The string used to separate fields when stored to disk, for example, the
Lines 353-359 Link Here
353
        // Prepare for a pretty date
354
        // Prepare for a pretty date
354
        // FIXME Can TIMESTAMP_FORMAT be null ? it does not appear to me .
355
        // FIXME Can TIMESTAMP_FORMAT be null ? it does not appear to me .
355
        if (!PRINT_MILLISECONDS && !NONE.equalsIgnoreCase(TIMESTAMP_FORMAT) && (TIMESTAMP_FORMAT != null)) {
356
        if (!PRINT_MILLISECONDS && !NONE.equalsIgnoreCase(TIMESTAMP_FORMAT) && (TIMESTAMP_FORMAT != null)) {
356
            DATE_FORMATTER = new SimpleDateFormat(TIMESTAMP_FORMAT);
357
            DATE_FORMATTER = FastDateFormat.getInstance(TIMESTAMP_FORMAT);
357
        } else {
358
        } else {
358
            DATE_FORMATTER = null;
359
            DATE_FORMATTER = null;
359
        }
360
        }
Lines 441-447 Link Here
441
    private boolean printMilliseconds = PRINT_MILLISECONDS;
442
    private boolean printMilliseconds = PRINT_MILLISECONDS;
442
443
443
    /** A formatter for the time stamp. */
444
    /** A formatter for the time stamp. */
444
    private transient DateFormat formatter = DATE_FORMATTER;
445
    private transient FastDateFormat formatter = DATE_FORMATTER;
445
    /* Make transient as we don't want to save the SimpleDataFormat class
446
    /* Make transient as we don't want to save the SimpleDataFormat class
446
     * Also, there's currently no way to change the value via the GUI, so changing it
447
     * Also, there's currently no way to change the value via the GUI, so changing it
447
     * later means editting the JMX, or recreating the Listener.
448
     * later means editting the JMX, or recreating the Listener.
Lines 581-587 Link Here
581
        try {
582
        try {
582
            SampleSaveConfiguration clone = (SampleSaveConfiguration)super.clone();
583
            SampleSaveConfiguration clone = (SampleSaveConfiguration)super.clone();
583
            if(this.formatter != null) {
584
            if(this.formatter != null) {
584
                clone.formatter = (SimpleDateFormat)this.formatter.clone();
585
                clone.formatter = (FastDateFormat)this.formatter.clone();
585
            }
586
            }
586
            return clone;
587
            return clone;
587
        }
588
        }
Lines 907-919 Link Here
907
908
908
    ///////////////// End of standard field accessors /////////////////////
909
    ///////////////// End of standard field accessors /////////////////////
909
910
911
    
910
    /**
912
    /**
911
     * Intended for use by CsvSaveService (and test cases)
913
     * Intended for use by CsvSaveService (and test cases)
912
     * @param fmt
914
     * @param fmt
913
     *            format of the date to be saved. If <code>null</code>
915
     *            format of the date to be saved. If <code>null</code>
914
     *            milliseconds since epoch will be printed
916
     *            milliseconds since epoch will be printed
915
     */
917
     */
916
    public void setFormatter(DateFormat fmt){
918
    public void setFastDateFormater(FastDateFormat fmt){
917
        printMilliseconds = fmt == null; // maintain relationship
919
        printMilliseconds = fmt == null; // maintain relationship
918
        formatter = fmt;
920
        formatter = fmt;
919
    }
921
    }
Lines 922-928 Link Here
922
        return printMilliseconds;
924
        return printMilliseconds;
923
    }
925
    }
924
926
925
    public DateFormat formatter() {
927
    public FastDateFormat threadSafeFormatter() {
926
        return formatter;
928
        return formatter;
927
    }
929
    }
928
930
(-)src/core/org/apache/jmeter/save/CSVSaveService.java (-8 / +7 lines)
Lines 30-36 Link Here
30
import java.io.Writer;
30
import java.io.Writer;
31
import java.nio.charset.StandardCharsets;
31
import java.nio.charset.StandardCharsets;
32
import java.text.ParseException;
32
import java.text.ParseException;
33
import java.text.SimpleDateFormat;
34
import java.util.ArrayList;
33
import java.util.ArrayList;
35
import java.util.Date;
34
import java.util.Date;
36
import java.util.List;
35
import java.util.List;
Lines 40-45 Link Here
40
import org.apache.commons.collections.map.LinkedMap;
39
import org.apache.commons.collections.map.LinkedMap;
41
import org.apache.commons.lang3.CharUtils;
40
import org.apache.commons.lang3.CharUtils;
42
import org.apache.commons.lang3.StringUtils;
41
import org.apache.commons.lang3.StringUtils;
42
import org.apache.commons.lang3.time.FastDateFormat;
43
import org.apache.jmeter.assertions.AssertionResult;
43
import org.apache.jmeter.assertions.AssertionResult;
44
import org.apache.jmeter.reporters.ResultCollector;
44
import org.apache.jmeter.reporters.ResultCollector;
45
import org.apache.jmeter.samplers.SampleEvent;
45
import org.apache.jmeter.samplers.SampleEvent;
Lines 214-228 Link Here
214
                        log.warn("Cannot parse timestamp: '{}'", text);
214
                        log.warn("Cannot parse timestamp: '{}'", text);
215
                        boolean foundMatch = false;
215
                        boolean foundMatch = false;
216
                        for(String fmt : DATE_FORMAT_STRINGS) {
216
                        for(String fmt : DATE_FORMAT_STRINGS) {
217
                            SimpleDateFormat dateFormat = new SimpleDateFormat(fmt);
217
                            FastDateFormat dateFormat = FastDateFormat.getInstance(fmt);
218
                            dateFormat.setLenient(false);
219
                            try {
218
                            try {
220
                                Date stamp = dateFormat.parse(text);
219
                                Date stamp = dateFormat.parse(text);
221
                                timeStamp = stamp.getTime();
220
                                timeStamp = stamp.getTime();
222
                                // method is only ever called from one thread at a time
221
                                // method is only ever called from one thread at a time
223
                                // so it's OK to use a static DateFormat
222
                                // so it's OK to use a static DateFormat
224
                                log.warn("Setting date format to: {}", fmt);
223
                                log.warn("Setting date format to: {}", fmt);
225
                                saveConfig.setFormatter(dateFormat);
224
                                saveConfig.setFastDateFormater(dateFormat);
226
                                foundMatch = true;
225
                                foundMatch = true;
227
                                break;
226
                                break;
228
                            } catch (ParseException pe) {
227
                            } catch (ParseException pe) {
Lines 233-240 Link Here
233
                            throw new ParseException("No date-time format found matching "+text,-1);
232
                            throw new ParseException("No date-time format found matching "+text,-1);
234
                        }
233
                        }
235
                    }
234
                    }
236
                } else if (saveConfig.formatter() != null) {
235
                } else if (saveConfig.threadSafeFormatter() != null) {
237
                    Date stamp = saveConfig.formatter().parse(text);
236
                    Date stamp = saveConfig.threadSafeFormatter().parse(text);
238
                    timeStamp = stamp.getTime();
237
                    timeStamp = stamp.getTime();
239
                } else { // can this happen?
238
                } else { // can this happen?
240
                    final String msg = "Unknown timestamp format";
239
                    final String msg = "Unknown timestamp format";
Lines 802-809 Link Here
802
        if (saveConfig.saveTimestamp()) {
801
        if (saveConfig.saveTimestamp()) {
803
            if (saveConfig.printMilliseconds()) {
802
            if (saveConfig.printMilliseconds()) {
804
                text.append(sample.getTimeStamp());
803
                text.append(sample.getTimeStamp());
805
            } else if (saveConfig.formatter() != null) {
804
            } else if (saveConfig.threadSafeFormatter() != null) {
806
                String stamp = saveConfig.formatter().format(
805
                String stamp = saveConfig.threadSafeFormatter().format(
807
                        new Date(sample.getTimeStamp()));
806
                        new Date(sample.getTimeStamp()));
808
                text.append(stamp);
807
                text.append(stamp);
809
            }
808
            }
(-)test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java (-5 / +5 lines)
Lines 25-34 Link Here
25
import static org.junit.Assert.assertTrue;
25
import static org.junit.Assert.assertTrue;
26
26
27
import java.lang.reflect.Method;
27
import java.lang.reflect.Method;
28
import java.text.SimpleDateFormat;
29
import java.util.ArrayList;
28
import java.util.ArrayList;
30
import java.util.List;
29
import java.util.List;
31
30
31
import org.apache.commons.lang3.time.FastDateFormat;
32
import org.apache.jmeter.junit.JMeterTestCase;
32
import org.apache.jmeter.junit.JMeterTestCase;
33
import org.junit.Test;
33
import org.junit.Test;
34
34
Lines 136-148 Link Here
136
        assertEquals("Hash codes should be equal",a.hashCode(), b.hashCode());
136
        assertEquals("Hash codes should be equal",a.hashCode(), b.hashCode());
137
        assertTrue("Objects should be equal",a.equals(b));
137
        assertTrue("Objects should be equal",a.equals(b));
138
        assertTrue("Objects should be equal",b.equals(a));
138
        assertTrue("Objects should be equal",b.equals(a));
139
        a.setFormatter(null);
139
        b.setFastDateFormater(null);
140
        b.setFormatter(null);
140
        b.setFastDateFormater(null);
141
        assertEquals("Hash codes should be equal",a.hashCode(), b.hashCode());
141
        assertEquals("Hash codes should be equal",a.hashCode(), b.hashCode());
142
        assertTrue("Objects should be equal",a.equals(b));
142
        assertTrue("Objects should be equal",a.equals(b));
143
        assertTrue("Objects should be equal",b.equals(a));
143
        assertTrue("Objects should be equal",b.equals(a));
144
        a.setFormatter(new SimpleDateFormat());
144
        b.setFastDateFormater(FastDateFormat.getInstance());
145
        b.setFormatter(new SimpleDateFormat());
145
        b.setFastDateFormater(FastDateFormat.getInstance());
146
        assertEquals("Hash codes should be equal",a.hashCode(), b.hashCode());
146
        assertEquals("Hash codes should be equal",a.hashCode(), b.hashCode());
147
        assertTrue("Objects should be equal",a.equals(b));
147
        assertTrue("Objects should be equal",a.equals(b));
148
        assertTrue("Objects should be equal",b.equals(a));
148
        assertTrue("Objects should be equal",b.equals(a));

Return to bug 60830