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

(-)src/components/org/apache/jmeter/assertions/SMIMEAssertion.java (-1 / +1 lines)
Lines 302-308 Link Here
302
302
303
        final SampleResult sampleResult = subResults[messageNumber];
303
        final SampleResult sampleResult = subResults[messageNumber];
304
        if (log.isDebugEnabled()) {
304
        if (log.isDebugEnabled()) {
305
            log.debug("Bytes: "+sampleResult.getBytes()+" CT: "+sampleResult.getContentType());
305
            log.debug("Bytes: "+sampleResult.getBytesAsLong()+" CT: "+sampleResult.getContentType());
306
        }
306
        }
307
        byte[] data = sampleResult.getResponseData();
307
        byte[] data = sampleResult.getResponseData();
308
        Session session = Session.getDefaultInstance(new Properties());
308
        Session session = Session.getDefaultInstance(new Properties());
(-)src/components/org/apache/jmeter/assertions/SizeAssertion.java (-3 / +3 lines)
Lines 79-85 Link Here
79
            String variableName = getVariableName();
79
            String variableName = getVariableName();
80
            String value = getThreadContext().getVariables().get(variableName);
80
            String value = getThreadContext().getVariables().get(variableName);
81
            try {
81
            try {
82
                resultSize = Integer.parseInt(value);
82
                resultSize = Long.parseLong(value);
83
            } catch (NumberFormatException e) {
83
            } catch (NumberFormatException e) {
84
                result.setFailure(true);
84
                result.setFailure(true);
85
                result.setFailureMessage("Error parsing variable name: "+variableName+" value: "+value);
85
                result.setFailureMessage("Error parsing variable name: "+variableName+" value: "+value);
Lines 88-100 Link Here
88
        } else if (isTestFieldResponseHeaders()) {
88
        } else if (isTestFieldResponseHeaders()) {
89
            resultSize = response.getHeadersSize();
89
            resultSize = response.getHeadersSize();
90
        }  else if (isTestFieldResponseBody()) {
90
        }  else if (isTestFieldResponseBody()) {
91
            resultSize = response.getBodySize();
91
            resultSize = response.getBodySizeAsLong();
92
        } else if (isTestFieldResponseCode()) {
92
        } else if (isTestFieldResponseCode()) {
93
            resultSize = response.getResponseCode().length();
93
            resultSize = response.getResponseCode().length();
94
        } else if (isTestFieldResponseMessage()) {
94
        } else if (isTestFieldResponseMessage()) {
95
            resultSize = response.getResponseMessage().length();
95
            resultSize = response.getResponseMessage().length();
96
        } else {
96
        } else {
97
            resultSize = response.getBytes();
97
            resultSize = response.getBytesAsLong();
98
        }
98
        }
99
        // is the Sample the correct size?
99
        // is the Sample the correct size?
100
        final String msg = compareSize(resultSize);
100
        final String msg = compareSize(resultSize);
(-)src/components/org/apache/jmeter/visualizers/SamplerResultTab.java (-4 / +5 lines)
Lines 238-247 Link Here
238
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
238
                statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL); //$NON-NLS-1$
239
                statsBuff.append(JMeterUtils.getResString("view_results_connect_time")).append(sampleResult.getConnectTime()).append(NL); //$NON-NLS-1$
239
                statsBuff.append(JMeterUtils.getResString("view_results_connect_time")).append(sampleResult.getConnectTime()).append(NL); //$NON-NLS-1$
240
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
240
                statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL); //$NON-NLS-1$
241
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytes()).append(NL); //$NON-NLS-1$
241
                statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytesAsLong()).append(NL); //$NON-NLS-1$
242
                statsBuff.append(JMeterUtils.getResString("view_results_sent_bytes")).append(sampleResult.getSentBytes()).append(NL); //$NON-NLS-1$
242
                statsBuff.append(JMeterUtils.getResString("view_results_sent_bytes")).append(sampleResult.getSentBytes()).append(NL); //$NON-NLS-1$
243
                statsBuff.append(JMeterUtils.getResString("view_results_sent_bytes")).append(sampleResult.getSentBytes()).append(NL); //$NON-NLS-1$
243
                statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL); //$NON-NLS-1$
244
                statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL); //$NON-NLS-1$
244
                statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySize()).append(NL); //$NON-NLS-1$
245
                statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySizeAsLong()).append(NL); //$NON-NLS-1$
245
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
246
                statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL); //$NON-NLS-1$
246
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
247
                statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL); //$NON-NLS-1$
247
                statsBuff.append(JMeterUtils.getResString("view_results_datatype")).append(sampleResult.getDataType()).append(NL); //$NON-NLS-1$
248
                statsBuff.append(JMeterUtils.getResString("view_results_datatype")).append(sampleResult.getDataType()).append(NL); //$NON-NLS-1$
