summaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2021-03-25 01:21:57 +0100
committerGitHub <noreply@github.com>2021-03-25 01:21:57 +0100
commitb8efc4785db0d3fef303b22e30e6f23e85ea4e51 (patch)
treec78641c028428abb907baf03fac6eb163873d38a /container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java
parent17978ed4bc296f2bd27e00b35244a6b1da66f40d (diff)
parent0176ecaec7b8beecacc0c27597b5f92d7db520f4 (diff)
Merge pull request #17140 from vespa-engine/gjoranv/merge-http-into-core_rebased
Gjoranv/merge http into core (rebased)
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java')
-rw-r--r--container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java b/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java
new file mode 100644
index 00000000000..75bc0c915d3
--- /dev/null
+++ b/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java
@@ -0,0 +1,45 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.logging;
+
+import com.yahoo.test.json.JsonTestHelper;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author bjorncs
+ */
+class JsonConnectionLogWriterTest {
+
+ @Test
+ void test_serialization() throws IOException {
+ var id = UUID.randomUUID();
+ var instant = Instant.parse("2021-01-13T12:12:12Z");
+ ConnectionLogEntry entry = ConnectionLogEntry.builder(id, instant)
+ .withPeerPort(1234)
+ .withSslHandshakeFailure(new ConnectionLogEntry.SslHandshakeFailure("UNKNOWN",
+ List.of(
+ new ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry("javax.net.ssl.SSLHandshakeException", "message"),
+ new ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry("java.io.IOException", "cause message"))))
+ .build();
+ String expectedJson = "{" +
+ "\"id\":\""+id.toString()+"\"," +
+ "\"timestamp\":\"2021-01-13T12:12:12Z\"," +
+ "\"peerPort\":1234," +
+ "\"ssl\":{\"handshake-failure\":{\"exception\":[" +
+ "{\"cause\":\"javax.net.ssl.SSLHandshakeException\",\"message\":\"message\"}," +
+ "{\"cause\":\"java.io.IOException\",\"message\":\"cause message\"}" +
+ "],\"type\":\"UNKNOWN\"}}}";
+
+ JsonConnectionLogWriter writer = new JsonConnectionLogWriter();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ writer.write(entry, out);
+ String actualJson = out.toString(StandardCharsets.UTF_8);
+ JsonTestHelper.assertJsonEquals(actualJson, expectedJson);
+ }
+} \ No newline at end of file