Class MethodTrack
java.lang.Object
ru.vyarus.dropwizard.guice.test.track.MethodTrack
- All Implemented Interfaces:
Comparable<MethodTrack>
Represents single method execution. Method arguments and the result stored as raw objects and in string form:
this is required because raw objects might be mutable and could change in another method, before test verification
would access them. Raw objects interception might be disabled, and so there would be nulls (string representations
would always be).
For the console output, it is preferred to wrap string values with quotes (to clearly see string bounds). Use
getQuotedArguments() and getQuotedResult() for console output (as toStringTrack() do).
Bean instance, where method was called, is identified by unique hash: getInstanceHash() (this is the same
string as in default Object.toString (@something part)). Hash is required to detect method calls to different
instances.
The same metrics timer used to track calls of the same method (even for different objects).
- Since:
- 11.02.2025
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintString[]String representation details: - Primitive values, number and booleans stored as is - String values could be truncated (by default 30 chars allowed) - Objects represented as ObjectType@instanceHash - null is "null".String[]Almost the same asgetArguments(), but all string arguments wrapped with quotes (to see string bounds).Almost the same asgetResult(), but, if the result returns string, quote it to see bounds.Object[]WARNING: arguments could contain mutable objects, changed after method call (or even during the call) and so be careful when use it (e.g., for reporting) - values might not be actual.WARNING: the result could be a mutable objects, changed after method call and so be careful when use it (e.g. for reporting) - value might not be exactly the same as returned value after the call.Note that if the method is void, a string result would also be null.Class<?>longcom.codahale.metrics.TimergetTimer()booleanbooleantoString()
-
Constructor Details
-
MethodTrack
public MethodTrack(Class<?> service, Method method, String instanceHash, long started, Duration duration, Object[] rawArguments, String[] arguments, Object rawResult, String result, Throwable throwable, boolean[] stringMarkers, com.codahale.metrics.Timer timer) Create track.- Parameters:
service- service typemethod- methodinstanceHash- service instance hashstarted- start timeduration- durationrawArguments- raw argumentsarguments- string argumentsrawResult- raw resultresult- string resultthrowable- exceptionstringMarkers- string arguments markerstimer- metrics
-
-
Method Details
-
getMethod
- Returns:
- called method
-
getService
- Returns:
- type of called guice bean
-
getInstanceHash
- Returns:
- called instance hash
-
getStarted
public long getStarted()- Returns:
- method start time
-
getDuration
- Returns:
- method duration
-
getRawArguments
WARNING: arguments could contain mutable objects, changed after method call (or even during the call) and so be careful when use it (e.g., for reporting) - values might not be actual.- Returns:
- arguments used for method call or null if raw objects keeping disabled
-
getArguments
String representation details: - Primitive values, number and booleans stored as is - String values could be truncated (by default 30 chars allowed) - Objects represented as ObjectType@instanceHash - null is "null".- Returns:
- string representation of method arguments
-
isVoidMethod
public boolean isVoidMethod()- Returns:
- true if method is void (no return)
-
getRawResult
WARNING: the result could be a mutable objects, changed after method call and so be careful when use it (e.g. for reporting) - value might not be exactly the same as returned value after the call.- Returns:
- result object or null if raw objects keeping disabled
-
getResult
Note that if the method is void, a string result would also be null. Also, would be null if an error happened.- Returns:
- string representation of the result
-
getThrowable
- Returns:
- error thrown by method or null
-
isSuccess
public boolean isSuccess()- Returns:
- true if no error appears, false otherwise
-
getTimer
public com.codahale.metrics.Timer getTimer()- Returns:
- timer for all executions of this method (shared instance)
-
getQuotedArguments
Almost the same asgetArguments(), but all string arguments wrapped with quotes (to see string bounds).- Returns:
- string arguments for the console report
-
getQuotedResult
Almost the same asgetResult(), but, if the result returns string, quote it to see bounds.- Returns:
- result string or null if method is void
-
toStringTrack
- Returns:
- string representation of method call (with arguments and return value)
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<MethodTrack>
-