Class MethodTrack
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.track.MethodTrack
-
- All Implemented Interfaces:
java.lang.Comparable<MethodTrack>
public class MethodTrack extends java.lang.Object implements java.lang.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()andgetQuotedResult()for console output (astoStringTrack()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 Constructor Description MethodTrack(java.lang.Class<?> service, java.lang.reflect.Method method, java.lang.String instanceHash, long started, java.time.Duration duration, java.lang.Object[] rawArguments, java.lang.String[] arguments, java.lang.Object rawResult, java.lang.String result, java.lang.Throwable throwable, boolean[] stringMarkers, com.codahale.metrics.Timer timer)Create track.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(MethodTrack o)java.lang.String[]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".java.time.DurationgetDuration()java.lang.StringgetInstanceHash()java.lang.reflect.MethodgetMethod()java.lang.String[]getQuotedArguments()Almost the same asgetArguments(), but all string arguments wrapped with quotes (to see string bounds).java.lang.StringgetQuotedResult()Almost the same asgetResult(), but, if the result returns string, quote it to see bounds.java.lang.Object[]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.java.lang.ObjectgetRawResult()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.java.lang.StringgetResult()Note that if the method is void, a string result would also be null.java.lang.Class<?>getService()longgetStarted()java.lang.ThrowablegetThrowable()com.codahale.metrics.TimergetTimer()booleanisSuccess()booleanisVoidMethod()java.lang.StringtoString()java.lang.StringtoStringTrack()
-
-
-
Constructor Detail
-
MethodTrack
public MethodTrack(java.lang.Class<?> service, java.lang.reflect.Method method, java.lang.String instanceHash, long started, java.time.Duration duration, java.lang.Object[] rawArguments, java.lang.String[] arguments, java.lang.Object rawResult, java.lang.String result, java.lang.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 Detail
-
getMethod
public java.lang.reflect.Method getMethod()
- Returns:
- called method
-
getService
public java.lang.Class<?> getService()
- Returns:
- type of called guice bean
-
getInstanceHash
public java.lang.String getInstanceHash()
- Returns:
- called instance hash
-
getStarted
public long getStarted()
- Returns:
- method start time
-
getDuration
public java.time.Duration getDuration()
- Returns:
- method duration
-
getRawArguments
public java.lang.Object[] 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
public java.lang.String[] 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
public java.lang.Object 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
public java.lang.String 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
public java.lang.Throwable 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
public java.lang.String[] getQuotedArguments()
Almost the same asgetArguments(), but all string arguments wrapped with quotes (to see string bounds).- Returns:
- string arguments for the console report
-
getQuotedResult
public java.lang.String 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
public java.lang.String toStringTrack()
- Returns:
- string representation of method call (with arguments and return value)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(MethodTrack o)
- Specified by:
compareToin interfacejava.lang.Comparable<MethodTrack>
-
-