Lines 298-307 Link Here
298
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
299
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime())); //$NON-NLS-1$
299
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_connect_time"), sampleResult.getConnectTime())); //$NON-NLS-1$
300
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_connect_time"), sampleResult.getConnectTime())); //$NON-NLS-1$
300
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
301
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency())); //$NON-NLS-1$
301
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$NON-NLS-1$
302
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytesAsLong())); //$NON-NLS-1$
302
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sent_bytes"),sampleResult.getSentBytes())); //$NON-NLS-1$
303
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sent_bytes"),sampleResult.getSentBytes())); //$NON-NLS-1$
303
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize())); //$NON-NLS-1$
304
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize())); //$NON-NLS-1$
304
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySize())); //$NON-NLS-1$
305
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySizeAsLong())); //$NON-NLS-1$
305
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
306
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount())); //$NON-NLS-1$
306
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
307
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount())); //$NON-NLS-1$
307
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
308
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode)); //$NON-NLS-1$
(-)src/components/org/apache/jmeter/visualizers/TableVisualizer.java (-1 / +1 lines)
Lines 194-200 Link Here
194
                            res.getSampleLabel(),
194
                            res.getSampleLabel(),
195
                            res.getTime(),
195
                            res.getTime(),
196
                            res.isSuccessful(),
196
                            res.isSuccessful(),
197
                            res.getBytes(),
197
                            res.getBytesAsLong(),
198
                            res.getSentBytes(),
198
                            res.getSentBytes(),
199
                            res.getLatency(),
199
                            res.getLatency(),
200
                            res.getConnectTime()
200
                            res.getConnectTime()
