1616 */
1717package org .graylog2 .events ;
1818
19- import com .fasterxml .jackson .databind .ObjectMapper ;
2019import com .mongodb .BasicDBObjectBuilder ;
2120import com .mongodb .DBCollection ;
2221import com .mongodb .DBObject ;
2322import org .graylog .testing .mongodb .MongoDBExtension ;
2423import org .graylog2 .database .MongoCollections ;
2524import org .graylog2 .database .MongoConnection ;
26- import org .graylog2 .shared .bindings .providers .ObjectMapperProvider ;
2725import org .joda .time .DateTime ;
2826import org .joda .time .DateTimeUtils ;
2927import org .joda .time .DateTimeZone ;
3533import org .mockito .junit .jupiter .MockitoSettings ;
3634import org .mockito .quality .Strictness ;
3735
36+ import java .time .Duration ;
3837import java .util .Collections ;
3938
4039import static org .assertj .core .api .Assertions .assertThat ;
4443@ MockitoSettings (strictness = Strictness .WARN )
4544public class ClusterEventCleanupPeriodicalTest {
4645 private static final DateTime TIME = new DateTime (2015 , 4 , 1 , 0 , 0 , DateTimeZone .UTC );
46+ private static final Duration maxEventAge = Duration .ofDays (1 );
4747
48- private final ObjectMapper objectMapper = new ObjectMapperProvider ().get ();
4948 private MongoConnection mongoConnection ;
5049 private ClusterEventCleanupPeriodical clusterEventCleanupPeriodical ;
5150
@@ -55,7 +54,7 @@ public void setUpService(MongoCollections mongoCollections) throws Exception {
5554
5655 this .mongoConnection = mongoCollections .mongoConnection ();
5756
58- this .clusterEventCleanupPeriodical = new ClusterEventCleanupPeriodical (mongoCollections );
57+ this .clusterEventCleanupPeriodical = new ClusterEventCleanupPeriodical (mongoCollections , maxEventAge );
5958 }
6059
6160 @ AfterEach
@@ -66,11 +65,12 @@ public void tearDown() {
6665
6766 @ Test
6867 public void testDoRun () throws Exception {
68+ final var maxEventAgeMillis = maxEventAge .toMillis ();
6969 final DBCollection collection = mongoConnection .getDatabase ().getCollection (ClusterEventPeriodical .COLLECTION_NAME );
7070 assertThat (insertEvent (collection , 0L )).isTrue ();
7171 assertThat (insertEvent (collection , TIME .getMillis ())).isTrue ();
72- assertThat (insertEvent (collection , TIME .minus (ClusterEventCleanupPeriodical . DEFAULT_MAX_EVENT_AGE ).getMillis ())).isTrue ();
73- assertThat (insertEvent (collection , TIME .minus (2 * ClusterEventCleanupPeriodical . DEFAULT_MAX_EVENT_AGE ).getMillis ())).isTrue ();
72+ assertThat (insertEvent (collection , TIME .minus (maxEventAgeMillis ).getMillis ())).isTrue ();
73+ assertThat (insertEvent (collection , TIME .minus (2 * maxEventAgeMillis ).getMillis ())).isTrue ();
7474 assertThat (collection .count ()).isEqualTo (4L );
7575
7676 clusterEventCleanupPeriodical .run ();
0 commit comments