Package org.apache.jmeter.samplers
Class SampleResult
java.lang.Object
org.apache.jmeter.samplers.SampleResult
- All Implemented Interfaces:
- Serializable,- Cloneable,- Searchable
- Direct Known Subclasses:
- HTTPSampleResult,- StatisticalSampleResult
This is a nice packaging for the various information returned from taking a
 sample of an entry.
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringData type value ("bin") indicating that the response data is binary.protected static final StringThe default encoding to be used to decode the responseData byte array.static final StringThe default encoding to be used if not overridden.static final StringData type value ("text") indicating that the response data is text.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedSampleResult(long elapsed, boolean atend) Create a sample with a specific elapsed time but don't allow the times to be changed later (only used by HTTPSampleResult)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 StatisticalSampleResultSampleResult(SampleResult res) Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAssertionResult(AssertionResult assertResult) voidaddRawSubResult(SampleResult subResult) Add a subresult to the collection without updating any parent fields.voidaddSubResult(SampleResult subResult) Add a subresult and adjust the parent byte count and end-time.voidaddSubResult(SampleResult subResult, boolean renameSubResults) Add a subresult and adjust the parent byte count and end-time.protected voidvoidClean up cached dataclone()voidSet the time to the end of connectingstatic SampleResultcreateTestSample(long elapsed) Create a sample with a specific elapsed time for test purposes, but don't allow the times to be changed laterstatic SampleResultcreateTestSample(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)longHelper method to get 1 ms resolution timing.intGets the assertion results associated with this sample.intDeprecated.replaced by getBodySizeAsLong()longintgetBytes()Deprecated.use getBytesAsLonglongreturn the bytes returned by the response.longReturns the dataEncoding.Returns the dataEncoding or the default if no dataEncoding was provided.protected StringgetDataEncodingWithDefault(String defaultEncoding) Returns the dataEncoding or the default if no dataEncoding was provided.Returns the data type of the sample.longintReturns the count of errors.intintGet the headers size in byteslonglongGet the media type from the Content Typebyte[]Gets the responseData attribute of the SampleResult object.Gets the responseData of the SampleResult object as a Stringintreturn the sample count.getSampleLabel(boolean includeGroup) Get the sample label for use in summary reports etc.Get a list of all tokens that should be visible to searchinglonglongGets the subresults associated with this sample.longgetTime()Get the time it took this sample to occur.longGet the sample timestamp, which may be either the start time or the end time.getURL()Get a String representation of the URL (if defined).static booleanisBinaryType(String ct) booleanisIgnore()booleanDeprecated.since 3.2 always return falsestatic booleansee https://bz.apache.org/bugzilla/show_bug.cgi?id=63055booleanbooleanbooleanDeprecated.booleanbooleanbooleanbooleanvoidSet the time to the first responsebooleanSet the "marked" flag to show that the result has been written to the file.voidAllow custom SampleSenders to drop unwanted assertionResultsvoidAllow custom SampleSenders to drop unwanted subResultsvoidRecord the end time of a sample and calculate the elapsed timevoidPause a samplevoidResume a samplevoidRecord the start time of a samplevoidsetAllThreads(int n) voidsetBodySize(int bodySize) Deprecated.use setBodySize(long)voidsetBodySize(long bodySize) voidsetBytes(int length) Deprecated.use setBytes(long)voidsetBytes(long length) In the event the sampler does want to pass back the actual contents, we still want to calculate the throughput.voidsetConnectTime(long time) This is only intended for use by SampleResultConverter!voidsetContentType(String string) Stores the content-type string, e.g.voidsetDataEncoding(String dataEncoding) Sets the dataEncoding.voidsetDataType(String dataType) Sets the data type of the sample.voidExtract and save the DataEncoding and DataType from the parameter provided.voidsetEndTime(long end) voidsetErrorCount(int i) voidsetGroupThreads(int n) voidsetHeadersSize(int size) Set the headers size in bytesvoidsetIdleTime(long idle) Set idle time pause.voidCall this method to tell JMeter to ignore this SampleResult by ListenersvoidsetLatency(long latency) This is only intended for use by SampleResultConverter!voidsetMonitor(boolean monitor) Deprecated.since 3.2 NOOPvoidsetParent(SampleResult parent) voidsetRequestHeaders(String string) voidsetResponseCode(String code) voidSet response code to OK, i.e.voidsetResponseData(byte[] response) Sets the responseData attribute of the SampleResult object.voidsetResponseData(String response) Deprecated.- only intended for use from BeanShell codevoidsetResponseData(String response, String encoding) Sets the encoding and responseData attributes of the SampleResult object.voidsetResponseHeaders(String string) voidsetResponseMessage(String msg) voidvoidSet result statuses OK - shorthand method to set: ResponseCode ResponseMessage Successful statusvoidsetResultFileName(String resultFileName) voidsetSampleCount(int count) The statistical sample sender aggregates several samples to save on transmission costs.voidsetSampleLabel(String label) voidvoidsetSaveConfig(SampleSaveConfiguration propertiesToSave) voidsetSentBytes(long sentBytesCount) voidsetStampAndTime(long stamp, long elapsed) For use by SaveService only.voidsetStartNextThreadLoop(boolean startNextThreadLoop) Deprecated.use SampleResult#setTestLogicalAction(TestLogicalAction)protected final voidsetStartTime(long start) voidsetStopTest(boolean b) voidsetStopTestNow(boolean b) voidsetStopThread(boolean b) voidsetSuccessful(boolean success) Sets the successful attribute of the SampleResult object.voidsetTestLogicalAction(JMeterContext.TestLogicalAction testLogicalAction) voidsetThreadName(String threadName) voidsetTimeStamp(long timeStamp) This is only intended for use by SampleResultConverter!voidvoidstoreSubResult(SampleResult subResult) Add a subresult read from a results file.voidstoreSubResult(SampleResult subResult, boolean renameSubResults) Add a subresult read from a results file.toString()Returns the display name.
- 
Field Details- 
DEFAULT_HTTP_ENCODINGThe default encoding to be used if not overridden. The value is ISO-8859-1.
- 
DEFAULT_ENCODINGThe default encoding to be used to decode the responseData byte array. The value is defined by the property "sampleresult.default.encoding" with a default ofDEFAULT_HTTP_ENCODINGif that is not defined.
- 
TEXTData type value ("text") indicating that the response data is text.
- 
BINARYData type value ("bin") indicating that the response data is binary.
 
