1
1
package com .sap .hcp .cf .logging .common ;
2
2
3
3
import static com .sap .hcp .cf .logging .common .converter .CustomFieldMatchers .hasCustomField ;
4
+ import static org .hamcrest .MatcherAssert .assertThat ;
4
5
import static org .hamcrest .Matchers .contains ;
5
6
import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
6
7
import static org .hamcrest .Matchers .lessThanOrEqualTo ;
7
8
import static org .hamcrest .core .Is .is ;
8
9
import static org .hamcrest .core .IsNull .notNullValue ;
9
- import static org .junit .Assert .assertThat ;
10
+
11
+ import java .time .Instant ;
10
12
11
13
import org .junit .Test ;
12
14
import org .slf4j .Logger ;
@@ -63,9 +65,9 @@ public void testMDC() {
63
65
MDC .put (SOME_KEY , SOME_VALUE );
64
66
MDC .put ("testNumeric" , "200" );
65
67
logMsg = "Running testMDC()" ;
66
- long beforeTS = System . currentTimeMillis () * 1000000 ;
68
+ long beforeTS = now () ;
67
69
LOGGER .info (logMsg );
68
- long afterTS = System . currentTimeMillis () * 1000000 ;
70
+ long afterTS = now () ;
69
71
assertThat (getMessage (), is (logMsg ));
70
72
assertThat (getField (Fields .COMPONENT_ID ), is ("-" ));
71
73
assertThat (getField (Fields .COMPONENT_NAME ), is ("-" ));
@@ -78,7 +80,7 @@ public void testMDC() {
78
80
@ Test
79
81
public void testUnregisteredCustomField () {
80
82
logMsg = "Running testUnregisteredCustomField()" ;
81
- long beforeTS = System . currentTimeMillis () * 1000000 ;
83
+ long beforeTS = now () ;
82
84
LOGGER .info (logMsg , CustomField .customField (SOME_KEY , SOME_VALUE ));
83
85
assertThat (getMessage (), is (logMsg ));
84
86
assertThat (getField (SOME_KEY ), is (SOME_VALUE ));
@@ -96,7 +98,7 @@ public void testCustomFieldOverwritesMdc() throws Exception {
96
98
MDC .put (RETAINED_FIELD_KEY , SOME_VALUE );
97
99
MDC .put (SOME_KEY , SOME_VALUE );
98
100
logMsg = "Running testCustomFieldOverwritesMdc()" ;
99
- long beforeTS = System . currentTimeMillis () * 1000000 ;
101
+ long beforeTS = now () ;
100
102
LOGGER .info (logMsg , CustomField .customField (CUSTOM_FIELD_KEY , SOME_OTHER_VALUE ),
101
103
CustomField .customField (RETAINED_FIELD_KEY , SOME_OTHER_VALUE ),
102
104
CustomField .customField (SOME_KEY , SOME_OTHER_VALUE ));
@@ -137,4 +139,9 @@ public void testJSONMsg() {
137
139
LOGGER .info (jsonMsg );
138
140
assertThat (getMessage (), is (jsonMsg ));
139
141
}
142
+
143
+ private static long now () {
144
+ Instant now = Instant .now ();
145
+ return now .getEpochSecond () * 1_000_000_000L + now .getNano ();
146
+ }
140
147
}
0 commit comments