diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/handler')
10 files changed, 133 insertions, 111 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java index 2eba4144b45..728118c38cc 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java @@ -3,13 +3,13 @@ package com.yahoo.container.handler; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.logging.CircularArrayAccessLogKeeper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.concurrent.Executor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; public class AccessLogRequestHandlerTest { @@ -20,7 +20,7 @@ public class AccessLogRequestHandlerTest { private final ByteArrayOutputStream out = new ByteArrayOutputStream(); @Test - public void testOneLogLine() throws IOException { + void testOneLogLine() throws IOException { keeper.addUri("foo"); HttpResponse response = handler.handle(null); response.render(out); @@ -28,14 +28,14 @@ public class AccessLogRequestHandlerTest { } @Test - public void testEmpty() throws IOException { + void testEmpty() throws IOException { HttpResponse response = handler.handle(null); response.render(out); assertEquals("{\"entries\":[]}", out.toString()); } @Test - public void testManyLogLines() throws IOException { + void testManyLogLines() throws IOException { keeper.addUri("foo"); keeper.addUri("foo"); HttpResponse response = handler.handle(null); diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java index 4c7cb5475dd..3d9a2360e77 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java @@ -6,7 +6,7 @@ import com.yahoo.container.jdisc.ContentChannelOutputStream; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.jdisc.handler.ReadableContentChannel; import com.yahoo.yolean.Exceptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.OutputStream; @@ -15,13 +15,13 @@ import java.util.Optional; import java.util.concurrent.Executor; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; public class LogHandlerTest { @Test - public void handleCorrectlyParsesQueryParameters() throws IOException { + void handleCorrectlyParsesQueryParameters() throws IOException { MockLogReader mockLogReader = new MockLogReader(); LogHandler logHandler = new LogHandler(mock(Executor.class), mockLogReader); diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java index e1bd0da457e..f49c127cb01 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java @@ -2,15 +2,14 @@ package com.yahoo.container.handler; import com.yahoo.compress.ZstdCompressor; -import org.junit.Before; -import org.junit.Test; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; @@ -20,12 +19,12 @@ import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class LogReaderTest { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public File folder; private Path logDirectory; private static final String logv11 = "3600.2\tnode1.com\t5480\tcontainer\tstdout\tinfo\tfourth\n"; @@ -35,9 +34,9 @@ public class LogReaderTest { private static final String log110 = "3600.1\tnode1.com\t5480\tcontainer\tstderr\twarning\tthird\n"; private static final String log200 = "86400.1\tnode2.com\t5480\tcontainer\tstderr\twarning\tjava.lang.NullPointerException\\n\\tat org.apache.felix.framework.BundleRevisionImpl.calculateContentPath(BundleRevisionImpl.java:438)\\n\\tat org.apache.felix.framework.BundleRevisionImpl.initializeContentPath(BundleRevisionImpl.java:371)\n"; - @Before + @BeforeEach public void setup() throws IOException { - logDirectory = folder.newFolder("opt/vespa/logs").toPath(); + logDirectory = newFolder(folder, "opt/vespa/logs").toPath(); // Log archive paths and file names indicate what hour they contain logs for, with the start of that hour. // Multiple entries may exist for each hour. Files.createDirectories(logDirectory.resolve("1970/01/01")); @@ -55,7 +54,7 @@ public class LogReaderTest { } @Test - public void testThatLogsOutsideRangeAreExcluded() { + void testThatLogsOutsideRangeAreExcluded() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*")); logReader.writeLogs(baos, Instant.ofEpochMilli(150), Instant.ofEpochMilli(3601050), Optional.empty()); @@ -64,7 +63,7 @@ public class LogReaderTest { } @Test - public void testThatLogsNotMatchingRegexAreExcluded() { + void testThatLogsNotMatchingRegexAreExcluded() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*-1.*")); logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), Optional.empty()); @@ -73,7 +72,7 @@ public class LogReaderTest { } @Test - public void testZippedStreaming() { + void testZippedStreaming() { ByteArrayOutputStream zippedBaos = new ByteArrayOutputStream(); LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*")); logReader.writeLogs(zippedBaos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), Optional.empty()); @@ -82,7 +81,7 @@ public class LogReaderTest { } @Test - public void logsForSingeNodeIsRetrieved() { + void logsForSingeNodeIsRetrieved() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*")); logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), Optional.of("node2.com")); @@ -103,4 +102,13 @@ public class LogReaderTest { return new ZstdCompressor().compress(data, 0, data.length); } + 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/handler/VipStatusHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java index e78810db897..18eca0bc8bd 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java @@ -15,7 +15,7 @@ import com.yahoo.jdisc.handler.ResponseHandler; import com.yahoo.jdisc.http.HttpRequest; import com.yahoo.jdisc.service.CurrentContainer; import com.yahoo.text.Utf8; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.File; @@ -27,8 +27,8 @@ import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.util.concurrent.Executors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Check semantics of VIP status handler. Do note this handler does not need to @@ -52,7 +52,7 @@ public class VipStatusHandlerTestCase { Metric metric = Mockito.mock(Metric.class); @Test - public void testHandleRequest() { + void testHandleRequest() { VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false)); VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); MockResponseHandler responseHandler = new MockResponseHandler(); @@ -78,7 +78,7 @@ public class VipStatusHandlerTestCase { } @Test - public void testFileNotFound() { + void testFileNotFound() { VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true) .statusfile("/VipStatusHandlerTestCaseFileThatReallyReallyShouldNotExist")); VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); @@ -95,7 +95,7 @@ public class VipStatusHandlerTestCase { } @Test - public void testFileFound() throws IOException { + void testFileFound() throws IOException { File statusFile = File.createTempFile("VipStatusHandlerTestCase", null); try { FileWriter writer = new FileWriter(statusFile); @@ -121,7 +121,7 @@ public class VipStatusHandlerTestCase { } @Test - public void testExplicitlyRotationControl() { + void testExplicitlyRotationControl() { VipStatus vipStatus = new VipStatus(); VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false)); VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric, vipStatus); diff --git a/container-core/src/test/java/com/yahoo/container/handler/VipStatusTestCase.java b/container-core/src/test/java/com/yahoo/container/handler/VipStatusTestCase.java index 168dd2cac7b..eed3c047b0a 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/VipStatusTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/handler/VipStatusTestCase.java @@ -5,13 +5,11 @@ import com.yahoo.container.QrSearchersConfig; import com.yahoo.container.core.VipStatusConfig; import com.yahoo.container.jdisc.state.StateMonitor; import com.yahoo.jdisc.Metric; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -19,14 +17,14 @@ import static org.junit.Assert.assertTrue; public class VipStatusTestCase { @Test - public void testInitializingOrDownRequireAllUp() { + void testInitializingOrDownRequireAllUp() { String[] clusters = {"cluster1", "cluster2", "cluster3"}; verifyStatus(clusters, StateMonitor.Status.initializing); verifyStatus(clusters, StateMonitor.Status.down); } @Test - public void testUpRequireAllDown() { + void testUpRequireAllDown() { String[] clusters = {"cluster1", "cluster2", "cluster3"}; VipStatus v = createVipStatus(clusters, StateMonitor.Status.initializing, true, new ClustersStatus(), new MetricMock()); @@ -54,21 +52,21 @@ public class VipStatusTestCase { } @Test - public void testNoClustersConfiguringInitiallyInRotationFalse() { + void testNoClustersConfiguringInitiallyInRotationFalse() { String[] clusters = {}; VipStatus v = createVipStatus(clusters, StateMonitor.Status.initializing, false, new ClustersStatus(), new MetricMock()); assertFalse(v.isInRotation()); } @Test - public void testNoClustersConfiguringInitiallyInRotationTrue() { + void testNoClustersConfiguringInitiallyInRotationTrue() { String[] clusters = {}; VipStatus v = createVipStatus(clusters, StateMonitor.Status.initializing, true, new ClustersStatus(), new MetricMock()); assertTrue(v.isInRotation()); } @Test - public void testInRotationMetricFollowsRotationState() { + void testInRotationMetricFollowsRotationState() { MetricMock metric = new MetricMock(); String[] clusters = {"cluster1", "cluster2", "cluster3"}; @@ -81,17 +79,17 @@ public class VipStatusTestCase { } @Test - public void testClusterRemovalRemovedIsDown() { + void testClusterRemovalRemovedIsDown() { assertClusterRemoval(true, false); } @Test - public void testClusterRemovalRemovedIsUp() { + void testClusterRemovalRemovedIsUp() { assertClusterRemoval(false, false); } @Test - public void testClusterRemovalAnotherIsDown() { + void testClusterRemovalAnotherIsDown() { assertClusterRemoval(false, true); } diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/ErrorResponseTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/ErrorResponseTest.java index c6e3986e870..4743075a9a6 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/metrics/ErrorResponseTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/ErrorResponseTest.java @@ -1,9 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.handler.metrics; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author gjoranv @@ -11,13 +11,13 @@ import static org.junit.Assert.assertEquals; public class ErrorResponseTest { @Test - public void error_message_is_wrapped_in_json_object() { + void error_message_is_wrapped_in_json_object() { var json = ErrorResponse.asErrorJson("bad"); assertEquals("{\"error\":\"bad\"}", json); } @Test - public void quotes_are_escaped() { + void quotes_are_escaped() { var json = ErrorResponse.asErrorJson("Message \" with \" embedded quotes."); assertEquals("{\"error\":\"Message \\\" with \\\" embedded quotes.\"}", json); } diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java index 350aad8198b..ad5b1a49670 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java @@ -4,12 +4,12 @@ package com.yahoo.container.handler.metrics; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import com.yahoo.container.jdisc.RequestHandlerTestDriver; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.io.BufferedReader; import java.io.IOException; @@ -26,9 +26,7 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options import static com.yahoo.container.handler.metrics.MetricsV2Handler.V2_PATH; import static com.yahoo.container.handler.metrics.MetricsV2Handler.VALUES_PATH; import static com.yahoo.container.handler.metrics.MetricsV2Handler.consumerQuery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author gjoranv @@ -53,15 +51,15 @@ public class MetricsV2HandlerTest { private static RequestHandlerTestDriver testDriver; - @Rule - public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); + @RegisterExtension + public WireMockExtension wireMockRule = WireMockExtension.newInstance().options(options().dynamicPort()).build(); - @Before + @BeforeEach public void setup() { setupWireMock(); var handler = new MetricsV2Handler(Executors.newSingleThreadExecutor(), new MetricsProxyApiConfig.Builder() - .metricsPort(wireMockRule.port()) + .metricsPort(wireMockRule.getPort()) .metricsApiPath(MOCK_METRICS_PATH) .prometheusApiPath("Not/In/Use") .build()); @@ -80,7 +78,7 @@ public class MetricsV2HandlerTest { } @Test - public void v2_response_contains_values_uri() throws Exception { + void v2_response_contains_values_uri() throws Exception { String response = testDriver.sendRequest(V2_URI).readAll(); JsonNode root = jsonMapper.readTree(response); assertTrue(root.has("resources")); @@ -92,29 +90,29 @@ public class MetricsV2HandlerTest { assertEquals(VALUES_URI, valuesUri.get("url").textValue()); } - @Ignore + @Disabled @Test - public void visually_inspect_values_response() { + void visually_inspect_values_response() { JsonNode responseJson = getResponseAsJson(null); System.out.println(responseJson); } @Test - public void invalid_path_yields_error_response() throws Exception { + void invalid_path_yields_error_response() throws Exception { String response = testDriver.sendRequest(V2_URI + "/invalid").readAll(); JsonNode root = jsonMapper.readTree(response); assertTrue(root.has("error")); - assertTrue(root.get("error" ).textValue().startsWith("No content")); + assertTrue(root.get("error").textValue().startsWith("No content")); } @Test - public void values_response_is_equal_to_test_file() { + void values_response_is_equal_to_test_file() { String response = testDriver.sendRequest(VALUES_URI).readAll(); assertEquals(RESPONSE, response); } @Test - public void consumer_is_propagated_to_metrics_proxy_api() { + void consumer_is_propagated_to_metrics_proxy_api() { JsonNode responseJson = getResponseAsJson(CUSTOM_CONSUMER); JsonNode firstNodeMetricsValues = diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java index 98920b895e0..5989ba4a202 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java @@ -4,12 +4,12 @@ package com.yahoo.container.handler.metrics; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import com.yahoo.container.jdisc.RequestHandlerTestDriver; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.util.concurrent.Executors; @@ -20,8 +20,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.yahoo.container.handler.metrics.MetricsV2Handler.consumerQuery; import static com.yahoo.container.handler.metrics.MetricsV2HandlerTest.getFileContents; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author gjoranv @@ -46,16 +46,16 @@ public class PrometheusV1HandlerTest { private static RequestHandlerTestDriver testDriver; - @Rule - public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); + @RegisterExtension + public WireMockExtension wireMockRule = WireMockExtension.newInstance().options(options().dynamicPort()).build(); - @Before + @BeforeEach public void setup() { setupWireMock(); var handler = new PrometheusV1Handler(Executors.newSingleThreadExecutor(), new MetricsProxyApiConfig.Builder() .prometheusApiPath(MOCK_METRICS_PATH) - .metricsPort(wireMockRule.port()) + .metricsPort(wireMockRule.getPort()) .metricsApiPath("/Not/In/Use") .build()); testDriver = new RequestHandlerTestDriver(handler); @@ -74,7 +74,7 @@ public class PrometheusV1HandlerTest { } @Test - public void v1_response_contains_values_uri() throws Exception { + void v1_response_contains_values_uri() throws Exception { String response = testDriver.sendRequest(V1_URI).readAll(); JsonNode root = jsonMapper.readTree(response); assertTrue(root.has("resources")); @@ -86,29 +86,29 @@ public class PrometheusV1HandlerTest { assertEquals(VALUES_URI, valuesUri.get("url").asText()); } - @Ignore + @Disabled @Test - public void visually_inspect_values_response() { + void visually_inspect_values_response() { String response = testDriver.sendRequest(VALUES_URI).readAll(); System.out.println(response); } @Test - public void invalid_path_yields_error_response() throws Exception { + void invalid_path_yields_error_response() throws Exception { String response = testDriver.sendRequest(V1_URI + "/invalid").readAll(); JsonNode root = jsonMapper.readTree(response); assertTrue(root.has("error")); - assertTrue(root.get("error" ).textValue().startsWith("No content")); + assertTrue(root.get("error").textValue().startsWith("No content")); } @Test - public void values_response_is_equal_to_test_file() { + void values_response_is_equal_to_test_file() { String response = testDriver.sendRequest(VALUES_URI).readAll(); assertEquals(RESPONSE, response); } @Test - public void consumer_is_propagated_to_metrics_proxy_api() { + void consumer_is_propagated_to_metrics_proxy_api() { String response = testDriver.sendRequest(VALUES_URI + consumerQuery(CUSTOM_CONSUMER)).readAll(); assertTrue(response.contains(REPLACED_CPU_METRIC)); diff --git a/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java b/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java index 2efa717800d..eefcc43fcb7 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java @@ -4,7 +4,7 @@ package com.yahoo.container.handler.test; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.filedistribution.fileacquirer.MockFileAcquirer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.File; @@ -12,7 +12,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.concurrent.Executor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Ulf Lilleengen @@ -22,7 +23,7 @@ public class MockServiceTest { private final File testFile = new File("src/test/java/com/yahoo/container/handler/test/test.txt"); @Test - public void testHandlerTextFormat() throws InterruptedException, IOException { + void testHandlerTextFormat() throws InterruptedException, IOException { HttpResponse response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.GET, "/foo/bar"); assertResponse(response, 200, "Hello\nThere!"); @@ -34,20 +35,24 @@ public class MockServiceTest { } @Test - public void testNoHandlerFound() throws InterruptedException, IOException { + void testNoHandlerFound() throws InterruptedException, IOException { HttpResponse response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.DELETE, "/foo/bar"); assertEquals(404, response.getStatus()); assertResponseContents(response, "DELETE:/foo/bar was not found"); } - @Test(expected = IllegalArgumentException.class) - public void testUnknownFileType() throws InterruptedException, IOException { - runHandlerWithFile(com.yahoo.jdisc.http.HttpRequest.Method.GET, "", new File("nonexistant")); + @Test + void testUnknownFileType() throws InterruptedException, IOException { + assertThrows(IllegalArgumentException.class, () -> { + runHandlerWithFile(com.yahoo.jdisc.http.HttpRequest.Method.GET, "", new File("nonexistant")); + }); } - @Test(expected = FileNotFoundException.class) - public void testExceptionResponse() throws InterruptedException, IOException { - runHandlerWithFile(com.yahoo.jdisc.http.HttpRequest.Method.GET, "", new File("nonexistant.txt")); + @Test + void testExceptionResponse() throws InterruptedException, IOException { + assertThrows(FileNotFoundException.class, () -> { + runHandlerWithFile(com.yahoo.jdisc.http.HttpRequest.Method.GET, "", new File("nonexistant.txt")); + }); } private void assertResponse(HttpResponse response, int expectedCode, String expectedMessage) throws IOException { diff --git a/container-core/src/test/java/com/yahoo/container/handler/threadpool/ContainerThreadPoolImplTest.java b/container-core/src/test/java/com/yahoo/container/handler/threadpool/ContainerThreadPoolImplTest.java index c3f91000296..4639022d767 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/threadpool/ContainerThreadPoolImplTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/threadpool/ContainerThreadPoolImplTest.java @@ -6,15 +6,15 @@ import com.yahoo.concurrent.Receiver; import com.yahoo.container.protect.ProcessTerminator; import com.yahoo.container.test.MetricMock; import com.yahoo.jdisc.Metric; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ThreadPoolExecutor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Steinar Knutsen @@ -25,14 +25,14 @@ public class ContainerThreadPoolImplTest { private static final int CPUS = 16; @Test - public final void testThreadPool() throws InterruptedException { + final void testThreadPool() throws InterruptedException { Metric metrics = new MetricMock(); ContainerThreadpoolConfig config = new ContainerThreadpoolConfig(new ContainerThreadpoolConfig.Builder().maxThreads(1)); ContainerThreadPool threadPool = new ContainerThreadpoolImpl(config, metrics); Executor exec = threadPool.executor(); Tuple2<Receiver.MessageState, Boolean> reply; FlipIt command = new FlipIt(); - for (boolean done = false; !done;) { + for (boolean done = false; !done; ) { try { exec.execute(command); done = true; @@ -74,7 +74,7 @@ public class ContainerThreadPoolImplTest { } @Test - public void testThatThreadPoolSizeFollowsConfig() { + void testThatThreadPoolSizeFollowsConfig() { MetricMock metrics = new MetricMock(); ThreadPoolExecutor executor = createPool(metrics, 3, 1200); assertEquals(3, executor.getMaximumPoolSize()); @@ -86,11 +86,12 @@ public class ContainerThreadPoolImplTest { assertEquals(1200L, metrics.innvocations().get("jdisc.thread_pool.work_queue.capacity").val); assertEquals(0L, metrics.innvocations().get("jdisc.thread_pool.work_queue.size").val); } + @Test - public void testThatThreadPoolSizeAutoDetected() { + void testThatThreadPoolSizeAutoDetected() { MetricMock metrics = new MetricMock(); ThreadPoolExecutor executor = createPool(metrics, 0, 0); - assertEquals(CPUS*4, executor.getMaximumPoolSize()); + assertEquals(CPUS * 4, executor.getMaximumPoolSize()); assertEquals(0, executor.getQueue().remainingCapacity()); assertEquals(7, metrics.innvocations().size()); assertEquals(64L, metrics.innvocations().get("serverThreadPoolSize").val); @@ -99,17 +100,19 @@ public class ContainerThreadPoolImplTest { assertEquals(64L, metrics.innvocations().get("jdisc.thread_pool.work_queue.capacity").val); assertEquals(0L, metrics.innvocations().get("jdisc.thread_pool.work_queue.size").val); } + @Test - public void testThatQueueSizeAutoDetected() { + void testThatQueueSizeAutoDetected() { ThreadPoolExecutor executor = createPool(24, -50); assertEquals(24, executor.getMaximumPoolSize()); - assertEquals(24*50, executor.getQueue().remainingCapacity()); + assertEquals(24 * 50, executor.getQueue().remainingCapacity()); } + @Test - public void testThatThreadPoolSizeAndQueueSizeAutoDetected() { + void testThatThreadPoolSizeAndQueueSizeAutoDetected() { ThreadPoolExecutor executor = createPool(0, -100); - assertEquals(CPUS*4, executor.getMaximumPoolSize()); - assertEquals(CPUS*4*100, executor.getQueue().remainingCapacity()); + assertEquals(CPUS * 4, executor.getMaximumPoolSize()); + assertEquals(CPUS * 4 * 100, executor.getQueue().remainingCapacity()); } private class FlipIt implements Runnable { @@ -121,9 +124,10 @@ public class ContainerThreadPoolImplTest { } } + // Ignored because it depends on the system time and so is unstable on factory @Test - @Ignore // Ignored because it depends on the system time and so is unstable on factory - public void testThreadPoolTerminationOnBreakdown() throws InterruptedException { + @Disabled + void testThreadPoolTerminationOnBreakdown() throws InterruptedException { ContainerThreadpoolConfig config = new ContainerThreadpoolConfig( new ContainerThreadpoolConfig.Builder() .maxThreads(2) @@ -138,10 +142,16 @@ public class ContainerThreadPoolImplTest { assertEquals(0, terminator.dieRequests); assertRejected(threadPool, new Hang(500)); // no more threads assertEquals(0, terminator.dieRequests); // ... but not for long enough yet - try { Thread.sleep(1500); } catch (InterruptedException e) {} + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + } threadPool.executor().execute(new Hang(1)); assertEquals(0, terminator.dieRequests); - try { Thread.sleep(50); } catch (InterruptedException e) {} // Make sure both threads are available + try { + Thread.sleep(50); + } catch (InterruptedException e) { + } // Make sure both threads are available // Dying when hanging both thread pool threads for longer than max thread execution time threadPool.executor().execute(new Hang(2000)); @@ -149,7 +159,10 @@ public class ContainerThreadPoolImplTest { assertEquals(0, terminator.dieRequests); assertRejected(threadPool, new Hang(2000)); // no more threads assertEquals(0, terminator.dieRequests); // ... but not for long enough yet - try { Thread.sleep(1500); } catch (InterruptedException e) {} + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + } assertRejected(threadPool, new Hang(2000)); // no more threads assertEquals(1, terminator.dieRequests); // ... for longer than maxThreadExecutionTime } |