- 
- 
Constructor Details- 
SampleResultpublic SampleResult()
- 
SampleResultCopy constructor.- Parameters:
- res- existing sample result
 
- 
SampleResultprotected SampleResult(long elapsed, boolean atend) Create a sample with a specific elapsed time but don't allow the times to be changed later (only used by HTTPSampleResult)- Parameters:
- elapsed- time
- atend- create the sample finishing now, else starting now
 
- 
SampleResultpublic 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 Details- 
setSaveConfig- Parameters:
- propertiesToSave- The propertiesToSave to set.
 
- 
getSaveConfig
- 
isStampedAtStartpublic boolean isStampedAtStart()
- 
createTestSampleCreate 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 epoch
- end- end time in milliseconds since unix epoch
- Returns:
- sample with given start and end time
 
- 
createTestSampleCreate 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 elapsedmilliseconds later
 
- 
currentTimeInMillispublic long currentTimeInMillis()Helper method to get 1 ms resolution timing.- Returns:
- the current time in milliseconds
- Throws:
- RuntimeException- when- useNanoTimeis- truebut- nanoTimeOffsetis not set
 
- 
setStampAndTimepublic 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
- Throws:
- RuntimeException- when- startTimeor- endTimehas been set already
 
- 
markFileSet the "marked" flag to show that the result has been written to the file.- Parameters:
- filename- the name of the file
- Returns:
- trueif the result was previously marked
 
- 
getResponseCode
- 
setResponseCodeOKpublic void setResponseCodeOK()Set response code to OK, i.e. "200"
- 
setResponseCode
- 
isResponseCodeOKpublic boolean isResponseCodeOK()
- 
getResponseMessage
- 
setResponseMessage
- 
setResponseMessageOKpublic void setResponseMessageOK()
- 
setResponseOKpublic void setResponseOK()Set result statuses OK - shorthand method to set:- ResponseCode
- ResponseMessage
- Successful status
 
- 
getThreadName
- 
setThreadName
- 
getTimeStamppublic long getTimeStamp()Get the sample timestamp, which may be either the start time or the end time.- Returns:
- timeStamp in milliseconds
- See Also:
 
- 
getSampleLabel
- 
getSampleLabelGet the sample label for use in summary reports etc.- Parameters:
- includeGroup- whether to include the thread group name
- Returns:
- the label
 
- 
setSampleLabel
- 
addAssertionResult
- 
getAssertionResultsGets 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.
 
- 
addSubResultAdd a subresult and adjust the parent byte count and end-time.- Parameters:
- subResult- the- SampleResultto be added
 
- 
isRenameSampleLabelpublic 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
 
- 
addSubResultAdd a subresult and adjust the parent byte count and end-time.- Parameters:
- subResult- the- SampleResultto be added
- renameSubResults- boolean do we rename subResults based on position
 
- 
addRawSubResultAdd a subresult to the collection without updating any parent fields.- Parameters:
- subResult- the- SampleResultto be added
 
