Class SampleResult
-
- All Implemented Interfaces:
-
java.io.Serializable
,java.lang.Cloneable
,org.apache.jmeter.gui.Searchable
public class SampleResult implements Serializable, Cloneable, Searchable
This is a nice packaging for the various information returned from taking a sample of an entry.
-
-
Field Summary
Fields Modifier and Type Field Description public final static String
DEFAULT_HTTP_ENCODING
public final static String
TEXT
public final static String
BINARY
public SampleSaveConfiguration
saveConfig
public SampleResult
parent
public Array<byte>
responseData
public String
responseCode
public String
resultFileName
public String
samplerData
public String
threadName
public String
responseMessage
public String
responseHeaders
public String
requestHeaders
public long
timeStamp
public long
startTime
public long
endTime
public long
idleTime
public String
dataType
public String
contentType
public long
latency
public long
connectTime
public JMeterContext.TestLogicalAction
testLogicalAction
public int
sampleCount
public int
headersSize
public volatile int
groupThreads
public volatile int
allThreads
public long
sentBytes
public transient volatile String
responseDataAsString
-
Constructor Summary
Constructors Constructor Description SampleResult()
SampleResult(SampleResult res)
Copy constructor. SampleResult(long stamp, long elapsed)
Allow users to create a sample with specific timestamp and elapsed times for cloning purposes, but don't allow the times to be changed later Currently used by CSVSaveService and StatisticalSampleResult
-
Method Summary
Modifier and Type Method Description SampleSaveConfiguration
getSaveConfig()
void
setSaveConfig(SampleSaveConfiguration propertiesToSave)
SampleResult
getParent()
void
setParent(SampleResult parent)
Array<byte>
getResponseData()
Gets the responseData attribute of the SampleResult object. void
setResponseData(Array<byte> response)
Sets the responseData attribute of the SampleResult object. String
getResponseCode()
void
setResponseCode(String code)
String
getResultFileName()
void
setResultFileName(String resultFileName)
String
getSamplerData()
void
setSamplerData(String s)
String
getThreadName()
void
setThreadName(String threadName)
String
getResponseMessage()
void
setResponseMessage(String msg)
String
getResponseHeaders()
void
setResponseHeaders(String string)
String
getRequestHeaders()
void
setRequestHeaders(String string)
long
getTimeStamp()
Get the sample timestamp, which may be either the start time or the end time. void
setTimeStamp(long timeStamp)
This is only intended for use by SampleResultConverter! long
getStartTime()
long
getEndTime()
void
setEndTime(long end)
long
getIdleTime()
void
setIdleTime(long idle)
Set idle time pause. String
getDataType()
Returns the data type of the sample. void
setDataType(String dataType)
Sets the data type of the sample. String
getContentType()
void
setContentType(String string)
Stores the content-type string, e.g. long
getLatency()
void
setLatency(long latency)
This is only intended for use by SampleResultConverter! long
getConnectTime()
void
setConnectTime(long time)
This is only intended for use by SampleResultConverter! JMeterContext.TestLogicalAction
getTestLogicalAction()
void
setTestLogicalAction(JMeterContext.TestLogicalAction testLogicalAction)
int
getSampleCount()
return the sample count. void
setSampleCount(int count)
The statistical sample sender aggregates several samples to save on transmission costs. int
getHeadersSize()
Get the headers size in bytes void
setHeadersSize(int size)
Set the headers size in bytes int
getGroupThreads()
void
setGroupThreads(int n)
int
getAllThreads()
void
setAllThreads(int n)
long
getSentBytes()
void
setSentBytes(long sentBytesCount)
String
getResponseDataAsString()
Gets the responseData of the SampleResult object as a String boolean
isStampedAtStart()
static SampleResult
createTestSample(long start, long end)
Create a sample with specific start and end times for test purposes, but don't allow the times to be changed later (used by StatVisualizerModel. static SampleResult
createTestSample(long elapsed)
Create a sample with a specific elapsed time for test purposes, but don't allow the times to be changed later long
currentTimeInMillis()
Helper method to get 1 ms resolution timing. void
setStampAndTime(long stamp, long elapsed)
For use by SaveService only. boolean
markFile(String filename)
Set the "marked" flag to show that the result has been written to the file. void
setResponseCodeOK()
Set response code to OK, i.e. boolean
isResponseCodeOK()
void
setResponseMessageOK()
void
setResponseOK()
Set result statuses OK - shorthand method to set: - ResponseCode
- ResponseMessage
- Successful status
String
getSampleLabel()
String
getSampleLabel(boolean includeGroup)
Get the sample label for use in summary reports etc. void
setSampleLabel(String label)
void
addAssertionResult(AssertionResult assertResult)
Array<AssertionResult>
getAssertionResults()
Gets the assertion results associated with this sample. void
addSubResult(SampleResult subResult)
Add a subresult and adjust the parent byte count and end-time. static boolean
isRenameSampleLabel()
see https://bz.apache.org/bugzilla/show_bug.cgi? void
addSubResult(SampleResult subResult, boolean renameSubResults)
Add a subresult and adjust the parent byte count and end-time. void
addRawSubResult(SampleResult subResult)
Add a subresult to the collection without updating any parent fields. void
storeSubResult(SampleResult subResult)
Add a subresult read from a results file. void
storeSubResult(SampleResult subResult, boolean renameSubResults)
Add a subresult read from a results file. Array<SampleResult>
getSubResults()
Gets the subresults associated with this sample. void
setResponseData(String response)
Sets the responseData attribute of the SampleResult object. void
setResponseData(String response, String encoding)
Sets the encoding and responseData attributes of the SampleResult object. long
getTime()
Get the time it took this sample to occur. boolean
isSuccessful()
void
setEncodingAndType(String ct)
Extract and save the DataEncoding and DataType from the parameter provided. static boolean
isBinaryType(String ct)
void
setSuccessful(boolean success)
Sets the successful attribute of the SampleResult object. String
toString()
Returns the display name. String
toDebugString()
String
getDataEncodingWithDefault()
Returns the dataEncoding or the default if no dataEncoding was provided. String
getDataEncodingNoDefault()
Returns the dataEncoding. boolean
isStopTest()
boolean
isStopTestNow()
boolean
isStopThread()
String
getMediaType()
Get the media type from the Content Type void
sampleStart()
Record the start time of a sample void
sampleEnd()
Record the end time of a sample and calculate the elapsed time void
samplePause()
Pause a sample void
sampleResume()
Resume a sample void
setMonitor(boolean monitor)
When a Sampler is working as a monitor boolean
isMonitor()
If the sampler is a monitor, method will return true. int
getErrorCount()
Returns the count of errors. void
setErrorCount(int i)
void
setBytes(int length)
In the event the sampler does want to pass back the actual contents, we still want to calculate the throughput. int
getBytes()
return the bytes returned by the response. long
getBytesAsLong()
return the bytes returned by the response. void
latencyEnd()
Set the time to the first response void
connectEnd()
Set the time to the end of connecting void
setURL(URL location)
URL
getURL()
String
getUrlAsString()
Get a String representation of the URL (if defined). void
removeAssertionResults()
Allow custom SampleSenders to drop unwanted assertionResults void
removeSubResults()
Allow custom SampleSenders to drop unwanted subResults int
getBodySize()
long
getBodySizeAsLong()
void
setBodySize(int bodySize)
boolean
isStartNextThreadLoop()
void
setStartNextThreadLoop(boolean startNextThreadLoop)
void
cleanAfterSample()
Clean up cached data Object
clone()
List<String>
getSearchableTokens()
Get a list of all tokens that should be visible to searching boolean
isIgnore()
void
setIgnore()
Call this method to tell JMeter to ignore this SampleResult by Listeners String
getFirstAssertionFailureMessage()
void
setDataEncoding(String dataEncoding)
Sets the dataEncoding. void
setStopTest(boolean b)
void
setStopTestNow(boolean b)
void
setStopThread(boolean b)
void
setBytes(long length)
In the event the sampler does want to pass back the actual contents, we still want to calculate the throughput. void
setBodySize(long bodySize)
-
-
Constructor Detail
-
SampleResult
SampleResult()
-
SampleResult
SampleResult(SampleResult res)
Copy constructor.- Parameters:
res
- existing sample result
-
SampleResult
SampleResult(long stamp, long elapsed)
Allow users to create a sample with specific timestamp and elapsed times for cloning purposes, but don't allow the times to be changed later Currently used by CSVSaveService and StatisticalSampleResult- Parameters:
stamp
- this may be a start time or an end time (both in milliseconds)elapsed
- time in milliseconds
-
-
Method Detail
-
getSaveConfig
SampleSaveConfiguration getSaveConfig()
-
setSaveConfig
void setSaveConfig(SampleSaveConfiguration propertiesToSave)
- Parameters:
propertiesToSave
- The propertiesToSave to set.
-
getParent
SampleResult getParent()
- Returns:
Returns the parent.
-
setParent
void setParent(SampleResult parent)
- Parameters:
parent
- The parent to set.
-
getResponseData
Array<byte> getResponseData()
Gets the responseData attribute of the SampleResult object.
Note that some samplers may not store all the data, in which case getResponseData().length will be incorrect. Instead, always use getBytes to obtain the sample result byte count.
- Returns:
the responseData value (cannot be null)
-
setResponseData
void setResponseData(Array<byte> response)
Sets the responseData attribute of the SampleResult object. If the parameter is null, then the responseData is set to an empty byte array. This ensures that getResponseData() can never be null.
- Parameters:
response
- the new responseData value
-
getResponseCode
String getResponseCode()
-
setResponseCode
void setResponseCode(String code)
-
getResultFileName
String getResultFileName()
-
setResultFileName
void setResultFileName(String resultFileName)
-
getSamplerData
String getSamplerData()
-
setSamplerData
void setSamplerData(String s)
-
getThreadName
String getThreadName()
-
setThreadName
void setThreadName(String threadName)
-
getResponseMessage
String getResponseMessage()
-
setResponseMessage
void setResponseMessage(String msg)
-
getResponseHeaders
String getResponseHeaders()
- Returns:
the response headers
-
setResponseHeaders
void setResponseHeaders(String string)
- Parameters:
string
- - response headers
-
getRequestHeaders
String getRequestHeaders()
- Returns:
the request headers
-
setRequestHeaders
void setRequestHeaders(String string)
- Parameters:
string
- - request headers
-
getTimeStamp
long getTimeStamp()
Get the sample timestamp, which may be either the start time or the end time.
- Returns:
timeStamp in milliseconds
-
setTimeStamp
void setTimeStamp(long timeStamp)
This is only intended for use by SampleResultConverter!
- Parameters:
timeStamp
- The timeStamp to set.
-
getStartTime
long getStartTime()
- Returns:
the start time
-
getEndTime
long getEndTime()
- Returns:
the end time
-
setEndTime
void setEndTime(long end)
-
getIdleTime
long getIdleTime()
- Returns:
idleTime
-
setIdleTime
void setIdleTime(long idle)
Set idle time pause. For use by SampleResultConverter/CSVSaveService.
- Parameters:
idle
- long
-
getDataType
String getDataType()
Returns the data type of the sample.
-
setDataType
void setDataType(String dataType)
Sets the data type of the sample.
-
getContentType
String getContentType()
- Returns:
the full content type - e.g. text/html [;charset=utf-8 ]
-
setContentType
void setContentType(String string)
Stores the content-type string, e.g.
text/xml; charset=utf-8
- Parameters:
string
- the content-type to be set
-
getLatency
long getLatency()
- Returns:
Returns the latency.
-
setLatency
void setLatency(long latency)
This is only intended for use by SampleResultConverter!
- Parameters:
latency
- The latency to set.
-
getConnectTime
long getConnectTime()
- Returns:
Returns the connect time.
-
setConnectTime
void setConnectTime(long time)
This is only intended for use by SampleResultConverter!
- Parameters:
time
- The connect time to set.
-
getTestLogicalAction
JMeterContext.TestLogicalAction getTestLogicalAction()
- Returns:
the testLogicalAction
-
setTestLogicalAction
void setTestLogicalAction(JMeterContext.TestLogicalAction testLogicalAction)
- Parameters:
testLogicalAction
- the testLogicalAction to set
-
getSampleCount
int getSampleCount()
return the sample count. by default, the value is 1.
- Returns:
the sample count
-
setSampleCount
void setSampleCount(int count)
The statistical sample sender aggregates several samples to save on transmission costs.
- Parameters:
count
- number of samples represented by this instance
-
getHeadersSize
int getHeadersSize()
Get the headers size in bytes
- Returns:
the headers size
-
setHeadersSize
void setHeadersSize(int size)
Set the headers size in bytes
- Parameters:
size
- the number of bytes of the header
-
getGroupThreads
int getGroupThreads()
-
setGroupThreads
void setGroupThreads(int n)
-
getAllThreads
int getAllThreads()
-
setAllThreads
void setAllThreads(int n)
-
getSentBytes
long getSentBytes()
- Returns:
the sentBytes
-
setSentBytes
void setSentBytes(long sentBytesCount)
- Parameters:
sentBytesCount
- long sent bytes
-
getResponseDataAsString
String getResponseDataAsString()
Gets the responseData of the SampleResult object as a String
- Returns:
the responseData value as a String, converted according to the encoding
-
isStampedAtStart
boolean isStampedAtStart()
-
createTestSample
static SampleResult createTestSample(long start, long end)
Create a sample with specific start and end times for test purposes, but don't allow the times to be changed later (used by StatVisualizerModel.Test)
- Parameters:
start
- start time in milliseconds since unix epochend
- end time in milliseconds since unix epoch- Returns:
sample with given start and end time
-
createTestSample
static SampleResult createTestSample(long elapsed)
Create a sample with a specific elapsed time for test purposes, but don't allow the times to be changed later
- Parameters:
elapsed
- - desired elapsed time in milliseconds- Returns:
sample that starts 'now' and ends
elapsed
milliseconds later
-
currentTimeInMillis
long currentTimeInMillis()
Helper method to get 1 ms resolution timing.
- Returns:
the current time in milliseconds
-
setStampAndTime
void setStampAndTime(long stamp, long elapsed)
For use by SaveService only.
- Parameters:
stamp
- this may be a start time or an end time (both in milliseconds)elapsed
- time in milliseconds
-
markFile
boolean markFile(String filename)
Set the "marked" flag to show that the result has been written to the file.
- Parameters:
filename
- the name of the file- Returns:
true
if the result was previously marked
-
setResponseCodeOK
void setResponseCodeOK()
Set response code to OK, i.e. "200"
-
isResponseCodeOK
boolean isResponseCodeOK()
-
setResponseMessageOK
void setResponseMessageOK()
-
setResponseOK
void setResponseOK()
Set result statuses OK - shorthand method to set:
- ResponseCode
- ResponseMessage
- Successful status
-
getSampleLabel
String getSampleLabel()
-
getSampleLabel
String getSampleLabel(boolean includeGroup)
Get the sample label for use in summary reports etc.
- Parameters:
includeGroup
- whether to include the thread group name- Returns:
the label
-
setSampleLabel
void setSampleLabel(String label)
-
addAssertionResult
void addAssertionResult(AssertionResult assertResult)
-
getAssertionResults
Array<AssertionResult> getAssertionResults()
Gets the assertion results associated with this sample.
- Returns:
an array containing the assertion results for this sample. Returns empty array if there are no assertion results.
-
addSubResult
void addSubResult(SampleResult subResult)
Add a subresult and adjust the parent byte count and end-time.
- Parameters:
subResult
- the SampleResult to be added
-
isRenameSampleLabel
static boolean isRenameSampleLabel()
see https://bz.apache.org/bugzilla/show_bug.cgi?id=63055
- Returns:
true if TestPlan is in functional mode or property subresults.disable_renaming is true
-
addSubResult
void addSubResult(SampleResult subResult, boolean renameSubResults)
Add a subresult and adjust the parent byte count and end-time.
- Parameters:
subResult
- the SampleResult to be addedrenameSubResults
- boolean do we rename subResults based on position
-
addRawSubResult
void addRawSubResult(SampleResult subResult)
Add a subresult to the collection without updating any parent fields.
- Parameters:
subResult
- the SampleResult to be added
-
storeSubResult
void storeSubResult(SampleResult subResult)
Add a subresult read from a results file.
As for addSubResult(SampleResult), except that the fields don't need to be accumulated
- Parameters:
subResult
- the SampleResult to be added
-
storeSubResult
void storeSubResult(SampleResult subResult, boolean renameSubResults)
Add a subresult read from a results file.
As for addSubResult(SampleResult), except that the fields don't need to be accumulated
- Parameters:
subResult
- the SampleResult to be addedrenameSubResults
- boolean do we rename subResults based on position
-
getSubResults
Array<SampleResult> getSubResults()
Gets the subresults associated with this sample.
- Returns:
an array containing the subresults for this sample. Returns an empty array if there are no subresults.
-
setResponseData
@Deprecated() void setResponseData(String response)
Sets the responseData attribute of the SampleResult object. Should only be called after setting the dataEncoding (if necessary)
- Parameters:
response
- the new responseData value (String)
-
setResponseData
void setResponseData(String response, String encoding)
Sets the encoding and responseData attributes of the SampleResult object.
- Parameters:
response
- the new responseData value (String)encoding
- the encoding to set and then use (if null, use platform default)
-
getTime
long getTime()
Get the time it took this sample to occur.
- Returns:
elapsed time in milliseconds
-
isSuccessful
boolean isSuccessful()
-
setEncodingAndType
void setEncodingAndType(String ct)
Extract and save the DataEncoding and DataType from the parameter provided. Does not save the full content Type.
- Parameters:
ct
- - content type (may be null)
-
isBinaryType
static boolean isBinaryType(String ct)
-
setSuccessful
void setSuccessful(boolean success)
Sets the successful attribute of the SampleResult object.
- Parameters:
success
- the new successful value
-
toDebugString
String toDebugString()
-
getDataEncodingWithDefault
String getDataEncodingWithDefault()
Returns the dataEncoding or the default if no dataEncoding was provided.
- Returns:
the value of the dataEncoding or DEFAULT_ENCODING
-
getDataEncodingNoDefault
String getDataEncodingNoDefault()
Returns the dataEncoding. May be null or the empty String.
- Returns:
the value of the dataEncoding
-
isStopTest
boolean isStopTest()
- Returns:
whether to stop the test waiting for current running Sampler to end
-
isStopTestNow
boolean isStopTestNow()
- Returns:
whether to stop the test now interrupting current running samplers
-
isStopThread
boolean isStopThread()
- Returns:
whether to stop this thread
-
getMediaType
String getMediaType()
Get the media type from the Content Type
- Returns:
the media type - e.g. text/html (without charset, if any)
-
sampleStart
void sampleStart()
Record the start time of a sample
-
sampleEnd
void sampleEnd()
Record the end time of a sample and calculate the elapsed time
-
samplePause
void samplePause()
Pause a sample
-
sampleResume
void sampleResume()
Resume a sample
-
setMonitor
@Deprecated() void setMonitor(boolean monitor)
When a Sampler is working as a monitor
- Parameters:
monitor
- flag whether this sampler is working as a monitor
-
isMonitor
@Deprecated() boolean isMonitor()
If the sampler is a monitor, method will return true.
- Returns:
true if the sampler is a monitor
-
getErrorCount
int getErrorCount()
Returns the count of errors.
- Returns:
0 - or 1 if the sample failed TODO do we need allow for nested samples?
-
setErrorCount
void setErrorCount(int i)
-
setBytes
@Deprecated() void setBytes(int length)
In the event the sampler does want to pass back the actual contents, we still want to calculate the throughput. The bytes are the bytes of the response data.
- Parameters:
length
- the number of bytes of the response data for this sample
-
getBytes
@Deprecated() int getBytes()
return the bytes returned by the response.
- Returns:
byte count
-
getBytesAsLong
long getBytesAsLong()
return the bytes returned by the response.
- Returns:
byte count
-
latencyEnd
void latencyEnd()
Set the time to the first response
-
connectEnd
void connectEnd()
Set the time to the end of connecting
-
getUrlAsString
String getUrlAsString()
Get a String representation of the URL (if defined).
- Returns:
ExternalForm of URL, or empty string if url is null
-
removeAssertionResults
void removeAssertionResults()
Allow custom SampleSenders to drop unwanted assertionResults
-
removeSubResults
void removeSubResults()
Allow custom SampleSenders to drop unwanted subResults
-
getBodySize
@Deprecated() int getBodySize()
- Returns:
the body size in bytes
-
getBodySizeAsLong
long getBodySizeAsLong()
- Returns:
the body size in bytes
-
setBodySize
@Deprecated() void setBodySize(int bodySize)
- Parameters:
bodySize
- the body size to set
-
isStartNextThreadLoop
@Deprecated() boolean isStartNextThreadLoop()
- Returns:
the startNextThreadLoop
-
setStartNextThreadLoop
@Deprecated() void setStartNextThreadLoop(boolean startNextThreadLoop)
- Parameters:
startNextThreadLoop
- the startNextLoop to set
-
cleanAfterSample
void cleanAfterSample()
Clean up cached data
-
getSearchableTokens
List<String> getSearchableTokens()
Get a list of all tokens that should be visible to searching
- Returns:
List of searchable tokens
-
isIgnore
boolean isIgnore()
- Returns:
boolean true if this SampleResult should not be sent to Listeners
-
setIgnore
void setIgnore()
Call this method to tell JMeter to ignore this SampleResult by Listeners
-
getFirstAssertionFailureMessage
String getFirstAssertionFailureMessage()
- Returns:
String first non null assertion failure message if assertionResults is not null, null otherwise
-
setDataEncoding
void setDataEncoding(String dataEncoding)
Sets the dataEncoding.
- Parameters:
dataEncoding
- the dataEncoding to set, e.g.
-
setStopTest
void setStopTest(boolean b)
-
setStopTestNow
void setStopTestNow(boolean b)
-
setStopThread
void setStopThread(boolean b)
-
setBytes
void setBytes(long length)
In the event the sampler does want to pass back the actual contents, we still want to calculate the throughput. The bytes are the bytes of the response data.
- Parameters:
length
- the number of bytes of the response data for this sample
-
setBodySize
void setBodySize(long bodySize)
- Parameters:
bodySize
- the body size to set
-
-
-