diff options
Diffstat (limited to 'core/src/test/java')
-rw-r--r-- | core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java | 8 | ||||
-rw-r--r-- | core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java | 53 |
2 files changed, 61 insertions, 0 deletions
diff --git a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java index 1a1c17c..4900a01 100644 --- a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java +++ b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterBenchmark.java @@ -13,12 +13,14 @@ public class FormatterBenchmark { private ExtLogRecord simpleLogRecord; private ExtLogRecord structuredLogRecord; + private ExtLogRecord massivelyStructuredLogRecord; private Formatter formatter; @Setup public void setup() { simpleLogRecord = FormatterTest.makeSimpleRecord(); structuredLogRecord = FormatterTest.makeStructuredRecord(); + massivelyStructuredLogRecord = FormatterTest.makeMassivelyStructuredRecord(); formatter = new Formatter(List.of(), List.of()); } @@ -31,4 +33,10 @@ public class FormatterBenchmark { public void structuredLogRecord(Blackhole blackhole) { blackhole.consume(formatter.format(structuredLogRecord)); } + + @Benchmark + public void massivelyStructuredLogRecord(Blackhole blackhole) { + var f = formatter.format(massivelyStructuredLogRecord); + blackhole.consume(f); + } } diff --git a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java index 91cc8e4..b755230 100644 --- a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java +++ b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java @@ -93,4 +93,57 @@ class FormatterTest { }); return logRecord; } + + @Test + void massivelyStructuredRecord() { + var logRecord = makeMassivelyStructuredRecord(); + + var formatter = new Formatter(List.of(), List.of()); + var formattingResult = formatter.format(logRecord); + assertLinesMatch( + List.of( + "\\{" + + "\"message\":\"Hello, world!\"," + + "\"severity\":\"INFO\"," + + "\"timestamp\":\\{\"seconds\":\\d+,\"nanos\":\\d+\\}," + + "\"logging.googleapis.com/sourceLocation\":" + + "\\{\"file\":\"ReflectionUtils.java\"," + + "\"line\":\"\\d+\"," + + "\"function\":\"org.junit.platform.commons.util.ReflectionUtils.invokeMethod\"" + + "\\}," + + "\"int-0\":0,\"int-1\":1,\"int-2\":2,\"int-3\":3,\"int-4\":4,\"int-5\":5,\"int-6\":6,\"int-7\":7,\"int-8\":8,\"int-9\":9," + + "\"double-10\":10.0,\"double-11\":11.0,\"double-12\":12.0,\"double-13\":13.0,\"double-14\":14.0," + + "\"double-15\":15.0,\"double-16\":16.0,\"double-17\":17.0,\"double-18\":18.0,\"double-19\":19.0," + + "\"boolean-20\":true,\"boolean-21\":false,\"boolean-22\":true,\"boolean-23\":false,\"boolean-24\":true," + + "\"boolean-25\":false,\"boolean-26\":true,\"boolean-27\":false,\"boolean-28\":true,\"boolean-29\":false," + + "\"string-30\":\"30\",\"string-31\":\"31\",\"string-32\":\"32\",\"string-33\":\"33\",\"string-34\":\"34\"," + + "\"string-35\":\"35\",\"string-36\":\"36\",\"string-37\":\"37\",\"string-38\":\"38\",\"string-39\":\"39\"" + + "\\}\n"), + List.of(formattingResult)); + } + + static ExtLogRecord makeMassivelyStructuredRecord() { + var logRecord = FormatterTest.makeSimpleRecord(); + logRecord.setParameters( + new Object[] { + (StructuredParameter) + () -> { + var b = Json.createObjectBuilder(); + for (int i = 0; i < 10; i++) { + b.add("int-" + i, i); + } + for (int i = 10; i < 20; i++) { + b.add("double-" + i, (double) i); + } + for (int i = 20; i < 30; i++) { + b.add("boolean-" + i, i % 2 == 0); + } + for (int i = 30; i < 40; i++) { + b.add("string-" + i, String.valueOf(i)); + } + return b; + } + }); + return logRecord; + } } |