- 
storeSubResultAdd a subresult read from a results file.As for addSubResult(SampleResult), except that the fields don't need to be accumulated- Parameters:
- subResult- the- SampleResultto be added
 
- 
storeSubResultAdd a subresult read from a results file.As for addSubResult(SampleResult), except that the fields don't need to be accumulated- Parameters:
- subResult- the- SampleResultto be added
- renameSubResults- boolean do we rename subResults based on position
 
- 
getSubResultsGets the subresults associated with this sample.- Returns:
- an array containing the subresults for this sample. Returns an empty array if there are no subresults.
 
- 
setResponseDatapublic void setResponseData(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
 
- 
setResponseDataDeprecated.- only intended for use from BeanShell codeSets the responseData attribute of the SampleResult object. Should only be called after setting the dataEncoding (if necessary)- Parameters:
- response- the new responseData value (String)
 
- 
setResponseDataSets 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)
 
- 
getResponseDatapublic 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)
 
- 
getResponseDataAsStringGets the responseData of the SampleResult object as a String- Returns:
- the responseData value as a String, converted according to the encoding
 
- 
setSamplerData
- 
getSamplerData
- 
getTimepublic long getTime()Get the time it took this sample to occur.- Returns:
- elapsed time in milliseconds
 
- 
isSuccessfulpublic boolean isSuccessful()
- 
setDataTypeSets the data type of the sample.
- 
getDataTypeReturns the data type of the sample.
- 
setEncodingAndTypeExtract and save the DataEncoding and DataType from the parameter provided. Does not save the full content Type.- Parameters:
- ct- - content type (may be null)
- See Also:
 
- 
isBinaryType
- 
setSuccessfulpublic void setSuccessful(boolean success) Sets the successful attribute of the SampleResult object.- Parameters:
- success- the new successful value
 
- 
toStringReturns the display name.
- 
toDebugString
- 
appendDebugParameters
- 
getDataEncodingWithDefaultReturns the dataEncoding or the default if no dataEncoding was provided.- Returns:
- the value of the dataEncoding or DEFAULT_ENCODING
 
- 
getDataEncodingWithDefaultReturns the dataEncoding or the default if no dataEncoding was provided.- Parameters:
- defaultEncoding- the default to be applied
- Returns:
- the value of the dataEncoding or the provided default
 
- 
getDataEncodingNoDefaultReturns the dataEncoding. May be null or the empty String.- Returns:
- the value of the dataEncoding
 
- 
setDataEncodingSets the dataEncoding.- Parameters:
- dataEncoding- the dataEncoding to set, e.g. ISO-8895-1, UTF-8
 
- 
isStopTestpublic boolean isStopTest()- Returns:
- whether to stop the test waiting for current running Sampler to end
 
- 
isStopTestNowpublic boolean isStopTestNow()- Returns:
- whether to stop the test now interrupting current running samplers
 
- 
isStopThreadpublic boolean isStopThread()- Returns:
- whether to stop this thread
 
- 
setStopTestpublic void setStopTest(boolean b) 
- 
setStopTestNowpublic void setStopTestNow(boolean b) 
- 
setStopThreadpublic void setStopThread(boolean b) 
- 
getRequestHeaders- Returns:
- the request headers
 
- 
getResponseHeaders- Returns:
- the response headers
 
- 
setRequestHeaders- Parameters:
- string- - request headers
 
- 
setResponseHeaders- Parameters:
- string- - response headers
 
- 
getContentType- Returns:
- the full content type - e.g. text/html [;charset=utf-8 ]
 
- 
getMediaTypeGet the media type from the Content Type- Returns:
- the media type - e.g. text/html (without charset, if any)
 
- 
setContentTypeStores the content-type string, e.g.text/xml; charset=utf-8- Parameters:
- string- the content-type to be set
- See Also:
 
- 
getIdleTimepublic long getIdleTime()- Returns:
- idleTime
 
- 
getEndTimepublic long getEndTime()- Returns:
- the end time
 
- 
getStartTimepublic long getStartTime()- Returns:
- the start time
 
- 
setStartTimeprotected final void setStartTime(long start) 
- 
setEndTimepublic void setEndTime(long end) 
- 
setIdleTimepublic void setIdleTime(long idle) Set idle time pause. For use by SampleResultConverter/CSVSaveService.- Parameters:
- idle- long
 
- 
sampleStartpublic void sampleStart()Record the start time of a sample
- 
sampleEndpublic void sampleEnd()Record the end time of a sample and calculate the elapsed time
- 
samplePausepublic void samplePause()Pause a sample
- 
sampleResumepublic void sampleResume()Resume a sample
- 
setMonitorDeprecated.since 3.2 NOOPWhen a Sampler is working as a monitor- Parameters:
- monitor- flag whether this sampler is working as a monitor
 
