Class Tracker<T>
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.track.Tracker<T>
-
- Type Parameters:
T- bean type
public class Tracker<T> extends java.lang.ObjectTracker object used for bean calls registration (together withTrackBeanorTrackersHook).Use metrics timer to aggregate method calls statistics. Use
getStats()for report building.Tracked methods filtering implemented with mockito:
findTracks(java.util.function.Function).By default, recorded tracks cleared after each test.
- Since:
- 11.02.2025
-
-
Constructor Summary
Constructors Constructor Description Tracker(java.lang.Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics)Create tracker.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Cleanup recorded tracks.java.util.List<MethodTrack>findTracks(java.util.function.Function<T,org.mockito.stubbing.OngoingStubbing<?>> where)Tracked methods filtering using mockito.MethodTrackgetLastTrack()java.util.List<MethodTrack>getLastTracks(int count)Returns last (count) tracks in execution order.TrackerStatsgetStats()NOTE: This is just an example usage - you can create a stats object with filtered methods (or with methods from multiple trackers).java.util.List<MethodTrack>getTracks()Tracks sorted by start time.java.lang.Class<T>getType()booleanisEmpty()intsize()
-
-
-
Constructor Detail
-
Tracker
public Tracker(java.lang.Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics)
Create tracker.- Parameters:
type- service typeconfig- configmetrics- metrics
-
-
Method Detail
-
getType
public java.lang.Class<T> getType()
- Returns:
- type of tracked bean
-
isEmpty
public boolean isEmpty()
- Returns:
- true if no method calls registered, false otherwise
-
size
public int size()
- Returns:
- count of tracked methods
-
getTracks
public java.util.List<MethodTrack> getTracks()
Tracks sorted by start time.- Returns:
- all tracked method calls
-
getLastTrack
public MethodTrack getLastTrack()
- Returns:
- last tracked method call
- Throws:
java.lang.IllegalStateException- if no calls tracked (error thrown to simplify usage - no additional checks required in test)
-
getLastTracks
public java.util.List<MethodTrack> getLastTracks(int count)
Returns last (count) tracks in execution order.- Parameters:
count- last tracks count- Returns:
- last tracks (count)
- Throws:
java.lang.IllegalStateException- if there is not enough recorded tracks
-
getStats
public TrackerStats getStats()
NOTE: This is just an example usage - you can create a stats object with filtered methods (or with methods from multiple trackers).- Returns:
- stats for all tracked methods (for reporting)
-
findTracks
public java.util.List<MethodTrack> findTracks(java.util.function.Function<T,org.mockito.stubbing.OngoingStubbing<?>> where)
Tracked methods filtering using mockito. Useful because mockito provides type-safe syntax. For example, search by method:find(mock -> when(mock.something()). Search by method with exact argument == 1:find(mock -> when(mock.something(intThat(argument -> argument == 1))).- Parameters:
where- search condition definition- Returns:
- list of matched tracks
-
clear
public void clear()
Cleanup recorded tracks. By default, called automatically after each test method.
-
-