2222import java .util .Objects ;
2323import java .util .Set ;
2424import java .util .function .Function ;
25+ import java .util .function .Supplier ;
26+
2527import org .apache .commons .lang3 .tuple .MutablePair ;
2628
2729public class EventAggregator {
@@ -30,10 +32,19 @@ public class EventAggregator {
3032 public static final java .time .Duration DEFAULT_EVENT_AGGREGATE_CACHE_EXPIRATION =
3133 java .time .Duration .ofSeconds (600 );
3234
35+ public EventAggregator (
36+ int maxLRUCacheEntries ,
37+ Function <CoreV1Event , MutablePair <String , String >> keyFunc ,
38+ Function <CoreV1Event , String > messageFunc ) {
39+ this (maxLRUCacheEntries , keyFunc , messageFunc , OffsetDateTime ::now );
40+ }
41+
3342 public EventAggregator (
3443 int maxLRUCacheEntries ,
3544 Function <CoreV1Event , MutablePair <String , String >> keyFunc ,
36- Function <CoreV1Event , String > messageFunc ) {
45+ Function <CoreV1Event , String > messageFunc ,
46+ Supplier <OffsetDateTime > now ) {
47+ this .now = now ;
3748 this .keyFunc = keyFunc ;
3849 this .messageFunc = messageFunc ;
3950 this .maxEvents = DEFAULT_MAX_EVENT_LOCAL_KEYS ;
@@ -47,11 +58,12 @@ public EventAggregator(
4758 private Cache <String , AggregatedRecord > spammingCache ;
4859 private Function <CoreV1Event , MutablePair <String , String >> keyFunc ;
4960 private Function <CoreV1Event , String > messageFunc ;
61+ private final Supplier <OffsetDateTime > now ;
5062
5163 private final int maxEvents ;
5264
5365 public synchronized MutablePair <CoreV1Event , String > aggregate (CoreV1Event event ) {
54- OffsetDateTime now = OffsetDateTime .now ();
66+ OffsetDateTime now = this .now . get ();
5567
5668 MutablePair <String , String > aggregatedKeys = keyFunc .apply (event );
5769 String aggregatedKey = aggregatedKeys .getLeft ();
0 commit comments