- 
isMonitorDeprecated.since 3.2 always return falseIf the sampler is a monitor, method will return true.- Returns:
- true if the sampler is a monitor
 
- 
setSampleCountpublic 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
 
- 
getSampleCountpublic int getSampleCount()return the sample count. by default, the value is 1.- Returns:
- the sample count
 
- 
getErrorCountpublic int getErrorCount()Returns the count of errors.- Returns:
- 0 - or 1 if the sample failed TODO do we need allow for nested samples?
 
- 
setErrorCountpublic void setErrorCount(int i) 
- 
setBytespublic 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
 
- 
setBytesDeprecated.use setBytes(long)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
 
- 
setSentBytespublic void setSentBytes(long sentBytesCount) - Parameters:
- sentBytesCount- long sent bytes
 
- 
getSentBytespublic long getSentBytes()- Returns:
- the sentBytes
 
- 
getBytesDeprecated.use getBytesAsLongreturn the bytes returned by the response.- Returns:
- byte count
 
- 
getBytesAsLongpublic long getBytesAsLong()return the bytes returned by the response.- Returns:
- byte count
 
- 
getLatencypublic long getLatency()- Returns:
- Returns the latency.
 
- 
latencyEndpublic void latencyEnd()Set the time to the first response
- 
setLatencypublic void setLatency(long latency) This is only intended for use by SampleResultConverter!- Parameters:
- latency- The latency to set.
 
- 
getConnectTimepublic long getConnectTime()- Returns:
- Returns the connect time.
 
- 
connectEndpublic void connectEnd()Set the time to the end of connecting
- 
setConnectTimepublic void setConnectTime(long time) This is only intended for use by SampleResultConverter!- Parameters:
- time- The connect time to set.
 
- 
setTimeStamppublic void setTimeStamp(long timeStamp) This is only intended for use by SampleResultConverter!- Parameters:
- timeStamp- The timeStamp to set.
 
- 
setURL
- 
getURL
- 
getUrlAsStringGet a String representation of the URL (if defined).- Returns:
- ExternalForm of URL, or empty string if url is null
 
- 
getParent- Returns:
- Returns the parent.
 
- 
setParent- Parameters:
- parent- The parent to set.
 
- 
getResultFileName
- 
setResultFileName
- 
getGroupThreadspublic int getGroupThreads()
- 
setGroupThreadspublic void setGroupThreads(int n) 
- 
getAllThreadspublic int getAllThreads()
- 
setAllThreadspublic void setAllThreads(int n) 
- 
removeAssertionResultspublic void removeAssertionResults()Allow custom SampleSenders to drop unwanted assertionResults
- 
removeSubResultspublic void removeSubResults()Allow custom SampleSenders to drop unwanted subResults
- 
setHeadersSizepublic void setHeadersSize(int size) Set the headers size in bytes- Parameters:
- size- the number of bytes of the header
 
- 
getHeadersSizepublic int getHeadersSize()Get the headers size in bytes- Returns:
- the headers size
 
- 
getBodySizeDeprecated.replaced by getBodySizeAsLong()- Returns:
- the body size in bytes
 
- 
getBodySizeAsLongpublic long getBodySizeAsLong()- Returns:
- the body size in bytes
 
- 
setBodySizepublic void setBodySize(long bodySize) - Parameters:
- bodySize- the body size to set
 
- 
setBodySizeDeprecated.use setBodySize(long)- Parameters:
- bodySize- the body size to set
 
- 
isStartNextThreadLoopDeprecated.- Returns:
- the startNextThreadLoop
 
- 
setStartNextThreadLoopDeprecated.use SampleResult#setTestLogicalAction(TestLogicalAction)- Parameters:
- startNextThreadLoop- the startNextLoop to set
 
- 
cleanAfterSamplepublic void cleanAfterSample()Clean up cached data
- 
clone
- 
getSearchableTokensDescription copied from interface:SearchableGet a list of all tokens that should be visible to searching- Specified by:
- getSearchableTokensin interface- Searchable
- Returns:
- List of searchable tokens
- Throws:
- Exception- when something fails while getting the searchable tokens
 
- 
isIgnorepublic boolean isIgnore()- Returns:
- boolean true if this SampleResult should not be sent to Listeners
 
- 
setIgnorepublic void setIgnore()Call this method to tell JMeter to ignore this SampleResult by Listeners
- 
getFirstAssertionFailureMessage- Returns:
- String first non null assertion failure message if assertionResults is not null, null otherwise
 
- 
getTestLogicalAction- Returns:
- the testLogicalAction
 
- 
setTestLogicalAction- Parameters:
- testLogicalAction- the testLogicalAction to set
 
 
-