(-)src/core/org/apache/jmeter/control/TransactionController.java (-1 / +1 lines)
Lines 321-327 Link Here
321
            if(res != null && !se.isTransactionSampleEvent()) {
321
            if(res != null && !se.isTransactionSampleEvent()) {
322
                SampleResult sampleResult = se.getResult();
322
                SampleResult sampleResult = se.getResult();
323
                res.setThreadName(sampleResult.getThreadName());
323
                res.setThreadName(sampleResult.getThreadName());
324
                res.setBytes(res.getBytes() + sampleResult.getBytes());
324
                res.setBytes(res.getBytesAsLong() + sampleResult.getBytesAsLong());
325
                res.setSentBytes(res.getSentBytes() + sampleResult.getSentBytes());
325
                res.setSentBytes(res.getSentBytes() + sampleResult.getSentBytes());
326
                if (!isIncludeTimers()) {// Accumulate waiting time for later
326
                if (!isIncludeTimers()) {// Accumulate waiting time for later
327
                    pauseTime += sampleResult.getEndTime() - sampleResult.getTime() - prevEndTime;
327
                    pauseTime += sampleResult.getEndTime() - sampleResult.getTime() - prevEndTime;
(-)src/core/org/apache/jmeter/report/core/Sample.java (-2 / +2 lines)
Lines 260-267 Link Here
260
     *
260
     *
261
     * @return the number of received bytes stored in the sample
261
     * @return the number of received bytes stored in the sample
262
     */
262
     */
263
    public int getReceivedBytes() {
263
    public long getReceivedBytes() {
264
        return getData(int.class, CSVSaveService.CSV_BYTES).intValue();
264
        return getData(long.class, CSVSaveService.CSV_BYTES).longValue();
265
    }
265
    }
266
266
267
    /**
267
    /**
(-)src/core/org/apache/jmeter/samplers/DataStrippingSampleSender.java (-1 / +1 lines)
Lines 117-123 Link Here
117
     * @param result {@link SampleResult}
117
     * @param result {@link SampleResult}
118
     */
118
     */
119
    private void stripResponse(SampleResult result) {
119
    private void stripResponse(SampleResult result) {
120
        result.setBytes(result.getBytes());
120
        result.setBytes(result.getBytesAsLong());
121
        result.setResponseData(SampleResult.EMPTY_BA);
121
        result.setResponseData(SampleResult.EMPTY_BA);
122
    }
122
    }
123
123
(-)src/core/org/apache/jmeter/samplers/SampleResult.java (-10 / +43 lines)
Lines 210-220 Link Here
210
210
211
    private int sampleCount = 1;
211
    private int sampleCount = 1;
212
212
213
    private int bytes = 0; // Allows override of sample size in case sampler does not want to store all the data
213
    private long bytes = 0; // Allows override of sample size in case sampler does not want to store all the data
214
    
214
    
215
    private int headersSize = 0;
215
    private int headersSize = 0;
216
    
216
    
217
    private int bodySize = 0;
217
    private long bodySize = 0;
218
218
219
    /** Currently active threads in this thread group */
219
    /** Currently active threads in this thread group */
220
    private volatile int groupThreads = 0;
220
    private volatile int groupThreads = 0;
Lines 267-273 Link Here
267
     * Cache for responseData as string to avoid multiple computations
267
     * Cache for responseData as string to avoid multiple computations
268
     */
268
     */
269
    private volatile transient String responseDataAsString;
269
    private volatile transient String responseDataAsString;
270
270
    
271
    private long sentBytes;
271
    private long sentBytes;
272
272
273
    private long initOffset(){
273
    private long initOffset(){
Lines 613-622 Link Here
613
        // Extend the time to the end of the added sample
613
        // Extend the time to the end of the added sample
614
        setEndTime(Math.max(getEndTime(), subResult.getEndTime() + nanoTimeOffset - subResult.nanoTimeOffset)); // Bug 51855
614
        setEndTime(Math.max(getEndTime(), subResult.getEndTime() + nanoTimeOffset - subResult.nanoTimeOffset)); // Bug 51855
615
        // Include the byte count for the added sample
615
        // Include the byte count for the added sample
616
        setBytes(getBytes() + subResult.getBytes());
616
        setBytes(getBytesAsLong() + subResult.getBytesAsLong());
617
        setSentBytes(getSentBytes() + subResult.getSentBytes());
617
        setSentBytes(getSentBytes() + subResult.getSentBytes());
618
        setHeadersSize(getHeadersSize() + subResult.getHeadersSize());
618
        setHeadersSize(getHeadersSize() + subResult.getHeadersSize());
619
        setBodySize(getBodySize() + subResult.getBodySize());
619
        setBodySize(getBodySizeAsLong() + subResult.getBodySizeAsLong());
620
        addRawSubResult(subResult);
620
        addRawSubResult(subResult);
621
    }
621
    }
622
    
622
    
Lines 1194-1203 Link Here
1194
     * @param length
1194
     * @param length
1195
     *            the number of bytes of the response data for this sample
1195
     *            the number of bytes of the response data for this sample
1196
     */
1196
     */
1197
    public void setBytes(int length) {
1197
    public void setBytes(long length) {
1198
        bytes = length;
1198
        bytes = length;
1199
    }
1199
    }
1200
1200
    
1201
    /**
1202
     * In the event the sampler does want to pass back the actual contents, we
1203
     * still want to calculate the throughput. The bytes are the bytes of the
1204
     * response data.
1205
     *
1206
     * @param length
1207
     *            the number of bytes of the response data for this sample
1208
     * @deprecated use setBytes(long)
1209
     */
1210
    @Deprecated
1211
    public void setBytes(int length) {
1212
        setBytes((long) length);
1213
    }
1214
    
1201
    /**
1215
    /**
1202
     * 
1216
     * 
1203
     * @param sentBytesCount long sent bytes
1217
     * @param sentBytesCount long sent bytes
Lines 1217-1231 Link Here
1217
     * return the bytes returned by the response.
1231
     * return the bytes returned by the response.
1218
     *
1232
     *
1219
     * @return byte count
1233
     * @return byte count
1234
     * @deprecated use getBytesAsLong 
1220
     */
1235
     */
1236
    @Deprecated
1221
    public int getBytes() {
1237
    public int getBytes() {
1238
        return (int) getBytesAsLong();
1239
    }
1240
1241
    /**
1242
     * return the bytes returned by the response.
1243
     *
1244
     * @return byte count
1245
     */
1246
    public long getBytesAsLong() {
1222
        if (GETBYTES_NETWORK_SIZE) {
1247
        if (GETBYTES_NETWORK_SIZE) {
1223
            int tmpSum = this.getHeadersSize() + this.getBodySize();
1248
            long tmpSum = this.getHeadersSize() + this.getBodySizeAsLong();
1224
            return tmpSum == 0 ? bytes : tmpSum;
1249
            return tmpSum == 0 ? bytes : tmpSum;
1225
        } else if (GETBYTES_HEADERS_SIZE) {
1250
        } else if (GETBYTES_HEADERS_SIZE) {
1226
            return this.getHeadersSize();
1251
            return this.getHeadersSize();
1227
        } else if (GETBYTES_BODY_REALSIZE) {
1252
        } else if (GETBYTES_BODY_REALSIZE) {
1228
            return this.getBodySize();
1253
            return this.getBodySizeAsLong();
1229
        }
1254
        }
1230
        return bytes == 0 ? responseData.length : bytes;
1255
        return bytes == 0 ? responseData.length : bytes;
1231
    }
1256
    }
Lines 1383-1396 Link Here
1383
    /**
1408
    /**
1384
     * @return the body size in bytes
1409
     * @return the body size in bytes
1385
     */
1410
     */
1411
    @Deprecated
1386
    public int getBodySize() {
1412
    public int getBodySize() {
1413
        return (int) getBodySizeAsLong();
1414
    }
1415
    
1416
    /**
1417
     * @return the body size in bytes
1418
     */
1419
    public long getBodySizeAsLong() {
1387
        return bodySize == 0 ? responseData.length : bodySize;
1420
        return bodySize == 0 ? responseData.length : bodySize;
1388
    }
1421
    }
1389
1422
1390
    /**
1423
    /**
1391
     * @param bodySize the body size to set
1424
     * @param bodySize the body size to set
1392
     */
1425
     */
1393
    public void setBodySize(int bodySize) {
1426
    public void setBodySize(long bodySize) {
1394
        this.bodySize = bodySize;
1427
        this.bodySize = bodySize;
1395
    }
1428
    }
1396
1429
(-)src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java (-1 / +1 lines)
Lines 72-78 Link Here
72
        // Add Sample Counter
72
        // Add Sample Counter
73
        setSampleCount(getSampleCount() + res.getSampleCount());
73
        setSampleCount(getSampleCount() + res.getSampleCount());
74
74
75
        setBytes(getBytes() + res.getBytes());
75
        setBytes(getBytesAsLong() + res.getBytesAsLong());
76
        setSentBytes(getSentBytes() + res.getSentBytes());
76
        setSentBytes(getSentBytes() + res.getSentBytes());
77
77
78
        // Add Error Counter
78
        // Add Error Counter
(-)src/core/org/apache/jmeter/save/CSVSaveService.java (-5 / +5 lines)
Lines 299-307 Link Here
299
            if (saveConfig.saveBytes()) {
299
            if (saveConfig.saveBytes()) {
300
                field = CSV_BYTES;
300
                field = CSV_BYTES;
301
                text = parts[i++];
301
                text = parts[i++];
302
                result.setBytes(Integer.parseInt(text));
302
                result.setBytes(Long.parseLong(text));
303
            }
303
            }
304
            
304
305
            if (saveConfig.saveSentBytes()) {
305
            if (saveConfig.saveSentBytes()) {
306
                field = CSV_SENT_BYTES;
306
                field = CSV_SENT_BYTES;
307
                text = parts[i++];
307
                text = parts[i++];
Lines 453-459 Link Here
453
            text.append(CSV_BYTES);
453
            text.append(CSV_BYTES);
454
            text.append(delim);
454
            text.append(delim);
455
        }
455
        }
456
        
456
457
        if (saveConfig.saveSentBytes()) {
457
        if (saveConfig.saveSentBytes()) {
458
            text.append(CSV_SENT_BYTES);
458
            text.append(CSV_SENT_BYTES);
459
            text.append(delim);
459
            text.append(delim);
Lines 936-944 Link Here
936
        }
936
        }
937
937
938
        if (saveConfig.saveBytes()) {
938
        if (saveConfig.saveBytes()) {
939
            text.append(sample.getBytes());
939
            text.append(sample.getBytesAsLong());
940
        }
940
        }
941
        
941
942
        if (saveConfig.saveSentBytes()) {
942
        if (saveConfig.saveSentBytes()) {
943
            text.append(sample.getSentBytes());
943
            text.append(sample.getSentBytes());
944
        }
944
        }
(-)src/core/org/apache/jmeter/save/converters/SampleResultConverter.java (-4 / +3 lines)
Lines 320-326 Link Here
320
            writer.addAttribute(ATT_DATA_ENCODING, ConversionHelp.encode(res.getDataEncodingNoDefault()));
320
            writer.addAttribute(ATT_DATA_ENCODING, ConversionHelp.encode(res.getDataEncodingNoDefault()));
321
        }
321
        }
322
        if (save.saveBytes()) {
322
        if (save.saveBytes()) {
323
            writer.addAttribute(ATT_BYTES, String.valueOf(res.getBytes()));
323
            writer.addAttribute(ATT_BYTES, String.valueOf(res.getBytesAsLong()));
324
        }
324
        }
325
        if (save.saveSentBytes()) {
325
        if (save.saveSentBytes()) {
326
            writer.addAttribute(ATT_SENT_BYTES, String.valueOf(res.getSentBytes()));
326
            writer.addAttribute(ATT_SENT_BYTES, String.valueOf(res.getSentBytes()));
Lines 449-455 Link Here
449
        res.setIdleTime(Converter.getLong(reader.getAttribute(ATT_IDLETIME)));
449
        res.setIdleTime(Converter.getLong(reader.getAttribute(ATT_IDLETIME)));
450
        res.setLatency(Converter.getLong(reader.getAttribute(ATT_LATENCY)));
450
        res.setLatency(Converter.getLong(reader.getAttribute(ATT_LATENCY)));
451
        res.setConnectTime(Converter.getLong(reader.getAttribute(ATT_CONNECT_TIME)));
451
        res.setConnectTime(Converter.getLong(reader.getAttribute(ATT_CONNECT_TIME)));
452
        res.setBytes(Converter.getInt(reader.getAttribute(ATT_BYTES)));
452
        res.setBytes(Converter.getLong(reader.getAttribute(ATT_BYTES)));
453
        res.setSentBytes(Converter.getLong(reader.getAttribute(ATT_SENT_BYTES)));
453
        res.setSentBytes(Converter.getLong(reader.getAttribute(ATT_SENT_BYTES)));
454
        res.setSampleCount(Converter.getInt(reader.getAttribute(ATT_SAMPLE_COUNT),1)); // default is 1
454
        res.setSampleCount(Converter.getInt(reader.getAttribute(ATT_SAMPLE_COUNT),1)); // default is 1
455
        res.setErrorCount(Converter.getInt(reader.getAttribute(ATT_ERROR_COUNT),0)); // default is 0
455
        res.setErrorCount(Converter.getInt(reader.getAttribute(ATT_ERROR_COUNT),0)); // default is 0
Lines 461-467 Link Here
461
        File in = new File(resultFileName);
461
        File in = new File(resultFileName);
462
        try (FileInputStream fis = new FileInputStream(in);
462
        try (FileInputStream fis = new FileInputStream(in);
463
                BufferedInputStream bis = new BufferedInputStream(fis)){
463
                BufferedInputStream bis = new BufferedInputStream(fis)){
464
            ByteArrayOutputStream outstream = new ByteArrayOutputStream(res.getBytes());
464
            ByteArrayOutputStream outstream = new ByteArrayOutputStream(4096);
465
            byte[] buffer = new byte[4096];
465
            byte[] buffer = new byte[4096];
466
            int len;
466
            int len;
467
            while ((len = bis.read(buffer)) > 0) {
467
            while ((len = bis.read(buffer)) > 0) {
Lines 474-480 Link Here
474
        } 
474
        } 
475
    }
475
    }
476
476
477
478
    /**
477
    /**
479
     * @param arg0 the mapper
478
     * @param arg0 the mapper
480
     */
479
     */
(-)src/core/org/apache/jmeter/util/Calculator.java (-1 / +1 lines)
Lines 110-116 Link Here
110
     * @param res the sample result; might represent multiple values
110
     * @param res the sample result; might represent multiple values
111
     */
111
     */
112
    public void addSample(SampleResult res) {
112
    public void addSample(SampleResult res) {
113
        addBytes(res.getBytes());
113
        addBytes(res.getBytesAsLong());
114
        addValue(res.getTime(),res.getSampleCount());
114
        addValue(res.getTime(),res.getSampleCount());
115
        errors+=res.getErrorCount(); // account for multiple samples
115
        errors+=res.getErrorCount(); // account for multiple samples
116
        if (startTime == 0){ // not yet intialised
116
        if (startTime == 0){ // not yet intialised
(-)src/core/org/apache/jmeter/visualizers/SamplingStatCalculator.java (-1 / +1 lines)
Lines 157-163 Link Here
157
        boolean rbool;
157
        boolean rbool;
158
        synchronized (calculator) {
158
        synchronized (calculator) {
159
            calculator.addValue(res.getTime(), res.getSampleCount());
159
            calculator.addValue(res.getTime(), res.getSampleCount());
160
            calculator.addBytes(res.getBytes());
160
            calculator.addBytes(res.getBytesAsLong());
161
            setStartTime(res);
161
            setStartTime(res);
162
            eCount = getCurrentSample().getErrorCount();
162
            eCount = getCurrentSample().getErrorCount();
163
            eCount += res.getErrorCount();
163
            eCount += res.getErrorCount();
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java (+26 lines)
Lines 409-414 Link Here
409
     */
409
     */
410
    protected byte[] readResponse(SampleResult res, InputStream instream,
410
    protected byte[] readResponse(SampleResult res, InputStream instream,
411
            int responseContentLength) throws IOException {
411
            int responseContentLength) throws IOException {
412
        return readResponse(res, instream, (long)responseContentLength);
413
    }
414
    /**
415
     * Read response from the input stream, converting to MD5 digest if the
416
     * useMD5 property is set.
417
     * <p>
418
     * For the MD5 case, the result byte count is set to the size of the
419
     * original response.
420
     * <p>
421
     * Closes the inputStream
422
     * <p>
423
     * Invokes
424
     * {@link HTTPSamplerBase#readResponse(SampleResult, InputStream, int)}
425
     * 
426
     * @param res
427
     *            sample to store information about the response into
428
     * @param instream
429
     *            input stream from which to read the response
430
     * @param responseContentLength
431
     *            expected input length or zero
432
     * @return the response or the MD5 of the response
433
     * @throws IOException
434
     *             if reading the result fails
435
     */
436
    protected byte[] readResponse(SampleResult res, InputStream instream,
437
            long responseContentLength) throws IOException {
412
        return testElement.readResponse(res, instream, responseContentLength);
438
        return testElement.readResponse(res, instream, responseContentLength);
413
    }
439
    }
414
440
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java (-2 / +16 lines)
Lines 26-36 Link Here
26
26
27
import org.apache.commons.io.IOUtils;
27
import org.apache.commons.io.IOUtils;
28
import org.apache.jmeter.protocol.http.util.HTTPConstants;
28
import org.apache.jmeter.protocol.http.util.HTTPConstants;
29
import org.apache.jmeter.util.JMeterUtils;
29
30
30
/**
31
/**
31
 * HTTP Sampler which can read from file: URLs
32
 * HTTP Sampler which can read from file: URLs
32
 */
33
 */
33
public class HTTPFileImpl extends HTTPAbstractImpl {
34
public class HTTPFileImpl extends HTTPAbstractImpl {
35
    private static final int MAX_BYTES_TO_STORE_PER_REQUEST =
36
            JMeterUtils.getPropDefault("httpsampler.max_bytes_to_store_per_request", 10 * 1024 *1024); // $NON-NLS-1$ // default value: false
34
37
35
    protected HTTPFileImpl(HTTPSamplerBase base) {
38
    protected HTTPFileImpl(HTTPSamplerBase base) {
36
        super(base);
39
        super(base);
Lines 51-63 Link Here
51
        res.setSampleLabel(url.toString());
54
        res.setSampleLabel(url.toString());
52
        InputStream is = null;
55
        InputStream is = null;
53
        res.sampleStart();
56
        res.sampleStart();
54
        try {
57
        int bufferSize = 4096;
58
        try ( org.apache.commons.io.output.ByteArrayOutputStream bos = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize) ) {
55
            byte[] responseData;
59
            byte[] responseData;
56
            URLConnection conn = url.openConnection();
60
            URLConnection conn = url.openConnection();
57
            is = conn.getInputStream();
61
            is = conn.getInputStream();
58
            responseData = IOUtils.toByteArray(is);
62
            byte[] readBuffer = new byte[bufferSize];
63
            int bytesReadInBuffer = 0;
64
            long totalBytes = 0;
65
            while ((bytesReadInBuffer = is.read(readBuffer)) > -1) {
66
                if(totalBytes+bytesReadInBuffer<=MAX_BYTES_TO_STORE_PER_REQUEST) {
67
                    bos.write(readBuffer, 0, bytesReadInBuffer);
68
                }
69
                totalBytes += bytesReadInBuffer;
70
            }
71
            responseData = bos.toByteArray();
59
            res.sampleEnd();
72
            res.sampleEnd();
60
            res.setResponseData(responseData);
73
            res.setResponseData(responseData);
74
            res.setBodySize(totalBytes);
61
            res.setResponseCodeOK();
75
            res.setResponseCodeOK();
62
            res.setResponseMessageOK();
76
            res.setResponseMessageOK();
63
            res.setSuccessful(true);
77
            res.setSuccessful(true);
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java (-5 / +5 lines)
Lines 285-293 Link Here
285
                    Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
285
                    Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
286
                    if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) {
286
                    if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) {
287
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
287
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
288
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                        
288
                        res.setResponseData(readResponse(res, tmpInput, httpMethod.getResponseContentLength()));                        
289
                    } else {
289
                    } else {
290
                        res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
290
                        res.setResponseData(readResponse(res, instream, httpMethod.getResponseContentLength()));
291
                    }
291
                    }
292
                } finally {
292
                } finally {
293
                    JOrphanUtils.closeQuietly(instream);
293
                    JOrphanUtils.closeQuietly(instream);
Lines 328-339 Link Here
328
328
329
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
329
            // record some sizes to allow HTTPSampleResult.getBytes() with different options
330
            if (instream != null) {
330
            if (instream != null) {
331
                res.setBodySize(((CountingInputStream) instream).getCount());
331
                res.setBodySize(((CountingInputStream) instream).getByteCount());
332
            }
332
            }
333
            res.setHeadersSize(calculateHeadersSize(httpMethod));
333
            res.setHeadersSize(calculateHeadersSize(httpMethod));
334
            if (log.isDebugEnabled()) {
334
            if (log.isDebugEnabled()) {
335
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
335
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySizeAsLong()
336
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
336
                        + " Total=" + (res.getHeadersSize() + res.getBodySizeAsLong()));
337
            }
337
            }
338
            
338
            
339
            // If we redirected automatically, the URL may have changed
339
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-5 / +5 lines)
Lines 406-412 Link Here
406
            }
406
            }
407
            HttpEntity entity = httpResponse.getEntity();
407
            HttpEntity entity = httpResponse.getEntity();
408
            if (entity != null) {
408
            if (entity != null) {
409
                res.setResponseData(readResponse(res, entity.getContent(), (int) entity.getContentLength()));
409
                res.setResponseData(readResponse(res, entity.getContent(), entity.getContentLength()));
410
            }
410
            }
411
            
411
            
412
            res.sampleEnd(); // Done with the sampling proper.
412
            res.sampleEnd(); // Done with the sampling proper.
Lines 437-448 Link Here
437
              + 1 // Add \r for initial header
437
              + 1 // Add \r for initial header
438
              + 2; // final \r\n before data
438
              + 2; // final \r\n before data
439
            long totalBytes = metrics.getReceivedBytesCount();
439
            long totalBytes = metrics.getReceivedBytesCount();
440
            res.setHeadersSize((int) headerBytes);
440
            res.setHeadersSize((int)headerBytes);
441
            res.setBodySize((int)(totalBytes - headerBytes));
441
            res.setBodySize(totalBytes - headerBytes);
442
            res.setSentBytes(metrics.getSentBytesCount());
442
            res.setSentBytes(metrics.getSentBytesCount());
443
            if (log.isDebugEnabled()) {
443
            if (log.isDebugEnabled()) {
444
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getBodySize()
444
                log.debug("ResponseHeadersSize=" + res.getHeadersSize() + " Content-Length=" + res.getBodySizeAsLong()
445
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
445
                        + " Total=" + (res.getHeadersSize() + res.getBodySizeAsLong()));
446
            }
446
            }
447
447
448
            // If we redirected automatically, the URL may have changed
448
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java (-3 / +3 lines)
Lines 284-290 Link Here
284
        // N.B. this closes 'in'
284
        // N.B. this closes 'in'
285
        byte[] responseData = readResponse(res, in, contentLength);
285
        byte[] responseData = readResponse(res, in, contentLength);
286
        if (instream != null) {
286
        if (instream != null) {
287
            res.setBodySize(((CountingInputStream) instream).getCount());
287
            res.setBodySize(((CountingInputStream) instream).getByteCount());
288
            instream.close();
288
            instream.close();
289
        }
289
        }
290
        return responseData;
290
        return responseData;
Lines 566-573 Link Here
566
            res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") // $NON-NLS-1$ $NON-NLS-2$
566
            res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") // $NON-NLS-1$ $NON-NLS-2$
567
                    .length() + 2); // add 2 for a '\r\n' at end of headers (before data) 
567
                    .length() + 2); // add 2 for a '\r\n' at end of headers (before data) 
568
            if (log.isDebugEnabled()) {
568
            if (log.isDebugEnabled()) {
569
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
569
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySizeAsLong()
570
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
570
                        + " Total=" + (res.getHeadersSize() + res.getBodySizeAsLong()));
571
            }
571
            }
572
            
572
            
573
            // If we redirected automatically, the URL may have changed
573
            // If we redirected automatically, the URL may have changed
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (-14 / +24 lines)
Lines 189-194 Link Here
189
189
190
    public static final boolean BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT = false; // The default setting to be used (i.e. historic)
190
    public static final boolean BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT = false; // The default setting to be used (i.e. historic)
191
191
192
    private static final int MAX_BYTES_TO_STORE_PER_REQUEST =
193
            JMeterUtils.getPropDefault("httpsampler.max_bytes_to_store_per_request", 10 * 1024 *1024); // $NON-NLS-1$ // default value: false
194
195
    private static final int MAX_BUFFER_SIZE = 
196
            JMeterUtils.getPropDefault("httpsampler.max_buffer_size", 65 * 1024); // $NON-NLS-1$
197
192
    private static final boolean IGNORE_FAILED_EMBEDDED_RESOURCES =
198
    private static final boolean IGNORE_FAILED_EMBEDDED_RESOURCES =
193
            JMeterUtils.getPropDefault("httpsampler.ignore_failed_embedded_resources", false); // $NON-NLS-1$ // default value: false
199
            JMeterUtils.getPropDefault("httpsampler.ignore_failed_embedded_resources", false); // $NON-NLS-1$ // default value: false
194
200
Lines 926-931 Link Here
926
    private static final boolean SEPARATE_CONTAINER =
932
    private static final boolean SEPARATE_CONTAINER =
927
            JMeterUtils.getPropDefault("httpsampler.separate.container", true); // $NON-NLS-1$
933
            JMeterUtils.getPropDefault("httpsampler.separate.container", true); // $NON-NLS-1$
928
934
935
929
    /**
936
    /**
930
     * Get the URL, built from its component parts.
937
     * Get the URL, built from its component parts.
931
     *
938
     *
Lines 1757-1763 Link Here
1757
     * @return the response or the MD5 of the response
1764
     * @return the response or the MD5 of the response
1758
     * @throws IOException if reading the result fails
1765
     * @throws IOException if reading the result fails
1759
     */
1766
     */
1760
    public byte[] readResponse(SampleResult sampleResult, InputStream in, int length) throws IOException {
1767
    public byte[] readResponse(SampleResult sampleResult, InputStream in, long length) throws IOException {
1761
        
1768
        
1762
        OutputStream w = null;
1769
        OutputStream w = null;
1763
        try {
1770
        try {
Lines 1776-1809 Link Here
1776
                if (!knownResponseLength) {
1783
                if (!knownResponseLength) {
1777
                    bufferSize = 4 * 1024;
1784
                    bufferSize = 4 * 1024;
1778
                } else {
1785
                } else {
1779
                    bufferSize = length;
1786
                    bufferSize = (int) Math.min(MAX_BUFFER_SIZE, length);
1780
                }
1787
                }
1781
            }
1788
            }
1782
            
1789
            
1783
            
1790
            
1784
            int bytesRead = 0;
1791
            int bytesReadInBuffer = 0;
1785
            int totalBytes = 0;
1792
            long totalBytes = 0;
1786
            boolean first = true;
1793
            boolean first = true;
1787
            while ((bytesRead = in.read(readBuffer)) > -1) {
1794
            while ((bytesReadInBuffer = in.read(readBuffer)) > -1) {
1788
                if (first) {
1795
                if (first) {
1789
                    sampleResult.latencyEnd();
1796
                    sampleResult.latencyEnd();
1790
                    first = false;
1797
                    first = false;
1791
                    if(md == null) {
1798
                    if(md == null) {
1792
                        if(knownResponseLength) {
1799
                        if(!knownResponseLength) {
1793
                            w = new DirectAccessByteArrayOutputStream(bufferSize);
1800
                            w = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize);
1794
                        }
1801
                        }
1795
                        else {
1802
                        else {
1796
                            w = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize);
1803
                            w = new DirectAccessByteArrayOutputStream(bufferSize);
1797
                        }
1804
                        }
1798
                    }
1805
                    }
1799
                }
1806
                }
1800
                
1807
                
1801
                if (md == null) {
1808
                if (md == null) {
1802
                    w.write(readBuffer, 0, bytesRead);
1809
                    if(totalBytes+bytesReadInBuffer<=MAX_BYTES_TO_STORE_PER_REQUEST) {
1810
                        w.write(readBuffer, 0, bytesReadInBuffer);
1811
                    } 
1803
                } else {
1812
                } else {
1804
                    md.update(readBuffer, 0, bytesRead);
1813
                    md.update(readBuffer, 0, bytesReadInBuffer);
1805
                    totalBytes += bytesRead;
1806
                }
1814
                }
1815
                totalBytes += bytesReadInBuffer;
1807
            }
1816
            }
1808
            
1817
            
1809
            if (first) { // Bug 46838 - if there was no data, still need to set latency
1818
            if (first) { // Bug 46838 - if there was no data, still need to set latency
Lines 1811-1823 Link Here
1811
                return new byte[0];
1820
                return new byte[0];
1812
            }
1821
            }
1813
            
1822
            
1814
            if (md != null) {
1823
            if (md == null) {
1824
                return toByteArray(w);
1825
            } else {
1815
                byte[] md5Result = md.digest();
1826
                byte[] md5Result = md.digest();
1816
                sampleResult.setBytes(totalBytes);
1827
                sampleResult.setBytes(totalBytes);
1817
                return JOrphanUtils.baToHexBytes(md5Result);
1828
                return JOrphanUtils.baToHexBytes(md5Result);                
1818
            }
1829
            }
1819
            
1830
            
1820
            return toByteArray(w);
1821
        } finally {
1831
        } finally {
1822
            IOUtils.closeQuietly(in);
1832
            IOUtils.closeQuietly(in);
1823
            IOUtils.closeQuietly(w);
1833
            IOUtils.closeQuietly(w);
(-)test/src/org/apache/jmeter/samplers/TestSampleResult.java (-4 / +4 lines)
Lines 146-152 Link Here
146
            res.setBytes(100);
146
            res.setBytes(100);
147
            res.setSampleLabel("sample of size 100 bytes");
147
            res.setSampleLabel("sample of size 100 bytes");
148
            res.sampleEnd();
148
            res.sampleEnd();
149
            assertEquals(100, res.getBytes());
149
            assertEquals(100, res.getBytesAsLong());
150
            assertEquals("sample of size 100 bytes", res.getSampleLabel());
150
            assertEquals("sample of size 100 bytes", res.getSampleLabel());
151
        }
151
        }
152
152
Lines 234-240 Link Here
234
            long child1Elapsed = child1.getTime();
234
            long child1Elapsed = child1.getTime();
235
235
236
            assertTrue(child1.isSuccessful());
236
            assertTrue(child1.isSuccessful());
237
            assertEquals(100, child1.getBytes());
237
            assertEquals(100, child1.getBytesAsLong());
238
            assertEquals("Child1 Sample", child1.getSampleLabel());
238
            assertEquals("Child1 Sample", child1.getSampleLabel());
239
            assertEquals(1, child1.getSampleCount());
239
            assertEquals(1, child1.getSampleCount());
240
            assertEquals(0, child1.getSubResults().length);
240
            assertEquals(0, child1.getSubResults().length);
Lines 257-263 Link Here
257
            long child2Elapsed = child2.getTime();
257
            long child2Elapsed = child2.getTime();
258
258
259
            assertTrue(child2.isSuccessful());
259
            assertTrue(child2.isSuccessful());
260
            assertEquals(200, child2.getBytes());
260
            assertEquals(200, child2.getBytesAsLong());
261
            assertEquals("Child2 Sample", child2.getSampleLabel());
261
            assertEquals("Child2 Sample", child2.getSampleLabel());
262
            assertEquals(1, child2.getSampleCount());
262
            assertEquals(1, child2.getSampleCount());
263
            assertEquals(0, child2.getSubResults().length);
263
            assertEquals(0, child2.getSubResults().length);
Lines 266-272 Link Here
266
            parent.addSubResult(child1);
266
            parent.addSubResult(child1);
267
            parent.addSubResult(child2);
267
            parent.addSubResult(child2);
268
            assertTrue(parent.isSuccessful());
268
            assertTrue(parent.isSuccessful());
269
            assertEquals(600, parent.getBytes());
269
            assertEquals(600, parent.getBytesAsLong());
270
            assertEquals("Parent Sample", parent.getSampleLabel());
270
            assertEquals("Parent Sample", parent.getSampleLabel());
271
            assertEquals(1, parent.getSampleCount());
271
            assertEquals(1, parent.getSampleCount());
272
            assertEquals(2, parent.getSubResults().length);
272
            assertEquals(2, parent.getSubResults().length);

Return to bug 53039