Class 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() 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 
      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
      int compareTo​(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.Duration getDuration()  
      java.lang.String getInstanceHash()  
      java.lang.reflect.Method getMethod()  
      java.lang.String[] getQuotedArguments()
      Almost the same as getArguments(), but all string arguments wrapped with quotes (to see string bounds).
      java.lang.String getQuotedResult()
      Almost the same as getResult(), 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.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.
      java.lang.String getResult()
      Note that if the method is void, a string result would also be null.
      java.lang.Class<?> getService()  
      long getStarted()  
      java.lang.Throwable getThrowable()  
      com.codahale.metrics.Timer getTimer()  
      boolean isSuccess()  
      boolean isVoidMethod()  
      java.lang.String toString()  
      java.lang.String toStringTrack()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 type
        method - method
        instanceHash - service instance hash
        started - start time
        duration - duration
        rawArguments - raw arguments
        arguments - string arguments
        rawResult - raw result
        result - string result
        throwable - exception
        stringMarkers - string arguments markers
        timer - 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 as getArguments(), 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 as getResult(), 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:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(MethodTrack o)
        Specified by:
        compareTo in interface java.lang.Comparable<MethodTrack>