|
37 | 37 | import static java.util.Objects.requireNonNull;
|
38 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
39 | 39 | import static org.assertj.core.api.Assertions.entry;
|
| 40 | +import static org.awaitility.Awaitility.await; |
40 | 41 | import static org.mockito.Mockito.mock;
|
41 | 42 | import static org.mockito.Mockito.when;
|
42 | 43 |
|
@@ -149,10 +150,10 @@ public void testLogJsonToConsole() throws Exception {
|
149 | 150 | defaultLoggingFactory.configure(new MetricRegistry(), "json-log-test");
|
150 | 151 | Marker marker = MarkerFactory.getMarker("marker");
|
151 | 152 | LoggerFactory.getLogger("com.example.app").info(marker, "Application log");
|
152 |
| - Thread.sleep(100); // Need to wait, because the logger is async |
| 153 | + // Need to wait, because the logger is async |
| 154 | + await().atMost(1, TimeUnit.SECONDS).until(() -> !redirectedStream.toString().isEmpty()); |
153 | 155 |
|
154 | 156 | JsonNode jsonNode = objectMapper.readTree(redirectedStream.toString());
|
155 |
| - assertThat(jsonNode).isNotNull(); |
156 | 157 | assertThat(jsonNode.get("timestamp").isTextual()).isTrue();
|
157 | 158 | assertThat(jsonNode.get("level").asText()).isEqualTo("INFO");
|
158 | 159 | assertThat(jsonNode.get("logger").asText()).isEqualTo("com.example.app");
|
@@ -204,10 +205,10 @@ public void testLogAccessJsonToConsole() throws Exception {
|
204 | 205 | when(response.getHeader("Server")).thenReturn("Apache/2.4.12");
|
205 | 206 |
|
206 | 207 | requestLog.log(request, response);
|
207 |
| - Thread.sleep(100); // Need to wait, because the logger is async |
| 208 | + // Need to wait, because the logger is async |
| 209 | + await().atMost(1, TimeUnit.SECONDS).until(() -> !redirectedStream.toString().isEmpty()); |
208 | 210 |
|
209 | 211 | JsonNode jsonNode = objectMapper.readTree(redirectedStream.toString());
|
210 |
| - assertThat(jsonNode).isNotNull(); |
211 | 212 | assertThat(jsonNode.get("timestamp").isNumber()).isTrue();
|
212 | 213 | assertThat(jsonNode.get("requestTime").isNumber()).isTrue();
|
213 | 214 | assertThat(jsonNode.get("remoteAddress").asText()).isEqualTo("10.0.0.1");
|
|
0 commit comments