diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/jdisc')
14 files changed, 196 insertions, 195 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/ExtendedResponseTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/ExtendedResponseTestCase.java index 400697af2a8..1b0521177e0 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/ExtendedResponseTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/ExtendedResponseTestCase.java @@ -1,16 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.jdisc; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.jdisc.Response; import com.yahoo.jdisc.handler.CompletionHandler; import com.yahoo.jdisc.handler.ContentChannel; @@ -48,18 +48,18 @@ public class ExtendedResponseTestCase { } - @Before + @BeforeEach public void setUp() throws Exception { r = new TestResponse(Response.Status.OK); } - @After + @AfterEach public void tearDown() throws Exception { r = null; } @Test - public final void testRenderOutputStreamContentChannelCompletionHandler() throws IOException { + final void testRenderOutputStreamContentChannelCompletionHandler() throws IOException { ByteArrayOutputStream b = new ByteArrayOutputStream(); r.render(b, null, null); assertEquals(COM_YAHOO_CONTAINER_JDISC_EXTENDED_RESPONSE_TEST_CASE, Utf8.toString(b.toByteArray())); @@ -67,22 +67,22 @@ public class ExtendedResponseTestCase { @Test - public final void testGetParsedQuery() { + final void testGetParsedQuery() { assertNull(r.getParsedQuery()); } @Test - public final void testGetTiming() { + final void testGetTiming() { assertNull(r.getTiming()); } @Test - public final void testGetCoverage() { + final void testGetCoverage() { assertNull(r.getCoverage()); } @Test - public final void testGetHitCounts() { + final void testGetHitCounts() { assertNull(r.getHitCounts()); } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java index 7fcca89b0d3..ca3c24113ff 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.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.jdisc; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -10,10 +10,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.text.Utf8; @@ -28,74 +27,74 @@ public class HttpRequestTestCase { HttpRequest r; InputStream requestData; - @Before + @BeforeEach public void setUp() throws Exception { requestData = new ByteArrayInputStream(Utf8.toBytes(X_RAY_YANKEE_ZULU)); r = HttpRequest.createTestRequest(HTTP_MAILHOST_25_ALPHA_BRAVO_CHARLIE_DELTA, Method.GET, requestData, Collections.singletonMap("foxtrot", "golf")); } - @After + @AfterEach public void tearDown() throws Exception { r = null; } @Test - public final void testGetMethod() { + final void testGetMethod() { assertSame(Method.GET, r.getMethod()); } @Test - public final void testGetUri() throws URISyntaxException { + final void testGetUri() throws URISyntaxException { assertEquals(new URI(HTTP_MAILHOST_25_ALPHA_BRAVO_CHARLIE_DELTA), r.getUri()); } @Test - public final void testGetJDiscRequest() throws URISyntaxException { + final void testGetJDiscRequest() throws URISyntaxException { assertEquals(new URI(HTTP_MAILHOST_25_ALPHA_BRAVO_CHARLIE_DELTA), r.getJDiscRequest().getUri()); } @Test - public final void testGetProperty() { + final void testGetProperty() { assertEquals("charlie", r.getProperty("bravo")); assertEquals("golf", r.getProperty("foxtrot")); assertNull(r.getProperty("zulu")); } @Test - public final void testPropertyMap() { + final void testPropertyMap() { assertEquals(4, r.propertyMap().size()); } @Test - public final void testGetBooleanProperty() { + final void testGetBooleanProperty() { assertTrue(r.getBooleanProperty("trueboolean")); assertFalse(r.getBooleanProperty("falseboolean")); assertFalse(r.getBooleanProperty("bravo")); } @Test - public final void testHasProperty() { + final void testHasProperty() { assertFalse(r.hasProperty("alpha")); assertTrue(r.hasProperty("bravo")); } @Test - public final void testGetHeader() { + final void testGetHeader() { assertNull(r.getHeader("SyntheticHeaderFor-com.yahoo.container.jdisc.HttpRequestTestCase")); } @Test - public final void testGetHost() { + final void testGetHost() { assertEquals("mailhost", r.getHost()); } @Test - public final void testGetPort() { + final void testGetPort() { assertEquals(25, r.getPort()); } @Test - public final void testGetData() throws IOException { + final void testGetData() throws IOException { byte[] b = new byte[X_RAY_YANKEE_ZULU.length()]; r.getData().read(b); assertEquals(X_RAY_YANKEE_ZULU, Utf8.toString(b)); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/HttpResponseTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/HttpResponseTestCase.java index 8dfa9a83988..963c98c2469 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/HttpResponseTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/HttpResponseTestCase.java @@ -1,16 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.jdisc; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.jdisc.Response; import com.yahoo.text.Utf8; @@ -37,45 +37,45 @@ public class HttpResponseTestCase { HttpResponse r; - @Before + @BeforeEach public void setUp() throws Exception { r = new TestResponse(Response.Status.OK); } - @After + @AfterEach public void tearDown() throws Exception { r = null; } @Test - public final void testRender() throws IOException { + final void testRender() throws IOException { ByteArrayOutputStream o = new ByteArrayOutputStream(1024); r.render(o); assertEquals(COM_YAHOO_CONTAINER_JDISC_HTTP_RESPONSE_TEST_CASE_TEST_RESPONSE, Utf8.toString(o.toByteArray())); } @Test - public final void testGetStatus() { + final void testGetStatus() { assertEquals(Response.Status.OK, r.getStatus()); } @Test - public final void testHeaders() { + final void testHeaders() { assertNotNull(r.headers()); } @Test - public final void testGetJdiscResponse() { + final void testGetJdiscResponse() { assertNotNull(r.getJdiscResponse()); } @Test - public final void testGetContentType() { + final void testGetContentType() { assertEquals(HttpResponse.DEFAULT_MIME_TYPE, r.getContentType()); } @Test - public final void testGetCharacterEncoding() { + final void testGetCharacterEncoding() { assertEquals(HttpResponse.DEFAULT_CHARACTER_ENCODING, r.getCharacterEncoding()); } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java index ae0f679771e..94158b277c4 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java @@ -13,8 +13,8 @@ import com.yahoo.jdisc.handler.ContentChannel; import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.handler.ResponseHandler; import com.yahoo.jdisc.service.CurrentContainer; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.io.IOException; import java.io.OutputStream; @@ -26,7 +26,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Test contracts in LoggingRequestHandler. @@ -110,13 +110,13 @@ public class LoggingRequestHandlerTestCase { } - @Before + @BeforeEach public void setUp() throws Exception { executor = Executors.newCachedThreadPool(); handler = new AccessLogTestHandler(executor); } - @After + @AfterEach public void tearDown() throws Exception { handler = null; executor.shutdown(); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingTestCase.java index ee76b3c5321..e423d44dfa4 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingTestCase.java @@ -3,10 +3,9 @@ package com.yahoo.container.jdisc; import com.yahoo.jdisc.handler.CompletionHandler; import com.yahoo.jdisc.handler.ContentChannel; -import java.util.logging.Level; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.ByteBuffer; @@ -17,8 +16,8 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Check error logging from ContentChannelOutputStream is sane. @@ -72,7 +71,7 @@ public class LoggingTestCase { ContentChannelOutputStream stream; - @Before + @BeforeEach public void setUp() throws Exception { stream = new ContentChannelOutputStream(new FailingContentChannel()); logger = Logger.getLogger(ContentChannelOutputStream.class.getName()); @@ -83,7 +82,7 @@ public class LoggingTestCase { logger.addHandler(logChecker); } - @After + @AfterEach public void tearDown() throws Exception { logger.removeHandler(logChecker); logger.setUseParentHandlers(initUseParentHandlers); @@ -96,7 +95,7 @@ public class LoggingTestCase { } @Test - public final void testFailed() throws IOException { + final void testFailed() throws IOException { stream.send(createData()); stream.send(createData()); stream.send(createData()); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/RequestBuilderTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/RequestBuilderTestCase.java index 9967ead052d..2a3adaff16e 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/RequestBuilderTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/RequestBuilderTestCase.java @@ -1,12 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.jdisc; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.yahoo.jdisc.http.HttpRequest.Method; /** @@ -17,26 +17,26 @@ import com.yahoo.jdisc.http.HttpRequest.Method; public class RequestBuilderTestCase { HttpRequest.Builder b; - @Before + @BeforeEach public void setUp() throws Exception { HttpRequest r = HttpRequest.createTestRequest("http://ssh:22/alpha?bravo=charlie", Method.GET); b = new HttpRequest.Builder(r); } - @After + @AfterEach public void tearDown() throws Exception { b = null; } @Test - public final void testBasic() { + final void testBasic() { HttpRequest r = b.put("delta", "echo").createDirectRequest(); assertEquals("charlie", r.getProperty("bravo")); assertEquals("echo", r.getProperty("delta")); } @Test - public void testRemove() { + void testRemove() { HttpRequest orig = b.put("delta", "echo").createDirectRequest(); HttpRequest child = new HttpRequest.Builder(orig).removeProperty("delta").createDirectRequest(); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandlerTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandlerTest.java index 2592b587539..86b7f545762 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandlerTest.java @@ -3,7 +3,7 @@ package com.yahoo.container.jdisc; import com.yahoo.container.test.MetricMock; import com.yahoo.jdisc.Metric; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.Executors; @@ -15,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ThreadedHttpRequestHandlerTest { @Test - public void unhandled_exceptions_metric_is_incremented_if_subclassed_handler_throws_exception() { + void unhandled_exceptions_metric_is_incremented_if_subclassed_handler_throws_exception() { MetricMock metricMock = new MetricMock(); ThreadedHttpRequestHandlerThrowingException handler = new ThreadedHttpRequestHandlerThrowingException(metricMock); RequestHandlerTestDriver driver = new RequestHandlerTestDriver(handler); @@ -24,7 +24,7 @@ public class ThreadedHttpRequestHandlerTest { String expectedMetricName = "jdisc.http.handler.unhandled_exceptions"; assertThat(metricMock.innvocations()) .containsKey(expectedMetricName); - assertThat(((MetricMock.SimpleMetricContext)metricMock.innvocations().get(expectedMetricName).ctx).dimensions) + assertThat(((MetricMock.SimpleMetricContext) metricMock.innvocations().get(expectedMetricName).ctx).dimensions) .containsEntry("exception", "DummyException"); } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedRequestHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedRequestHandlerTestCase.java index a9b16799aea..0fbe533fd99 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedRequestHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/ThreadedRequestHandlerTestCase.java @@ -7,7 +7,7 @@ import com.yahoo.jdisc.application.ContainerBuilder; import com.yahoo.jdisc.handler.*; import com.yahoo.jdisc.test.TestDriver; import com.yahoo.yolean.Exceptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URI; @@ -23,7 +23,7 @@ import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -31,7 +31,7 @@ import static org.junit.Assert.*; public class ThreadedRequestHandlerTestCase { @Test - public void requireThatNullExecutorThrowsException() { + void requireThatNullExecutorThrowsException() { try { new ThreadedRequestHandler(null) { @@ -47,7 +47,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void requireThatHandlerSetsRequestTimeout() throws InterruptedException { + void requireThatHandlerSetsRequestTimeout() throws InterruptedException { Executor executor = Executors.newSingleThreadExecutor(); TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(); ContainerBuilder builder = driver.newContainerBuilder(); @@ -69,7 +69,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void requireThatOverriddenRequestTimeoutIsUsed() throws InterruptedException { + void requireThatOverriddenRequestTimeoutIsUsed() throws InterruptedException { Executor executor = Executors.newSingleThreadExecutor(); TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(); ContainerBuilder builder = driver.newContainerBuilder(); @@ -82,7 +82,7 @@ public class ThreadedRequestHandlerTestCase { requestHandler.entryLatch.countDown(); assertTrue(requestHandler.exitLatch.await(60, TimeUnit.SECONDS)); - assertEquals(1, (long)requestHandler.request.getTimeout(TimeUnit.SECONDS)); + assertEquals(1, (long) requestHandler.request.getTimeout(TimeUnit.SECONDS)); assertTrue(responseHandler.latch.await(60, TimeUnit.SECONDS)); assertNull(responseHandler.content.read()); @@ -90,7 +90,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void requireThatRequestAndResponseReachHandlers() throws InterruptedException { + void requireThatRequestAndResponseReachHandlers() throws InterruptedException { Executor executor = Executors.newSingleThreadExecutor(); TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(); ContainerBuilder builder = driver.newContainerBuilder(); @@ -119,7 +119,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void requireThatRejectedExecutionIsHandledGracefully() throws Exception { + void requireThatRejectedExecutionIsHandledGracefully() throws Exception { // Instrumentation. final Executor executor = new Executor() { @Override @@ -150,14 +150,14 @@ public class ThreadedRequestHandlerTestCase { } // Verification. - assertEquals("Response handler should be invoked synchronously in this case.", 0, responseHandler.latch.getCount()); + assertEquals(0, responseHandler.latch.getCount(), "Response handler should be invoked synchronously in this case."); assertEquals(Response.Status.SERVICE_UNAVAILABLE, responseHandler.response.getStatus()); assertNull(responseHandler.content.read()); assertTrue(driver.close()); } @Test - public void requireThatRequestContentIsClosedIfHandlerIgnoresIt() throws InterruptedException { + void requireThatRequestContentIsClosedIfHandlerIgnoresIt() throws InterruptedException { Executor executor = Executors.newSingleThreadExecutor(); TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(); ContainerBuilder builder = driver.newContainerBuilder(); @@ -186,7 +186,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void requireThatResponseIsDispatchedIfHandlerIgnoresIt() throws InterruptedException { + void requireThatResponseIsDispatchedIfHandlerIgnoresIt() throws InterruptedException { Executor executor = Executors.newSingleThreadExecutor(); TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(); ContainerBuilder builder = driver.newContainerBuilder(); @@ -207,7 +207,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void requireThatRequestContentIsClosedAndResponseIsDispatchedIfHandlerIgnoresIt() + void requireThatRequestContentIsClosedAndResponseIsDispatchedIfHandlerIgnoresIt() throws InterruptedException { Executor executor = Executors.newSingleThreadExecutor(); @@ -360,7 +360,7 @@ public class ThreadedRequestHandlerTestCase { } @Test - public void testMaxPendingOutputStream() throws IOException, ExecutionException, InterruptedException { + void testMaxPendingOutputStream() throws IOException, ExecutionException, InterruptedException { ReadableContentChannel buffer = new ReadableContentChannel(); MaxPendingContentChannelOutputStream limited = new MaxPendingContentChannelOutputStream(buffer, 2); @@ -375,7 +375,8 @@ public class ThreadedRequestHandlerTestCase { future.get(100, TimeUnit.MILLISECONDS); fail("Should not be able to write now"); } - catch (TimeoutException expected) { } + catch (TimeoutException expected) { + } // Free buffer capacity, so write completes, then drain buffer. assertEquals(2, buffer.read().capacity()); @@ -390,12 +391,14 @@ public class ThreadedRequestHandlerTestCase { limited.send(ByteBuffer.allocate(3)); fail("Should throw"); } - catch (IOException expected) { } + catch (IOException expected) { + } try { limited.send(ByteBuffer.allocate(3)); fail("Should throw"); } - catch (IOException expected) { } + catch (IOException expected) { + } } } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java index 1b075ace190..5cec6c471fe 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java @@ -2,12 +2,12 @@ package com.yahoo.container.jdisc.state; import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.util.stream.Stream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -16,12 +16,12 @@ import static org.junit.Assert.assertEquals; public class CoredumpGathererTest { @Test - public void finds_one_coredump() { - JsonNode packet = CoredumpGatherer.gatherCoredumpMetrics(new MockFileWrapper()); + void finds_one_coredump() { + JsonNode packet = CoredumpGatherer.gatherCoredumpMetrics(new MockFileWrapper()); - assertEquals("system-coredumps-processing", packet.get("application").textValue()); - assertEquals(1, packet.get("status_code").intValue()); - assertEquals("Found 1 coredump(s)", packet.get("status_msg").textValue()); + assertEquals("system-coredumps-processing", packet.get("application").textValue()); + assertEquals(1, packet.get("status_code").intValue()); + assertEquals("Found 1 coredump(s)", packet.get("status_msg").textValue()); } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java index 634f5321555..c394630cb40 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java @@ -2,11 +2,11 @@ package com.yahoo.container.jdisc.state; import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.file.Path; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -15,7 +15,7 @@ import static org.junit.Assert.assertEquals; public class HostLifeGathererTest { @Test - public void host_is_alive() { + void host_is_alive() { JsonNode packet = HostLifeGatherer.getHostLifePacket(new MockFileWrapper()); JsonNode metrics = packet.get("metrics"); assertEquals("host_life", packet.get("application").textValue()); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricSnapshotTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricSnapshotTest.java index 82349dd6af9..1fd5e081fb0 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricSnapshotTest.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricSnapshotTest.java @@ -1,13 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.jdisc.state; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class MetricSnapshotTest { @@ -19,16 +19,16 @@ public class MetricSnapshotTest { * most likely be deprecated. */ @Test - public void emptyMetricSetNotAddedToClonedSnapshot() { + void emptyMetricSetNotAddedToClonedSnapshot() { StateMetricContext ctx = StateMetricContext.newInstance(null); MetricSnapshot snapshot = new MetricSnapshot(); snapshot.add(ctx, "foo", 1234); MetricSnapshot newSnapshot = snapshot.createSnapshot(); assertFalse(newSnapshot.iterator().hasNext()); } - + @Test - public void testEquality() { + void testEquality() { assertEquals(Collections.unmodifiableMap(new HashMap(0)).hashCode(), Collections.emptyMap().hashCode()); assertEquals(Collections.unmodifiableMap(new HashMap(0)), Collections.emptyMap()); } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricsPacketsHandlerTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricsPacketsHandlerTest.java index 6c05af95289..019fc1e1e78 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricsPacketsHandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/MetricsPacketsHandlerTest.java @@ -4,8 +4,8 @@ package com.yahoo.container.jdisc.state; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.container.jdisc.RequestHandlerTestDriver; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -18,8 +18,8 @@ import static com.yahoo.container.jdisc.state.MetricsPacketsHandler.PACKET_SEPAR import static com.yahoo.container.jdisc.state.MetricsPacketsHandler.STATUS_CODE_KEY; import static com.yahoo.container.jdisc.state.MetricsPacketsHandler.STATUS_MSG_KEY; import static com.yahoo.container.jdisc.state.MetricsPacketsHandler.TIMESTAMP_KEY; -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 @@ -31,7 +31,7 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { private static MetricsPacketsHandler metricsPacketsHandler; - @Before + @BeforeEach public void setupHandler() { metricsPacketsHandlerConfig = new MetricsPacketsHandlerConfig(new MetricsPacketsHandlerConfig.Builder() .application(APPLICATION_NAME).hostname(HOST_DIMENSION)); @@ -40,20 +40,20 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void status_packet_is_returned_prior_to_first_snapshot() throws Exception { + void status_packet_is_returned_prior_to_first_snapshot() throws Exception { String response = requestAsString("http://localhost/metrics-packets"); List<JsonNode> packets = toJsonPackets(response); assertEquals(1, packets.size()); JsonNode statusPacket = packets.get(0); - assertEquals(statusPacket.toString(), APPLICATION_NAME, statusPacket.get(APPLICATION_KEY).asText()); - assertEquals(statusPacket.toString(), 0, statusPacket.get(STATUS_CODE_KEY).asInt()); - assertEquals(statusPacket.toString(), "up", statusPacket.get(STATUS_MSG_KEY).asText()); + assertEquals(APPLICATION_NAME, statusPacket.get(APPLICATION_KEY).asText(), statusPacket.toString()); + assertEquals(0, statusPacket.get(STATUS_CODE_KEY).asInt(), statusPacket.toString()); + assertEquals("up", statusPacket.get(STATUS_MSG_KEY).asText(), statusPacket.toString()); } @Test - public void metrics_are_included_after_snapshot() throws Exception { + void metrics_are_included_after_snapshot() throws Exception { createSnapshotWithCountMetric("counter", 1, null); List<JsonNode> packets = incrementTimeAndGetJsonPackets(); assertEquals(2, packets.size()); @@ -63,7 +63,7 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void metadata_is_included_in_each_metrics_packet() throws Exception { + void metadata_is_included_in_each_metrics_packet() throws Exception { createSnapshotWithCountMetric("counter", 1, null); List<JsonNode> packets = incrementTimeAndGetJsonPackets(); JsonNode counterPacket = packets.get(1); @@ -74,16 +74,16 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void timestamp_resolution_is_in_seconds() throws Exception { + void timestamp_resolution_is_in_seconds() throws Exception { createSnapshotWithCountMetric("counter", 1, null); List<JsonNode> packets = incrementTimeAndGetJsonPackets(); JsonNode counterPacket = packets.get(1); - assertEquals(SNAPSHOT_INTERVAL/1000L, counterPacket.get(TIMESTAMP_KEY).asLong()); + assertEquals(SNAPSHOT_INTERVAL / 1000L, counterPacket.get(TIMESTAMP_KEY).asLong()); } @Test - public void expected_aggregators_are_output_for_gauge_metrics() throws Exception{ + void expected_aggregators_are_output_for_gauge_metrics() throws Exception { var context = StateMetricContext.newInstance(Map.of("dim1", "value1")); var snapshot = new MetricSnapshot(); snapshot.set(context, "gauge", 0.2); @@ -98,7 +98,7 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void dimensions_from_context_are_included() throws Exception { + void dimensions_from_context_are_included() throws Exception { var context = StateMetricContext.newInstance(Map.of("dim1", "value1")); createSnapshotWithCountMetric("counter", 1, context); @@ -111,7 +111,7 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void metrics_with_identical_dimensions_are_contained_in_the_same_packet() throws Exception { + void metrics_with_identical_dimensions_are_contained_in_the_same_packet() throws Exception { var context = StateMetricContext.newInstance(Map.of("dim1", "value1")); var snapshot = new MetricSnapshot(); snapshot.add(context, "counter1", 1); @@ -128,7 +128,7 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void metrics_with_different_dimensions_get_separate_packets() throws Exception { + void metrics_with_different_dimensions_get_separate_packets() throws Exception { var context1 = StateMetricContext.newInstance(Map.of("dim1", "value1")); var context2 = StateMetricContext.newInstance(Map.of("dim2", "value2")); var snapshot = new MetricSnapshot(); @@ -141,7 +141,7 @@ public class MetricsPacketsHandlerTest extends StateHandlerTestBase { } @Test - public void host_dimension_only_created_if_absent() throws Exception { + void host_dimension_only_created_if_absent() throws Exception { var context1 = StateMetricContext.newInstance(Map.of("dim1", "value1", "host", "foo.bar")); var context2 = StateMetricContext.newInstance(Map.of("dim2", "value2")); var snapshot = new MetricSnapshot(); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java index 8f800707f7a..63502a6b49f 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java @@ -5,15 +5,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.yahoo.component.Vtag; import com.yahoo.container.jdisc.RequestHandlerTestDriver; import com.yahoo.vespa.defaults.Defaults; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.concurrent.TimeUnit; -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 Simon Thoresen Hult @@ -23,47 +21,47 @@ public class StateHandlerTest extends StateHandlerTestBase { private static final String V1_URI = URI_BASE + "/state/v1/"; private static StateHandler stateHandler; - @Before + @BeforeEach public void setupHandler() { stateHandler = new StateHandler(monitor, timer, applicationMetadataConfig, snapshotProviderRegistry); testDriver = new RequestHandlerTestDriver(stateHandler); } @Test - public void testStatusReportPriorToFirstSnapshot() throws Exception { + void testStatusReportPriorToFirstSnapshot() throws Exception { JsonNode json = requestAsJson(V1_URI + "/all"); - assertEquals(json.toString(), "up", json.get("status").get("code").asText()); - assertFalse(json.toString(), json.get("metrics").has("values")); + assertEquals("up", json.get("status").get("code").asText(), json.toString()); + assertFalse(json.get("metrics").has("values"), json.toString()); } @Test - public void testReportIncludesMetricsAfterSnapshot() throws Exception { + void testReportIncludesMetricsAfterSnapshot() throws Exception { var snapshot = new MetricSnapshot(); snapshot.add(null, "foo", 1); snapshot.set(null, "bar", 4); snapshotProvider.setSnapshot(snapshot); JsonNode json1 = requestAsJson(V1_URI + "metrics"); - assertEquals(json1.toString(), "up", json1.get("status").get("code").asText()); - assertEquals(json1.toString(), 2, json1.get("metrics").get("values").size()); + assertEquals("up", json1.get("status").get("code").asText(), json1.toString()); + assertEquals(2, json1.get("metrics").get("values").size(), json1.toString()); } @Test - public void testCountMetricCount() throws Exception { + void testCountMetricCount() throws Exception { var snapshot = new MetricSnapshot(); snapshot.add(null, "foo", 4); snapshot.add(null, "foo", 2); snapshotProvider.setSnapshot(snapshot); JsonNode json = requestAsJson(V1_URI + "all"); - assertEquals(json.toString(), "up", json.get("status").get("code").asText()); - assertEquals(json.toString(), 1, json.get("metrics").get("values").size()); - assertEquals(json.toString(), 6, - json.get("metrics").get("values").get(0).get("values").get("count").asDouble(), 0.001); + assertEquals("up", json.get("status").get("code").asText(), json.toString()); + assertEquals(1, json.get("metrics").get("values").size(), json.toString()); + assertEquals(6, + json.get("metrics").get("values").get(0).get("values").get("count").asDouble(), 0.001, json.toString()); } @Test - public void gaugeSnapshotsTracksCountMinMaxAvgPerPeriod() throws Exception { + void gaugeSnapshotsTracksCountMinMaxAvgPerPeriod() throws Exception { var snapshot = new MetricSnapshot(); snapshot.set(null, "bar", 20); snapshot.set(null, "bar", 40); @@ -71,23 +69,23 @@ public class StateHandlerTest extends StateHandlerTestBase { JsonNode json = requestAsJson(V1_URI + "all"); JsonNode metricValues = getFirstMetricValueNode(json); - assertEquals(json.toString(), 40, metricValues.get("last").asDouble(), 0.001); + assertEquals(40, metricValues.get("last").asDouble(), 0.001, json.toString()); // Last snapshot had explicit values set - assertEquals(json.toString(), 30, metricValues.get("average").asDouble(), 0.001); - assertEquals(json.toString(), 20, metricValues.get("min").asDouble(), 0.001); - assertEquals(json.toString(), 40, metricValues.get("max").asDouble(), 0.001); - assertEquals(json.toString(), 2, metricValues.get("count").asInt()); + assertEquals(30, metricValues.get("average").asDouble(), 0.001, json.toString()); + assertEquals(20, metricValues.get("min").asDouble(), 0.001, json.toString()); + assertEquals(40, metricValues.get("max").asDouble(), 0.001, json.toString()); + assertEquals(2, metricValues.get("count").asInt(), json.toString()); } private JsonNode getFirstMetricValueNode(JsonNode root) { - assertEquals(root.toString(), 1, root.get("metrics").get("values").size()); + assertEquals(1, root.get("metrics").get("values").size(), root.toString()); JsonNode metricValues = root.get("metrics").get("values").get(0).get("values"); - assertTrue(root.toString(), metricValues.has("last")); + assertTrue(metricValues.has("last"), root.toString()); return metricValues; } @Test - public void testReadabilityOfJsonReport() { + void testReadabilityOfJsonReport() { var snapshot = new MetricSnapshot(0L, SNAPSHOT_INTERVAL, TimeUnit.MILLISECONDS); snapshot.add(null, "foo", 1); var ctx = StateMetricContext.newInstance(Map.of("component", "test")); @@ -98,43 +96,43 @@ public class StateHandlerTest extends StateHandlerTestBase { snapshotProvider.setSnapshot(snapshot); advanceToNextSnapshot(); assertEquals("{\n" + - " \"time\" : 300000,\n" + - " \"status\" : {\n" + - " \"code\" : \"up\"\n" + - " },\n" + - " \"metrics\" : {\n" + - " \"snapshot\" : {\n" + - " \"from\" : 0.0,\n" + - " \"to\" : 300.0\n" + - " },\n" + - " \"values\" : [ {\n" + - " \"name\" : \"foo\",\n" + - " \"values\" : {\n" + - " \"count\" : 1,\n" + - " \"rate\" : 0.0033333333333333335\n" + - " }\n" + - " }, {\n" + - " \"name\" : \"bar\",\n" + - " \"values\" : {\n" + - " \"average\" : 3.5,\n" + - " \"sum\" : 14.0,\n" + - " \"count\" : 4,\n" + - " \"last\" : 5.0,\n" + - " \"max\" : 5.0,\n" + - " \"min\" : 2.0,\n" + - " \"rate\" : 0.013333333333333334\n" + - " },\n" + - " \"dimensions\" : {\n" + - " \"component\" : \"test\"\n" + - " }\n" + - " } ]\n" + - " }\n" + - "}", - requestAsString(V1_URI + "all")); + " \"time\" : 300000,\n" + + " \"status\" : {\n" + + " \"code\" : \"up\"\n" + + " },\n" + + " \"metrics\" : {\n" + + " \"snapshot\" : {\n" + + " \"from\" : 0.0,\n" + + " \"to\" : 300.0\n" + + " },\n" + + " \"values\" : [ {\n" + + " \"name\" : \"foo\",\n" + + " \"values\" : {\n" + + " \"count\" : 1,\n" + + " \"rate\" : 0.0033333333333333335\n" + + " }\n" + + " }, {\n" + + " \"name\" : \"bar\",\n" + + " \"values\" : {\n" + + " \"average\" : 3.5,\n" + + " \"sum\" : 14.0,\n" + + " \"count\" : 4,\n" + + " \"last\" : 5.0,\n" + + " \"max\" : 5.0,\n" + + " \"min\" : 2.0,\n" + + " \"rate\" : 0.013333333333333334\n" + + " },\n" + + " \"dimensions\" : {\n" + + " \"component\" : \"test\"\n" + + " }\n" + + " } ]\n" + + " }\n" + + "}", + requestAsString(V1_URI + "all")); } @Test - public void testHealthAggregation() throws Exception { + void testHealthAggregation() throws Exception { var context1 = StateMetricContext.newInstance(Map.of("port", Defaults.getDefaults().vespaWebServicePort())); var context2 = StateMetricContext.newInstance(Map.of("port", 80)); var snapshot = new MetricSnapshot(); @@ -146,20 +144,22 @@ public class StateHandlerTest extends StateHandlerTestBase { snapshotProvider.setSnapshot(snapshot); JsonNode json = requestAsJson(V1_URI + "health"); - assertEquals(json.toString(), "up", json.get("status").get("code").asText()); - assertEquals(json.toString(), 2, json.get("metrics").get("values").size()); - assertEquals(json.toString(), "requestsPerSecond", - json.get("metrics").get("values").get(0).get("name").asText()); - assertEquals(json.toString(), 6, - json.get("metrics").get("values").get(0).get("values").get("count").asDouble(), 0.001); - assertEquals(json.toString(), "latencySeconds", - json.get("metrics").get("values").get(1).get("name").asText()); - assertEquals(json.toString(), 0.03, - json.get("metrics").get("values").get(1).get("values").get("average").asDouble(), 0.001); + assertEquals("up", json.get("status").get("code").asText(), json.toString()); + assertEquals(2, json.get("metrics").get("values").size(), json.toString()); + assertEquals("requestsPerSecond", + json.get("metrics").get("values").get(0).get("name").asText(), + json.toString()); + assertEquals(6, + json.get("metrics").get("values").get(0).get("values").get("count").asDouble(), 0.001, json.toString()); + assertEquals("latencySeconds", + json.get("metrics").get("values").get(1).get("name").asText(), + json.toString()); + assertEquals(0.03, + json.get("metrics").get("values").get(1).get("values").get("average").asDouble(), 0.001, json.toString()); } @Test - public void testStateConfig() throws Exception { + void testStateConfig() throws Exception { JsonNode root = requestAsJson(V1_URI + "config"); JsonNode config = root.get("config"); @@ -168,7 +168,7 @@ public class StateHandlerTest extends StateHandlerTestBase { } @Test - public void testStateVersion() throws Exception { + void testStateVersion() throws Exception { JsonNode root = requestAsJson(V1_URI + "version"); JsonNode version = root.get("version"); diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTestBase.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTestBase.java index b87a1179832..e3d01391a9c 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTestBase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTestBase.java @@ -9,8 +9,8 @@ import com.yahoo.container.core.ApplicationMetadataConfig; import com.yahoo.container.jdisc.RequestHandlerTestDriver; import com.yahoo.container.jdisc.config.HealthMonitorConfig; import com.yahoo.jdisc.Timer; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -38,7 +38,7 @@ public class StateHandlerTestBase { MockSnapshotProvider snapshotProvider; ComponentRegistry<SnapshotProvider> snapshotProviderRegistry; - @BeforeClass + @BeforeAll public static void setupClass() { healthMonitorConfig = new HealthMonitorConfig(new HealthMonitorConfig.Builder() .initialStatus("up")); @@ -46,7 +46,7 @@ public class StateHandlerTestBase { .generation(META_GENERATION)); } - @Before + @BeforeEach public void setupSnapshotProvider() { timer = currentTimeMillis::get; snapshotProvider = new MockSnapshotProvider(); |