11package com .sap .hcp .cf .logging .common ;
22
33import static com .sap .hcp .cf .logging .common .converter .CustomFieldMatchers .hasCustomField ;
4+ import static org .hamcrest .MatcherAssert .assertThat ;
45import static org .hamcrest .Matchers .contains ;
56import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
67import static org .hamcrest .Matchers .lessThanOrEqualTo ;
78import static org .hamcrest .core .Is .is ;
89import static org .hamcrest .core .IsNull .notNullValue ;
9- import static org .junit .Assert .assertThat ;
10+
11+ import java .time .Instant ;
1012
1113import org .junit .Test ;
1214import org .slf4j .Logger ;
@@ -63,9 +65,9 @@ public void testMDC() {
6365 MDC .put (SOME_KEY , SOME_VALUE );
6466 MDC .put ("testNumeric" , "200" );
6567 logMsg = "Running testMDC()" ;
66- long beforeTS = System . currentTimeMillis () * 1000000 ;
68+ long beforeTS = now () ;
6769 LOGGER .info (logMsg );
68- long afterTS = System . currentTimeMillis () * 1000000 ;
70+ long afterTS = now () ;
6971 assertThat (getMessage (), is (logMsg ));
7072 assertThat (getField (Fields .COMPONENT_ID ), is ("-" ));
7173 assertThat (getField (Fields .COMPONENT_NAME ), is ("-" ));
@@ -78,7 +80,7 @@ public void testMDC() {
7880 @ Test
7981 public void testUnregisteredCustomField () {
8082 logMsg = "Running testUnregisteredCustomField()" ;
81- long beforeTS = System . currentTimeMillis () * 1000000 ;
83+ long beforeTS = now () ;
8284 LOGGER .info (logMsg , CustomField .customField (SOME_KEY , SOME_VALUE ));
8385 assertThat (getMessage (), is (logMsg ));
8486 assertThat (getField (SOME_KEY ), is (SOME_VALUE ));
@@ -96,7 +98,7 @@ public void testCustomFieldOverwritesMdc() throws Exception {
9698 MDC .put (RETAINED_FIELD_KEY , SOME_VALUE );
9799 MDC .put (SOME_KEY , SOME_VALUE );
98100 logMsg = "Running testCustomFieldOverwritesMdc()" ;
99- long beforeTS = System . currentTimeMillis () * 1000000 ;
101+ long beforeTS = now () ;
100102 LOGGER .info (logMsg , CustomField .customField (CUSTOM_FIELD_KEY , SOME_OTHER_VALUE ),
101103 CustomField .customField (RETAINED_FIELD_KEY , SOME_OTHER_VALUE ),
102104 CustomField .customField (SOME_KEY , SOME_OTHER_VALUE ));
@@ -137,4 +139,9 @@ public void testJSONMsg() {
137139 LOGGER .info (jsonMsg );
138140 assertThat (getMessage (), is (jsonMsg ));
139141 }
142+
143+ private static long now () {
144+ Instant now = Instant .now ();
145+ return now .getEpochSecond () * 1_000_000_000L + now .getNano ();
146+ }
140147}
0 commit comments