Skip to content

Commit 22ffccd

Browse files
committed
try to fix timestamp tests
1 parent cf4305b commit 22ffccd

File tree

1 file changed

+3
-17
lines changed
  • log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json

1 file changed

+3
-17
lines changed

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/GcpLayoutTest.java

+3-17
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
import static org.apache.logging.log4j.layout.template.json.TestHelpers.usingSerializedLogEventAccessor;
2222
import static org.assertj.core.api.Assertions.assertThat;
2323

24-
import java.time.Instant;
25-
import java.time.ZoneId;
26-
import java.time.ZonedDateTime;
27-
import java.time.format.DateTimeFormatter;
28-
import java.util.Locale;
2924
import org.apache.logging.log4j.Level;
3025
import org.apache.logging.log4j.core.LogEvent;
3126
import org.apache.logging.log4j.core.impl.ContextDataFactory;
@@ -44,9 +39,6 @@ class GcpLayoutTest {
4439

4540
private static final int LOG_EVENT_COUNT = 1_000;
4641

47-
private static final DateTimeFormatter DATE_TIME_FORMATTER =
48-
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
49-
5042
@Test
5143
void test_lite_log_events() {
5244
LogEventFixture.createLiteLogEvents(LOG_EVENT_COUNT).forEach(GcpLayoutTest::verifySerialization);
@@ -84,8 +76,9 @@ private static void verifySerialization(final LogEvent logEvent) {
8476
usingSerializedLogEventAccessor(LAYOUT, logEvent, accessor -> {
8577

8678
// Verify timestamp.
87-
final String expectedTimestamp = formatLogEventInstant(logEvent);
88-
assertThat(accessor.getString("timestamp")).isEqualTo(expectedTimestamp);
79+
final org.apache.logging.log4j.core.time.Instant instant = logEvent.getInstant();
80+
assertThat(accessor.getInteger("timestampSeconds")).isEqualTo(instant.getEpochSecond());
81+
assertThat(accessor.getInteger("timestampNanos")).isEqualTo(instant.getNanoOfSecond());
8982

9083
// Verify severity.
9184
final Level level = logEvent.getLevel();
@@ -169,11 +162,4 @@ private static void verifySerialization(final LogEvent logEvent) {
169162
assertThat(accessor.getString("logger")).isEqualTo(logEvent.getLoggerName());
170163
});
171164
}
172-
173-
private static String formatLogEventInstant(final LogEvent logEvent) {
174-
final org.apache.logging.log4j.core.time.Instant instant = logEvent.getInstant();
175-
final ZonedDateTime dateTime = Instant.ofEpochSecond(instant.getEpochSecond(), instant.getNanoOfSecond())
176-
.atZone(ZoneId.of("UTC"));
177-
return DATE_TIME_FORMATTER.format(dateTime);
178-
}
179165
}

0 commit comments

Comments
 (0)