diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/logging')
4 files changed, 222 insertions, 198 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java b/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java index 451e6dc42bb..f942ee588be 100644 --- a/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java +++ b/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.logging; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.Matchers.contains; @@ -14,11 +14,11 @@ public class CircularArrayAccessLogKeeperTest { private CircularArrayAccessLogKeeper circularArrayAccessLogKeeper = new CircularArrayAccessLogKeeper(); @Test - public void testSizeIsCroppedCorrectly() { + void testSizeIsCroppedCorrectly() { for (int i = 0; i < CircularArrayAccessLogKeeper.SIZE - 1; i++) { circularArrayAccessLogKeeper.addUri(String.valueOf(i)); } - assertThat(circularArrayAccessLogKeeper.getUris().size(), is(CircularArrayAccessLogKeeper.SIZE -1)); + assertThat(circularArrayAccessLogKeeper.getUris().size(), is(CircularArrayAccessLogKeeper.SIZE - 1)); circularArrayAccessLogKeeper.addUri("foo"); assertThat(circularArrayAccessLogKeeper.getUris().size(), is(CircularArrayAccessLogKeeper.SIZE)); circularArrayAccessLogKeeper.addUri("bar"); @@ -28,12 +28,12 @@ public class CircularArrayAccessLogKeeperTest { } @Test - public void testEmpty() { + void testEmpty() { assertThat(circularArrayAccessLogKeeper.getUris().size(), is(0)); } @Test - public void testSomeItems() { + void testSomeItems() { circularArrayAccessLogKeeper.addUri("a"); circularArrayAccessLogKeeper.addUri("b"); circularArrayAccessLogKeeper.addUri("b"); diff --git a/container-core/src/test/java/com/yahoo/container/logging/JSONLogTestCase.java b/container-core/src/test/java/com/yahoo/container/logging/JSONLogTestCase.java index eb862d69b5b..1c66a1d805a 100644 --- a/container-core/src/test/java/com/yahoo/container/logging/JSONLogTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/logging/JSONLogTestCase.java @@ -2,7 +2,7 @@ package com.yahoo.container.logging; import com.yahoo.yolean.trace.TraceNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -41,35 +41,36 @@ public class JSONLogTestCase { } @Test - public void test_json_log_entry() { + void test_json_log_entry() { RequestLogEntry entry = newRequestLogEntry("test").build(); - String expectedOutput = - "{\"ip\":\"152.200.54.243\"," + - "\"peeraddr\":\"152.200.54.243\"," + - "\"time\":920880005.023," + - "\"duration\":0.122," + - "\"responsesize\":9875," + - "\"requestsize\":0," + - "\"code\":200," + - "\"method\":\"GET\"," + - "\"uri\":\"?query=test\"," + - "\"version\":\"HTTP/1.1\"," + - "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + - "\"host\":\"localhost\"," + - "\"scheme\":null," + - "\"localport\":0," + - "\"search\":{" + - "\"totalhits\":1234," + - "\"hits\":0," + - "\"coverage\":{\"coverage\":100,\"documents\":100}" + - "}" + - "}"; + String expectedOutput = + "{\"ip\":\"152.200.54.243\"," + + "\"peeraddr\":\"152.200.54.243\"," + + "\"time\":920880005.023," + + "\"duration\":0.122," + + "\"responsesize\":9875," + + "\"requestsize\":0," + + "\"code\":200," + + "\"method\":\"GET\"," + + "\"uri\":\"?query=test\"," + + "\"version\":\"HTTP/1.1\"," + + "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + + "\"host\":\"localhost\"," + + "\"scheme\":null," + + "\"localport\":0," + + "\"search\":{" + + "\"totalhits\":1234," + + "\"hits\":0," + + "\"coverage\":{\"coverage\":100,\"documents\":100}" + + "}" + + "}"; assertJsonEquals(formatEntry(entry), expectedOutput); } + @Test - public void test_json_of_trace() { + void test_json_of_trace() { TraceNode root = new TraceNode("root", 7); RequestLogEntry entry = newRequestLogEntry("test") .traceNode(root) @@ -77,31 +78,32 @@ public class JSONLogTestCase { String expectedOutput = "{\"ip\":\"152.200.54.243\"," + - "\"peeraddr\":\"152.200.54.243\"," + - "\"time\":920880005.023," + - "\"duration\":0.122," + - "\"responsesize\":9875," + - "\"requestsize\":0," + - "\"code\":200," + - "\"method\":\"GET\"," + - "\"uri\":\"?query=test\"," + - "\"version\":\"HTTP/1.1\"," + - "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + - "\"host\":\"localhost\"," + - "\"scheme\":null," + - "\"localport\":0," + - "\"trace\":{\"timestamp\":0,\"message\":\"root\"}," + - "\"search\":{" + - "\"totalhits\":1234," + - "\"hits\":0," + - "\"coverage\":{\"coverage\":100,\"documents\":100}" + - "}" + - "}"; + "\"peeraddr\":\"152.200.54.243\"," + + "\"time\":920880005.023," + + "\"duration\":0.122," + + "\"responsesize\":9875," + + "\"requestsize\":0," + + "\"code\":200," + + "\"method\":\"GET\"," + + "\"uri\":\"?query=test\"," + + "\"version\":\"HTTP/1.1\"," + + "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + + "\"host\":\"localhost\"," + + "\"scheme\":null," + + "\"localport\":0," + + "\"trace\":{\"timestamp\":0,\"message\":\"root\"}," + + "\"search\":{" + + "\"totalhits\":1234," + + "\"hits\":0," + + "\"coverage\":{\"coverage\":100,\"documents\":100}" + + "}" + + "}"; assertJsonEquals(formatEntry(entry), expectedOutput); } + @Test - public void test_with_keyvalues() { + void test_with_keyvalues() { RequestLogEntry entry = newRequestLogEntry("test") .addExtraAttribute("singlevalue", "value1") .addExtraAttribute("multivalue", "value2") @@ -109,62 +111,62 @@ public class JSONLogTestCase { .build(); String expectedOutput = - "{\"ip\":\"152.200.54.243\"," + - "\"peeraddr\":\"152.200.54.243\"," + - "\"time\":920880005.023," + - "\"duration\":0.122," + - "\"responsesize\":9875," + - "\"requestsize\":0," + - "\"code\":200," + - "\"method\":\"GET\"," + - "\"uri\":\"?query=test\"," + - "\"version\":\"HTTP/1.1\"," + - "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + - "\"host\":\"localhost\"," + - "\"scheme\":null," + - "\"localport\":0," + - "\"search\":{" + - "\"totalhits\":1234," + - "\"hits\":0," + - "\"coverage\":{\"coverage\":100,\"documents\":100}" + - "}," + - "\"attributes\":{" + - "\"singlevalue\":\"value1\"," + - "\"multivalue\":[\"value2\",\"value3\"]}" + - "}"; + "{\"ip\":\"152.200.54.243\"," + + "\"peeraddr\":\"152.200.54.243\"," + + "\"time\":920880005.023," + + "\"duration\":0.122," + + "\"responsesize\":9875," + + "\"requestsize\":0," + + "\"code\":200," + + "\"method\":\"GET\"," + + "\"uri\":\"?query=test\"," + + "\"version\":\"HTTP/1.1\"," + + "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + + "\"host\":\"localhost\"," + + "\"scheme\":null," + + "\"localport\":0," + + "\"search\":{" + + "\"totalhits\":1234," + + "\"hits\":0," + + "\"coverage\":{\"coverage\":100,\"documents\":100}" + + "}," + + "\"attributes\":{" + + "\"singlevalue\":\"value1\"," + + "\"multivalue\":[\"value2\",\"value3\"]}" + + "}"; assertJsonEquals(formatEntry(entry), expectedOutput); } @Test - public void test_with_remoteaddrport() throws Exception { + void test_with_remoteaddrport() throws Exception { RequestLogEntry entry = newRequestLogEntry("test") .remoteAddress("FE80:0000:0000:0000:0202:B3FF:FE1E:8329") .build(); String expectedOutput = - "{\"ip\":\"152.200.54.243\"," + - "\"peeraddr\":\"152.200.54.243\"," + - "\"time\":920880005.023," + - "\"duration\":0.122," + - "\"responsesize\":9875," + - "\"requestsize\":0," + - "\"code\":200," + - "\"method\":\"GET\"," + - "\"uri\":\"?query=test\"," + - "\"version\":\"HTTP/1.1\"," + - "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + - "\"host\":\"localhost\"," + - "\"scheme\":null," + - "\"localport\":0," + - "\"remoteaddr\":\"FE80:0000:0000:0000:0202:B3FF:FE1E:8329\"," + - "\"search\":{" + - "\"totalhits\":1234," + - "\"hits\":0," + - "\"coverage\":{\"coverage\":100,\"documents\":100}" + - "}" + - "}"; + "{\"ip\":\"152.200.54.243\"," + + "\"peeraddr\":\"152.200.54.243\"," + + "\"time\":920880005.023," + + "\"duration\":0.122," + + "\"responsesize\":9875," + + "\"requestsize\":0," + + "\"code\":200," + + "\"method\":\"GET\"," + + "\"uri\":\"?query=test\"," + + "\"version\":\"HTTP/1.1\"," + + "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + + "\"host\":\"localhost\"," + + "\"scheme\":null," + + "\"localport\":0," + + "\"remoteaddr\":\"FE80:0000:0000:0000:0202:B3FF:FE1E:8329\"," + + "\"search\":{" + + "\"totalhits\":1234," + + "\"hits\":0," + + "\"coverage\":{\"coverage\":100,\"documents\":100}" + + "}" + + "}"; assertJsonEquals(formatEntry(entry), expectedOutput); @@ -175,34 +177,34 @@ public class JSONLogTestCase { .build(); expectedOutput = - "{\"ip\":\"152.200.54.243\"," + - "\"peeraddr\":\"152.200.54.243\"," + - "\"time\":920880005.023," + - "\"duration\":0.122," + - "\"responsesize\":9875," + - "\"requestsize\":0," + - "\"code\":200," + - "\"method\":\"GET\"," + - "\"uri\":\"?query=test\"," + - "\"version\":\"HTTP/1.1\"," + - "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + - "\"host\":\"localhost\"," + - "\"scheme\":null," + - "\"localport\":0," + - "\"remoteaddr\":\"FE80:0000:0000:0000:0202:B3FF:FE1E:8329\"," + - "\"remoteport\":1234," + - "\"search\":{" + - "\"totalhits\":1234," + - "\"hits\":0," + - "\"coverage\":{\"coverage\":100,\"documents\":100}" + - "}" + - "}"; + "{\"ip\":\"152.200.54.243\"," + + "\"peeraddr\":\"152.200.54.243\"," + + "\"time\":920880005.023," + + "\"duration\":0.122," + + "\"responsesize\":9875," + + "\"requestsize\":0," + + "\"code\":200," + + "\"method\":\"GET\"," + + "\"uri\":\"?query=test\"," + + "\"version\":\"HTTP/1.1\"," + + "\"agent\":\"Mozilla/4.05 [en] (Win95; I)\"," + + "\"host\":\"localhost\"," + + "\"scheme\":null," + + "\"localport\":0," + + "\"remoteaddr\":\"FE80:0000:0000:0000:0202:B3FF:FE1E:8329\"," + + "\"remoteport\":1234," + + "\"search\":{" + + "\"totalhits\":1234," + + "\"hits\":0," + + "\"coverage\":{\"coverage\":100,\"documents\":100}" + + "}" + + "}"; assertJsonEquals(formatEntry(entry), expectedOutput); } @Test - public void test_remote_address_same_as_ip_address() throws Exception { + void test_remote_address_same_as_ip_address() throws Exception { RequestLogEntry entry = newRequestLogEntry("test").build(); RequestLogEntry entrywithremote = newRequestLogEntry("test") .remoteAddress(entry.peerAddress().get()) @@ -212,7 +214,7 @@ public class JSONLogTestCase { } @Test - public void test_useragent_with_quotes() { + void test_useragent_with_quotes() { RequestLogEntry entry = new RequestLogEntry.Builder() .rawQuery("query=test") .rawPath("") @@ -231,26 +233,26 @@ public class JSONLogTestCase { .build(); String expectedOutput = - "{\"ip\":\"152.200.54.243\"," + - "\"peeraddr\":\"152.200.54.243\"," + - "\"time\":920880005.023," + - "\"duration\":0.122," + - "\"responsesize\":9875," + - "\"requestsize\":0," + - "\"code\":200," + - "\"method\":\"GET\"," + - "\"uri\":\"?query=test\"," + - "\"version\":\"HTTP/1.1\"," + - "\"agent\":\"Mozilla/4.05 [en] (Win95; I; \\\"Best Browser Ever\\\")\"," + - "\"host\":\"localhost\"," + - "\"scheme\":null," + - "\"localport\":0," + - "\"search\":{" + - "\"totalhits\":1234," + - "\"hits\":0," + - "\"coverage\":{\"coverage\":50,\"documents\":100,\"degraded\":{\"non-ideal-state\":true}}" + - "}" + - "}"; + "{\"ip\":\"152.200.54.243\"," + + "\"peeraddr\":\"152.200.54.243\"," + + "\"time\":920880005.023," + + "\"duration\":0.122," + + "\"responsesize\":9875," + + "\"requestsize\":0," + + "\"code\":200," + + "\"method\":\"GET\"," + + "\"uri\":\"?query=test\"," + + "\"version\":\"HTTP/1.1\"," + + "\"agent\":\"Mozilla/4.05 [en] (Win95; I; \\\"Best Browser Ever\\\")\"," + + "\"host\":\"localhost\"," + + "\"scheme\":null," + + "\"localport\":0," + + "\"search\":{" + + "\"totalhits\":1234," + + "\"hits\":0," + + "\"coverage\":{\"coverage\":50,\"documents\":100,\"degraded\":{\"non-ideal-state\":true}}" + + "}" + + "}"; assertJsonEquals(formatEntry(entry), expectedOutput); } @@ -280,15 +282,15 @@ public class JSONLogTestCase { } @Test - public void test_with_coverage_degradation() { + void test_with_coverage_degradation() { verifyCoverage("\"coverage\":{\"coverage\":50,\"documents\":100,\"degraded\":{\"non-ideal-state\":true}}", - newRequestLogEntry("test", new Coverage(100,200,200,0)).build()); + newRequestLogEntry("test", new Coverage(100, 200, 200, 0)).build()); verifyCoverage("\"coverage\":{\"coverage\":50,\"documents\":100,\"degraded\":{\"match-phase\":true}}", - newRequestLogEntry("test", new Coverage(100,200,200,1)).build()); + newRequestLogEntry("test", new Coverage(100, 200, 200, 1)).build()); verifyCoverage("\"coverage\":{\"coverage\":50,\"documents\":100,\"degraded\":{\"timeout\":true}}", - newRequestLogEntry("test", new Coverage(100,200,200,2)).build()); + newRequestLogEntry("test", new Coverage(100, 200, 200, 2)).build()); verifyCoverage("\"coverage\":{\"coverage\":50,\"documents\":100,\"degraded\":{\"adaptive-timeout\":true}}", - newRequestLogEntry("test", new Coverage(100,200,200,4)).build()); + newRequestLogEntry("test", new Coverage(100, 200, 200, 4)).build()); } private String formatEntry(RequestLogEntry entry) { diff --git a/container-core/src/test/java/com/yahoo/container/logging/LogFileHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/logging/LogFileHandlerTestCase.java index 2a3877100f5..b5c65733436 100644 --- a/container-core/src/test/java/com/yahoo/container/logging/LogFileHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/logging/LogFileHandlerTestCase.java @@ -4,9 +4,9 @@ package com.yahoo.container.logging; import com.yahoo.compress.ZstdCompressor; import com.yahoo.container.logging.LogFileHandler.Compression; import com.yahoo.io.IOUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.IOException; @@ -26,7 +26,7 @@ import java.util.zip.GZIPInputStream; import static com.yahoo.yolean.Exceptions.uncheck; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * @author Bob Travis @@ -35,26 +35,26 @@ import static org.junit.Assert.assertNotEquals; public class LogFileHandlerTestCase { private static final int BUFFER_SIZE = 0x10000; - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public File temporaryFolder; @Test - public void testIt() throws IOException { - File root = temporaryFolder.newFolder("logfilehandlertest"); + void testIt() throws IOException { + File root = newFolder(temporaryFolder, "logfilehandlertest"); String pattern = root.getAbsolutePath() + "/logfilehandlertest.%Y%m%d%H%M%S"; long[] rTimes = {1000, 2000, 10000}; LogFileHandler<String> h = new LogFileHandler<>(Compression.NONE, BUFFER_SIZE, pattern, rTimes, null, 2048, "thread-name", new StringLogWriter()); long now = System.currentTimeMillis(); - long millisPerDay = 60*60*24*1000; - long tomorrowDays = (now / millisPerDay) +1; + long millisPerDay = 60 * 60 * 24 * 1000; + long tomorrowDays = (now / millisPerDay) + 1; long tomorrowMillis = tomorrowDays * millisPerDay; - assertThat(tomorrowMillis+1000).isEqualTo(h.logThread.getNextRotationTime(tomorrowMillis)); - assertThat(tomorrowMillis+10000).isEqualTo(h.logThread.getNextRotationTime(tomorrowMillis+3000)); + assertThat(tomorrowMillis + 1000).isEqualTo(h.logThread.getNextRotationTime(tomorrowMillis)); + assertThat(tomorrowMillis + 10000).isEqualTo(h.logThread.getNextRotationTime(tomorrowMillis + 3000)); String message = "test"; h.publish(message); - h.publish( "another test"); + h.publish("another test"); h.rotateNow(); h.publish(message); h.flush(); @@ -62,41 +62,42 @@ public class LogFileHandlerTestCase { } @Test - public void testSimpleLogging() throws IOException { - File logFile = temporaryFolder.newFile("testLogFileG1.txt"); + void testSimpleLogging() throws IOException { + File logFile = File.createTempFile("testLogFileG1.txt", null, temporaryFolder); - //create logfilehandler - LogFileHandler<String> h = new LogFileHandler<>(Compression.NONE, BUFFER_SIZE, logFile.getAbsolutePath(), "0 5 ...", null, 2048, "thread-name", new StringLogWriter()); + //create logfilehandler + LogFileHandler<String> h = new LogFileHandler<>(Compression.NONE, BUFFER_SIZE, logFile.getAbsolutePath(), "0 5 ...", null, 2048, "thread-name", new StringLogWriter()); - //write log - h.publish("testDeleteFileFirst1"); - h.flush(); - h.shutdown(); + //write log + h.publish("testDeleteFileFirst1"); + h.flush(); + h.shutdown(); } @Test - public void testDeleteFileDuringLogging() throws IOException { - File logFile = temporaryFolder.newFile("testLogFileG2.txt"); + void testDeleteFileDuringLogging() throws IOException { + File logFile = File.createTempFile("testLogFileG2.txt", null, temporaryFolder); - //create logfilehandler - LogFileHandler<String> h = new LogFileHandler<>(Compression.NONE, BUFFER_SIZE, logFile.getAbsolutePath(), "0 5 ...", null, 2048, "thread-name", new StringLogWriter()); + //create logfilehandler + LogFileHandler<String> h = new LogFileHandler<>(Compression.NONE, BUFFER_SIZE, logFile.getAbsolutePath(), "0 5 ...", null, 2048, "thread-name", new StringLogWriter()); - //write log - h.publish("testDeleteFileDuringLogging1"); - h.flush(); + //write log + h.publish("testDeleteFileDuringLogging1"); + h.flush(); - //delete log file + //delete log file logFile.delete(); - //write log again - h.publish("testDeleteFileDuringLogging2"); - h.flush(); - h.shutdown(); + //write log again + h.publish("testDeleteFileDuringLogging2"); + h.flush(); + h.shutdown(); } - @Test(timeout = /*5 minutes*/300_000) - public void testSymlink() throws IOException, InterruptedException { - File root = temporaryFolder.newFolder("testlogforsymlinkchecking"); + @Test + @Timeout(300_000) + void testSymlink() throws IOException, InterruptedException { + File root = newFolder(temporaryFolder, "testlogforsymlinkchecking"); Formatter formatter = new Formatter() { public String format(LogRecord r) { DateFormat df = new SimpleDateFormat("yyyy.MM.dd:HH:mm:ss.SSS"); @@ -125,9 +126,10 @@ public class LogFileHandlerTestCase { handler.shutdown(); } - @Test(timeout = /*5 minutes*/300_000) - public void compresses_previous_log_file() throws InterruptedException, IOException { - File root = temporaryFolder.newFolder("compressespreviouslogfile"); + @Test + @Timeout(300_000) + void compresses_previous_log_file() throws InterruptedException, IOException { + File root = newFolder(temporaryFolder, "compressespreviouslogfile"); LogFileHandler<String> firstHandler = new LogFileHandler<>( Compression.ZSTD, BUFFER_SIZE, root.getAbsolutePath() + "/compressespreviouslogfile.%Y%m%d%H%M%S%s", new long[]{0}, "symlink", 2048, "thread-name", new StringLogWriter()); firstHandler.publishAndWait("test"); @@ -135,7 +137,7 @@ public class LogFileHandlerTestCase { assertThat(Files.size(Paths.get(firstHandler.getFileName()))).isEqualTo(5); assertThat(root.toPath().resolve("symlink").toRealPath().toString()).isEqualTo( - Paths.get(firstHandler.getFileName()).toRealPath().toString()); + Paths.get(firstHandler.getFileName()).toRealPath().toString()); LogFileHandler<String> secondHandler = new LogFileHandler<>( Compression.ZSTD, BUFFER_SIZE, root.getAbsolutePath() + "/compressespreviouslogfile.%Y%m%d%H%M%S%s", new long[]{0}, "symlink", 2048, "thread-name", new StringLogWriter()); @@ -143,22 +145,24 @@ public class LogFileHandlerTestCase { secondHandler.rotateNow(); assertThat(root.toPath().resolve("symlink").toRealPath().toString()).isEqualTo( - Paths.get(secondHandler.getFileName()).toRealPath().toString()); + Paths.get(secondHandler.getFileName()).toRealPath().toString()); while (Files.exists(root.toPath().resolve(firstHandler.getFileName()))) Thread.sleep(1); assertThat(Files.exists(Paths.get(firstHandler.getFileName() + ".zst"))).isTrue(); secondHandler.shutdown(); } - @Test(timeout = /*5 minutes*/300_000) - public void testcompression_gzip() throws InterruptedException, IOException { + @Test + @Timeout(300_000) + void testcompression_gzip() throws InterruptedException, IOException { testcompression( Compression.GZIP, "gz", (compressedFile, __) -> uncheck(() -> new String(new GZIPInputStream(Files.newInputStream(compressedFile)).readAllBytes()))); } - @Test(timeout = /*5 minutes*/300_000) - public void testcompression_zstd() throws InterruptedException, IOException { + @Test + @Timeout(300_000) + void testcompression_zstd() throws InterruptedException, IOException { testcompression( Compression.ZSTD, "zst", (compressedFile, uncompressedSize) -> uncheck(() -> { @@ -173,7 +177,7 @@ public class LogFileHandlerTestCase { private void testcompression(Compression compression, String fileExtension, BiFunction<Path, Integer, String> decompressor) throws IOException, InterruptedException { - File root = temporaryFolder.newFolder("testcompression" + compression.name()); + File root = newFolder(temporaryFolder, "testcompression" + compression.name()); LogFileHandler<String> h = new LogFileHandler<>( compression, BUFFER_SIZE, root.getAbsolutePath() + "/logfilehandlertest.%Y%m%d%H%M%S%s", new long[]{0}, null, 2048, "thread-name", new StringLogWriter()); @@ -206,5 +210,23 @@ public class LogFileHandlerTestCase { public void write(String record, OutputStream outputStream) throws IOException { outputStream.write(record.getBytes(StandardCharsets.UTF_8)); } + + private static File newFolder(File root, String... subDirs) throws IOException { + String subFolder = String.join("/", subDirs); + File result = new File(root, subFolder); + if (!result.mkdirs()) { + throw new IOException("Couldn't create folders " + root); + } + return result; + } + } + + private static File newFolder(File root, String... subDirs) throws IOException { + String subFolder = String.join("/", subDirs); + File result = new File(root, subFolder); + if (!result.mkdirs()) { + throw new IOException("Couldn't create folders " + root); + } + return result; } } diff --git a/container-core/src/test/java/com/yahoo/container/logging/test/LogFormatterTestCase.java b/container-core/src/test/java/com/yahoo/container/logging/test/LogFormatterTestCase.java index 382f17f072f..c3526b42f55 100644 --- a/container-core/src/test/java/com/yahoo/container/logging/test/LogFormatterTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/logging/test/LogFormatterTestCase.java @@ -2,11 +2,11 @@ package com.yahoo.container.logging.test; import com.yahoo.container.logging.LogFormatter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Bob Travis @@ -14,14 +14,14 @@ import static org.junit.Assert.assertEquals; public class LogFormatterTestCase { @Test - public void testIt() { + void testIt() { java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("UTC")); @SuppressWarnings("deprecation") - long time = new Date(103,7,25,13,30,35).getTime(); - String result = LogFormatter.insertDate("test%Y%m%d%H%M%S%x",time); - assertEquals("test20030825133035Aug",result); - result = LogFormatter.insertDate("test%s%T",time); - assertEquals("test000"+time, result); + long time = new Date(103, 7, 25, 13, 30, 35).getTime(); + String result = LogFormatter.insertDate("test%Y%m%d%H%M%S%x", time); + assertEquals("test20030825133035Aug", result); + result = LogFormatter.insertDate("test%s%T", time); + assertEquals("test000" + time, result); } } |