Class MethodTrack

java.lang.Object
ru.vyarus.dropwizard.guice.test.track.MethodTrack
All Implemented Interfaces:
Comparable<MethodTrack>

public class MethodTrack extends Object implements 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 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 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 Details

    • getMethod

      public Method getMethod()
      Returns:
      called method
    • getService

      public Class<?> getService()
      Returns:
      type of called guice bean
    • getInstanceHash

      public String getInstanceHash()
      Returns:
      called instance hash
    • getStarted

      public long getStarted()
      Returns:
      method start time
    • getDuration

      public Duration getDuration()
      Returns:
      method duration
    • getRawArguments

      public 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 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 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 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 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 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 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 String toStringTrack()
      Returns:
      string representation of method call (with arguments and return value)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(MethodTrack o)
      Specified by:
      compareTo in interface Comparable<MethodTrack>