diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-01-22 18:33:09 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-01-25 19:01:57 +0100 |
commit | b24a4cecfc9418d0613fa3fb90309bfdae723f18 (patch) | |
tree | 8c89efe4e6679478e12eb7d496e330e6a90ae447 /jdisc_http_service/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java | |
parent | 80a329ba15c6b1cde5d12239b5b7c568156bdb65 (diff) |
Write connection log entry directly to output stream
Diffstat (limited to 'jdisc_http_service/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java')
-rw-r--r-- | jdisc_http_service/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java b/jdisc_http_service/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java new file mode 100644 index 00000000000..b8978fe489c --- /dev/null +++ b/jdisc_http_service/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java @@ -0,0 +1,36 @@ +package com.yahoo.container.logging;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +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.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) + .build(); + String expectedJson = "{" + + "\"id\":\""+id.toString()+"\"," + + "\"timestamp\":\"2021-01-13T12:12:12Z\"," + + "\"peerPort\":1234" + + "}"; + + 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 |