summaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container
diff options
context:
space:
mode:
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container')
-rw-r--r--container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java18
-rw-r--r--container-core/src/test/java/com/yahoo/container/core/config/PlatformBundleLoaderTest.java16
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java33
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/ContainerTest.java38
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java17
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java20
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java130
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java17
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java46
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java16
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java14
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java10
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java6
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java36
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java14
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/VipStatusTestCase.java22
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/metrics/ErrorResponseTest.java8
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java36
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java36
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java25
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/threadpool/ContainerThreadPoolImplTest.java51
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/ExtendedResponseTestCase.java24
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java35
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/HttpResponseTestCase.java26
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java10
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/LoggingTestCase.java17
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/RequestBuilderTestCase.java18
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandlerTest.java6
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/ThreadedRequestHandlerTestCase.java35
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java14
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java6
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/MetricSnapshotTest.java12
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/MetricsPacketsHandlerTest.java36
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTest.java144
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/StateHandlerTestBase.java8
-rw-r--r--container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java10
-rw-r--r--container-core/src/test/java/com/yahoo/container/logging/JSONLogTestCase.java280
-rw-r--r--container-core/src/test/java/com/yahoo/container/logging/LogFileHandlerTestCase.java114
-rw-r--r--container-core/src/test/java/com/yahoo/container/logging/test/LogFormatterTestCase.java16
39 files changed, 729 insertions, 691 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java
index 4f6fea76828..cf8cc6053cd 100644
--- a/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java
+++ b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java
@@ -5,16 +5,16 @@ import com.yahoo.config.FileReference;
import com.yahoo.filedistribution.fileacquirer.FileAcquirer;
import com.yahoo.filedistribution.fileacquirer.MockFileAcquirer;
import com.yahoo.osgi.Osgi;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.osgi.framework.Bundle;
import java.util.List;
import java.util.Map;
import java.util.Set;
-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
@@ -29,7 +29,7 @@ public class ApplicationBundleLoaderTest {
private ApplicationBundleLoader bundleLoader;
private TestOsgi osgi;
- @Before
+ @BeforeEach
public void setup() {
osgi = new TestOsgi(testBundles());
var bundleInstaller = new TestBundleInstaller(MockFileAcquirer.returnFile(null));
@@ -38,12 +38,12 @@ public class ApplicationBundleLoaderTest {
}
@Test
- public void bundles_are_installed_and_started() {
+ void bundles_are_installed_and_started() {
bundleLoader.useBundles(List.of(BUNDLE_1_REF));
assertEquals(1, osgi.getInstalledBundles().size());
// The bundle is installed and started
- TestBundle installedBundle = (TestBundle)osgi.getInstalledBundles().get(0);
+ TestBundle installedBundle = (TestBundle) osgi.getInstalledBundles().get(0);
assertEquals(BUNDLE_1.getSymbolicName(), installedBundle.getSymbolicName());
assertTrue(installedBundle.started);
@@ -53,7 +53,7 @@ public class ApplicationBundleLoaderTest {
}
@Test
- public void new_bundle_can_be_installed_in_reconfig() {
+ void new_bundle_can_be_installed_in_reconfig() {
bundleLoader.useBundles(List.of(BUNDLE_1_REF));
Set<Bundle> obsoleteBundles = bundleLoader.useBundles(List.of(BUNDLE_1_REF, BUNDLE_2_REF));
@@ -78,7 +78,7 @@ public class ApplicationBundleLoaderTest {
}
@Test
- public void unused_bundle_is_marked_obsolete_after_reconfig() {
+ void unused_bundle_is_marked_obsolete_after_reconfig() {
bundleLoader.useBundles(List.of(BUNDLE_1_REF));
Set<Bundle> obsoleteBundles = bundleLoader.useBundles(List.of(BUNDLE_2_REF));
diff --git a/container-core/src/test/java/com/yahoo/container/core/config/PlatformBundleLoaderTest.java b/container-core/src/test/java/com/yahoo/container/core/config/PlatformBundleLoaderTest.java
index 3cd9779f878..21d99915c5c 100644
--- a/container-core/src/test/java/com/yahoo/container/core/config/PlatformBundleLoaderTest.java
+++ b/container-core/src/test/java/com/yahoo/container/core/config/PlatformBundleLoaderTest.java
@@ -2,15 +2,15 @@
package com.yahoo.container.core.config;
import com.yahoo.osgi.Osgi;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.osgi.framework.Bundle;
import java.util.List;
import java.util.Map;
-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
@@ -25,25 +25,25 @@ public class PlatformBundleLoaderTest {
private PlatformBundleLoader bundleLoader;
private TestOsgi osgi;
- @Before
+ @BeforeEach
public void setup() {
osgi = new TestOsgi(testBundles());
bundleLoader = new PlatformBundleLoader(osgi, new TestBundleInstaller());
}
@Test
- public void bundles_are_installed_and_started() {
+ void bundles_are_installed_and_started() {
bundleLoader.useBundles(List.of(BUNDLE_1_REF));
assertEquals(1, osgi.getInstalledBundles().size());
// The bundle is installed and started
- TestBundle installedBundle = (TestBundle)osgi.getInstalledBundles().get(0);
+ TestBundle installedBundle = (TestBundle) osgi.getInstalledBundles().get(0);
assertEquals(BUNDLE_1.getSymbolicName(), installedBundle.getSymbolicName());
assertTrue(installedBundle.started);
}
@Test
- public void bundles_cannot_be_added_by_later_calls() {
+ void bundles_cannot_be_added_by_later_calls() {
bundleLoader.useBundles(List.of(BUNDLE_1_REF));
bundleLoader.useBundles(List.of(BUNDLE_2_REF)); // Should be a NOP
diff --git a/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java b/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java
index 695efbf7c17..942555e391d 100644
--- a/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java
@@ -9,18 +9,20 @@ import com.yahoo.container.di.ConfigRetriever.BootstrapConfigs;
import com.yahoo.container.di.ConfigRetriever.ComponentsConfigs;
import com.yahoo.container.di.ConfigRetriever.ConfigSnapshot;
import com.yahoo.vespa.config.ConfigKey;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
*
@@ -32,18 +34,21 @@ public class ConfigRetrieverTest {
private DirConfigSource dirConfigSource = null;
- @Before
+ @TempDir
+ File tmpDir;
+
+ @BeforeEach
public void setup() {
- dirConfigSource = new DirConfigSource("ConfigRetrieverTest-");
+ dirConfigSource = new DirConfigSource(tmpDir, "ConfigRetrieverTest-");
}
- @After
+ @AfterEach
public void cleanup() {
dirConfigSource.cleanup();
}
@Test
- public void require_that_bootstrap_configs_come_first() {
+ void require_that_bootstrap_configs_come_first() {
writeConfigs();
ConfigRetriever retriever = createConfigRetriever();
ConfigSnapshot bootstrapConfigs = retriever.getConfigs(Collections.emptySet(), 0, true);
@@ -53,7 +58,7 @@ public class ConfigRetrieverTest {
@Test
@SuppressWarnings("unused")
- public void require_that_components_comes_after_bootstrap() {
+ void require_that_components_comes_after_bootstrap() {
writeConfigs();
ConfigRetriever retriever = createConfigRetriever();
ConfigSnapshot bootstrapConfigs = retriever.getConfigs(Collections.emptySet(), 0, true);
@@ -68,7 +73,7 @@ public class ConfigRetrieverTest {
}
}
- @Ignore
+ @Disabled
@SuppressWarnings("unused")
public void require_exception_upon_modified_components_keys_without_bootstrap() {
@@ -89,7 +94,7 @@ public class ConfigRetrieverTest {
}
@Test
- public void require_that_empty_components_keys_after_bootstrap_returns_components_configs() {
+ void require_that_empty_components_keys_after_bootstrap_returns_components_configs() {
writeConfigs();
ConfigRetriever retriever = createConfigRetriever();
assertTrue(retriever.getConfigs(Collections.emptySet(), 0, true) instanceof BootstrapConfigs);
diff --git a/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java b/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java
index 30dc4f313e4..04091c25ad6 100644
--- a/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java
@@ -9,8 +9,8 @@ import com.yahoo.container.di.componentgraph.Provider;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
import com.yahoo.container.di.componentgraph.core.ComponentGraphTest.SimpleComponent;
import com.yahoo.container.di.componentgraph.core.ComponentNode.ComponentConstructorException;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.osgi.framework.Bundle;
import java.util.Collection;
@@ -20,13 +20,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Tony Vaagenes
@@ -36,7 +30,7 @@ import static org.junit.Assert.fail;
public class ContainerTest extends ContainerTestBase {
@Test
- public void components_can_be_created_from_config() {
+ void components_can_be_created_from_config() {
writeBootstrapConfigs();
dirConfigSource.writeConfig("test", "stringVal \"myString\"");
@@ -49,7 +43,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void components_are_reconfigured_after_config_update_without_bootstrap_configs() {
+ void components_are_reconfigured_after_config_update_without_bootstrap_configs() {
writeBootstrapConfigs();
dirConfigSource.writeConfig("test", "stringVal \"original\"");
@@ -71,7 +65,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void graph_is_updated_after_bootstrap_update() {
+ void graph_is_updated_after_bootstrap_update() {
dirConfigSource.writeConfig("test", "stringVal \"original\"");
writeBootstrapConfigs("id1");
@@ -99,7 +93,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void component_is_deconstructed_when_not_reused() {
+ void component_is_deconstructed_when_not_reused() {
writeBootstrapConfigs("id1", DestructableComponent.class);
Container container = newContainer(dirConfigSource);
@@ -113,9 +107,9 @@ public class ContainerTest extends ContainerTestBase {
assertTrue(componentToDestruct.deconstructed);
}
- @Ignore // because logAndDie is impossible(?) to verify programmatically
+ @Disabled // because logAndDie is impossible(?) to verify programmatically
@Test
- public void manually_verify_what_happens_when_first_graph_contains_component_that_throws_exception_in_ctor() {
+ void manually_verify_what_happens_when_first_graph_contains_component_that_throws_exception_in_ctor() {
writeBootstrapConfigs("thrower", ComponentThrowingExceptionInConstructor.class);
Container container = newContainer(dirConfigSource);
try {
@@ -127,7 +121,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void previous_graph_is_retained_when_new_graph_contains_component_that_throws_exception_in_ctor() {
+ void previous_graph_is_retained_when_new_graph_contains_component_that_throws_exception_in_ctor() {
ComponentEntry simpleComponentEntry = new ComponentEntry("simpleComponent", SimpleComponent.class);
writeBootstrapConfigs(simpleComponentEntry);
@@ -161,7 +155,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void previous_graph_is_retained_when_new_graph_throws_exception_for_missing_config() {
+ void previous_graph_is_retained_when_new_graph_throws_exception_for_missing_config() {
ComponentEntry simpleComponentEntry = new ComponentEntry("simpleComponent", SimpleComponent.class);
writeBootstrapConfigs(simpleComponentEntry);
@@ -185,7 +179,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void getNewComponentGraph_hangs_waiting_for_valid_config_after_invalid_config() throws Exception {
+ void getNewComponentGraph_hangs_waiting_for_valid_config_after_invalid_config() throws Exception {
dirConfigSource.writeConfig("test", "stringVal \"original\"");
writeBootstrapConfigs("myId", ComponentTakingConfig.class);
@@ -196,7 +190,7 @@ public class ContainerTest extends ContainerTestBase {
container.reloadConfig(2);
assertThrows(IllegalArgumentException.class,
- () -> getNewComponentGraph(container, currentGraph));
+ () -> getNewComponentGraph(container, currentGraph));
ExecutorService exec = Executors.newFixedThreadPool(1);
Future<ComponentGraph> newGraph = exec.submit(() -> getNewComponentGraph(container, currentGraph));
@@ -215,7 +209,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void providers_are_destructed() {
+ void providers_are_destructed() {
writeBootstrapConfigs("id1", DestructableProvider.class);
ComponentDeconstructor deconstructor = (generation, components, bundles) -> {
@@ -226,7 +220,7 @@ public class ContainerTest extends ContainerTestBase {
((Provider<?>) component).deconstruct();
}
});
- if (! bundles.isEmpty()) throw new IllegalArgumentException("This test should not use bundles");
+ if (!bundles.isEmpty()) throw new IllegalArgumentException("This test should not use bundles");
};
Container container = newContainer(dirConfigSource, deconstructor);
@@ -242,7 +236,7 @@ public class ContainerTest extends ContainerTestBase {
}
@Test
- public void providers_are_invoked_only_when_needed() {
+ void providers_are_invoked_only_when_needed() {
writeBootstrapConfigs("id1", FailOnGetProvider.class);
Container container = newContainer(dirConfigSource);
diff --git a/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java b/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
index e7f12d3f228..4383bd08f71 100644
--- a/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
+++ b/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
@@ -7,10 +7,12 @@ import com.yahoo.config.FileReference;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.di.ContainerTest.ComponentTakingConfig;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.io.TempDir;
import org.osgi.framework.Bundle;
+import java.io.File;
import java.util.Collection;
import java.util.Set;
@@ -26,17 +28,20 @@ public class ContainerTestBase {
private ComponentGraph componentGraph;
protected DirConfigSource dirConfigSource = null;
- @Before
+ @TempDir
+ File tmpDir;
+
+ @BeforeEach
public void setup() {
- dirConfigSource = new DirConfigSource("ContainerTest-");
+ dirConfigSource = new DirConfigSource(tmpDir, "ContainerTest-");
}
- @After
+ @AfterEach
public void cleanup() {
dirConfigSource.cleanup();
}
- @Before
+ @BeforeEach
public void createGraph() {
componentGraph = new ComponentGraph(0);
}
diff --git a/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java b/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java
index 43b2c8ad8e6..db7e93f7c6e 100644
--- a/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java
+++ b/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java
@@ -3,7 +3,6 @@ package com.yahoo.container.di;
import com.yahoo.config.subscription.ConfigSource;
import com.yahoo.config.subscription.ConfigSourceSet;
-import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.FileOutputStream;
@@ -18,15 +17,16 @@ import java.util.Random;
*/
public class DirConfigSource {
- private final TemporaryFolder tempFolder = createTemporaryFolder();
+ private final File tempFolder;
public final ConfigSource configSource;
- public DirConfigSource(String testSourcePrefix) {
+ public DirConfigSource(File tmpDir, String testSourcePrefix) {
+ this.tempFolder = tmpDir;
this.configSource = new ConfigSourceSet(testSourcePrefix + new Random().nextLong());
}
public void writeConfig(String name, String contents) {
- File file = new File(tempFolder.getRoot(), name + ".cfg");
+ File file = new File(tempFolder, name + ".cfg");
if (!file.exists()) {
try {
file.createNewFile();
@@ -39,7 +39,7 @@ public class DirConfigSource {
}
public String configId() {
- return "dir:" + tempFolder.getRoot().getPath();
+ return "dir:" + tempFolder.getPath();
}
public ConfigSource configSource() {
@@ -58,14 +58,4 @@ public class DirConfigSource {
}
}
- private static TemporaryFolder createTemporaryFolder() {
- TemporaryFolder folder = new TemporaryFolder();
- try {
- folder.create();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return folder;
- }
-
}
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
index 5abb96527bd..c21c1b35782 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
@@ -18,7 +18,7 @@ import com.yahoo.config.test.Test2Config;
import com.yahoo.config.test.TestConfig;
import com.yahoo.container.di.componentgraph.Provider;
import com.yahoo.vespa.config.ConfigKey;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.lang.annotation.Annotation;
import java.util.Collections;
@@ -30,13 +30,7 @@ import java.util.concurrent.Executors;
import java.util.function.Supplier;
import static com.yahoo.container.di.componentgraph.core.ComponentGraph.isBindingAnnotation;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author gjoranv
@@ -65,7 +59,7 @@ public class ComponentGraphTest {
}
@Test
- public void component_taking_config_can_be_instantiated() {
+ void component_taking_config_can_be_instantiated() {
ComponentGraph componentGraph = new ComponentGraph();
String configId = "raw:stringVal \"test-value\"";
Node componentNode = mockComponentNode(ComponentTakingConfig.class, configId);
@@ -80,7 +74,7 @@ public class ComponentGraphTest {
}
@Test
- public void all_created_components_are_returned_in_reverse_topological_order() {
+ void all_created_components_are_returned_in_reverse_topological_order() {
for (int i = 0; i < 10; i++) {
Node innerComponent = mockComponentNode(SimpleComponent.class);
Node middleComponent = mockComponentNode(ComponentTakingComponent.class);
@@ -97,12 +91,12 @@ public class ComponentGraphTest {
outerComponent.constructInstance();
assertEquals(List.of(outerComponent.constructedInstance().get(), middleComponent.constructedInstance().get(), innerComponent.constructedInstance().get()),
- componentGraph.allConstructedComponentsAndProviders());
+ componentGraph.allConstructedComponentsAndProviders());
}
}
@Test
- public void component_can_be_explicitly_injected_into_another_component() {
+ void component_can_be_explicitly_injected_into_another_component() {
Node injectedComponent = mockComponentNode(SimpleComponent.class);
Node targetComponent = mockComponentNode(ComponentTakingComponent.class);
targetComponent.inject(injectedComponent);
@@ -121,7 +115,7 @@ public class ComponentGraphTest {
}
@Test
- public void explicitly_injected_components_may_be_unused() {
+ void explicitly_injected_components_may_be_unused() {
Node notUsingInjected = mockComponentNode(SimpleComponent.class);
Node injectedComponent = mockComponentNode(SimpleComponent2.class);
notUsingInjected.inject(injectedComponent);
@@ -136,7 +130,7 @@ public class ComponentGraphTest {
}
@Test
- public void interface_implementation_can_be_injected() {
+ void interface_implementation_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(ComponentImpl.class));
componentGraph.add(mockComponentNode(ComponentTakingInterface.class));
@@ -147,7 +141,7 @@ public class ComponentGraphTest {
}
@Test
- public void private_class_with_public_ctor_can_be_instantiated() {
+ void private_class_with_public_ctor_can_be_instantiated() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(PrivateClassComponent.class));
componentGraph.complete();
@@ -157,7 +151,7 @@ public class ComponentGraphTest {
}
@Test
- public void all_components_of_a_type_can_be_injected() {
+ void all_components_of_a_type_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(SimpleComponent.class));
componentGraph.add(mockComponentNode(SimpleComponent.class));
@@ -170,7 +164,7 @@ public class ComponentGraphTest {
}
@Test
- public void empty_component_registry_can_be_injected() {
+ void empty_component_registry_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(ComponentTakingAllSimpleComponents.class));
componentGraph.complete();
@@ -180,7 +174,7 @@ public class ComponentGraphTest {
}
@Test
- public void component_registry_with_wildcard_upper_bound_can_be_injected() {
+ void component_registry_with_wildcard_upper_bound_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(SimpleComponent.class));
componentGraph.add(mockComponentNode(SimpleDerivedComponent.class));
@@ -192,22 +186,24 @@ public class ComponentGraphTest {
assertEquals(2, instance.simpleComponents.allComponents().size());
}
- @Test(expected = RuntimeException.class)
- public void require_exception_when_injecting_registry_with_unknown_type_variable() {
- @SuppressWarnings("rawtypes")
- Class<ComponentTakingAllComponentsWithTypeVariable> clazz = ComponentTakingAllComponentsWithTypeVariable.class;
+ @Test
+ void require_exception_when_injecting_registry_with_unknown_type_variable() {
+ assertThrows(RuntimeException.class, () -> {
+ @SuppressWarnings("rawtypes")
+ Class<ComponentTakingAllComponentsWithTypeVariable> clazz = ComponentTakingAllComponentsWithTypeVariable.class;
- ComponentGraph componentGraph = new ComponentGraph();
- componentGraph.add(mockComponentNode(SimpleComponent.class));
- componentGraph.add(mockComponentNode(SimpleDerivedComponent.class));
- componentGraph.add(mockComponentNode(clazz));
- componentGraph.complete();
+ ComponentGraph componentGraph = new ComponentGraph();
+ componentGraph.add(mockComponentNode(SimpleComponent.class));
+ componentGraph.add(mockComponentNode(SimpleDerivedComponent.class));
+ componentGraph.add(mockComponentNode(clazz));
+ componentGraph.complete();
- componentGraph.getInstance(clazz);
+ componentGraph.getInstance(clazz);
+ });
}
@Test
- public void components_are_shared() {
+ void components_are_shared() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(SimpleComponent.class));
componentGraph.complete();
@@ -218,7 +214,7 @@ public class ComponentGraphTest {
}
@Test
- public void singleton_components_can_be_injected() {
+ void singleton_components_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
String configId = "raw:stringVal \"test-value\"";
@@ -233,17 +229,19 @@ public class ComponentGraphTest {
assertEquals("test-value", injected.config.stringVal());
}
- @Test(expected = RuntimeException.class)
- public void require_error_when_multiple_components_match_a_singleton_dependency() {
- ComponentGraph componentGraph = new ComponentGraph();
- componentGraph.add(mockComponentNode(SimpleDerivedComponent.class));
- componentGraph.add(mockComponentNode(SimpleComponent.class));
- componentGraph.add(mockComponentNode(ComponentTakingComponent.class));
- componentGraph.complete();
+ @Test
+ void require_error_when_multiple_components_match_a_singleton_dependency() {
+ assertThrows(RuntimeException.class, () -> {
+ ComponentGraph componentGraph = new ComponentGraph();
+ componentGraph.add(mockComponentNode(SimpleDerivedComponent.class));
+ componentGraph.add(mockComponentNode(SimpleComponent.class));
+ componentGraph.add(mockComponentNode(ComponentTakingComponent.class));
+ componentGraph.complete();
+ });
}
@Test
- public void named_component_can_be_injected() {
+ void named_component_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(SimpleComponent.class));
componentGraph.add(mockComponentNode(SimpleComponent.class, Names.named("named-test")));
@@ -252,7 +250,7 @@ public class ComponentGraphTest {
}
@Test
- public void config_keys_can_be_retrieved() {
+ void config_keys_can_be_retrieved() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(ComponentTakingConfig.class, "raw:stringVal \"component1\""));
componentGraph.add(mockComponentNode(ComponentTakingConfig.class, "raw:stringVal \"component2\""));
@@ -269,7 +267,7 @@ public class ComponentGraphTest {
}
@Test
- public void providers_can_be_instantiated() {
+ void providers_can_be_instantiated() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(ExecutorProvider.class));
componentGraph.complete();
@@ -278,7 +276,7 @@ public class ComponentGraphTest {
}
@Test
- public void providers_can_be_inherited() {
+ void providers_can_be_inherited() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(DerivedExecutorProvider.class));
componentGraph.complete();
@@ -287,7 +285,7 @@ public class ComponentGraphTest {
}
@Test
- public void providers_can_deliver_a_new_instance_for_each_component() {
+ void providers_can_deliver_a_new_instance_for_each_component() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(NewIntProvider.class));
componentGraph.complete();
@@ -299,7 +297,7 @@ public class ComponentGraphTest {
}
@Test
- public void providers_can_be_injected_explicitly() {
+ void providers_can_be_injected_explicitly() {
ComponentGraph componentGraph = new ComponentGraph();
Node componentTakingExecutor = mockComponentNode(ComponentTakingExecutor.class);
@@ -316,7 +314,7 @@ public class ComponentGraphTest {
}
@Test
- public void global_providers_can_be_injected() {
+ void global_providers_can_be_injected() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(ComponentTakingExecutor.class));
@@ -327,18 +325,20 @@ public class ComponentGraphTest {
assertNotNull(componentGraph.getInstance(ComponentTakingExecutor.class));
}
- @Test(expected = RuntimeException.class)
- public void throw_if_multiple_global_providers_exist() {
- ComponentGraph componentGraph = new ComponentGraph();
+ @Test
+ void throw_if_multiple_global_providers_exist() {
+ assertThrows(RuntimeException.class, () -> {
+ ComponentGraph componentGraph = new ComponentGraph();
- componentGraph.add(mockComponentNode(ExecutorProvider.class));
- componentGraph.add(mockComponentNode(ExecutorProvider.class));
- componentGraph.add(mockComponentNode(ComponentTakingExecutor.class));
- componentGraph.complete();
+ componentGraph.add(mockComponentNode(ExecutorProvider.class));
+ componentGraph.add(mockComponentNode(ExecutorProvider.class));
+ componentGraph.add(mockComponentNode(ComponentTakingExecutor.class));
+ componentGraph.complete();
+ });
}
@Test
- public void provider_is_not_used_when_component_of_provided_class_exists() {
+ void provider_is_not_used_when_component_of_provided_class_exists() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(SimpleComponent.class));
@@ -352,13 +352,13 @@ public class ComponentGraphTest {
//TODO: move
@Test
- public void check_if_annotation_is_a_binding_annotation() {
+ void check_if_annotation_is_a_binding_annotation() {
assertTrue(isBindingAnnotation(Names.named("name")));
assertFalse(isBindingAnnotation(Named.class.getAnnotations()[0]));
}
@Test
- public void cycles_gives_exception() {
+ void cycles_gives_exception() {
ComponentGraph componentGraph = new ComponentGraph();
Node node1 = mockComponentNode(ComponentCausingCycle.class);
@@ -379,18 +379,20 @@ public class ComponentGraphTest {
}
}
- @Test(expected = IllegalArgumentException.class)
- public void abstract_classes_are_rejected() {
- new ComponentNode(ComponentId.fromString("Test"), "", AbstractClass.class);
+ @Test
+ void abstract_classes_are_rejected() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ new ComponentNode(ComponentId.fromString("Test"), "", AbstractClass.class);
+ });
}
@Test
- public void inject_constructor_is_preferred() {
+ void inject_constructor_is_preferred() {
assertThatComponentCanBeCreated(ComponentWithInjectConstructor.class);
}
@Test
- public void constructor_with_most_parameters_is_preferred() {
+ void constructor_with_most_parameters_is_preferred() {
assertThatComponentCanBeCreated(ComponentWithMultipleConstructors.class);
}
@@ -407,7 +409,7 @@ public class ComponentGraphTest {
}
@Test
- public void require_fallback_to_child_injector() {
+ void require_fallback_to_child_injector() {
ComponentGraph componentGraph = new ComponentGraph();
componentGraph.add(mockComponentNode(ComponentTakingExecutor.class));
@@ -417,7 +419,7 @@ public class ComponentGraphTest {
}
@Test
- public void child_injector_can_inject_multiple_instances_for_same_key() {
+ void child_injector_can_inject_multiple_instances_for_same_key() {
Pair<Integer, Pair<Executor, Executor>> graph = buildGraphWithChildInjector(Executors::newSingleThreadExecutor);
int graphSize = graph.getFirst();
Executor executorA = graph.getSecond().getFirst();
@@ -428,7 +430,7 @@ public class ComponentGraphTest {
}
@Test
- public void components_injected_via_child_injector_can_be_shared() {
+ void components_injected_via_child_injector_can_be_shared() {
Executor commonExecutor = Executors.newSingleThreadExecutor();
Pair<Integer, Pair<Executor, Executor>> graph = buildGraphWithChildInjector(() -> commonExecutor);
int graphSize = graph.getFirst();
@@ -462,7 +464,7 @@ public class ComponentGraphTest {
}
@Test
- public void providers_can_be_reused() {
+ void providers_can_be_reused() {
ComponentGraph oldGraph = createReusingGraph();
Executor executor = oldGraph.getInstance(Executor.class);
@@ -483,7 +485,7 @@ public class ComponentGraphTest {
}
@Test
- public void component_id_can_be_injected() {
+ void component_id_can_be_injected() {
String componentId = "myId:1.2@namespace";
ComponentGraph componentGraph = new ComponentGraph();
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java
index 1e3d67ed463..878c245a708 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java
@@ -11,18 +11,15 @@ import com.yahoo.component.AbstractComponent;
import com.yahoo.component.ComponentId;
import com.yahoo.config.ConfigInstance;
import com.yahoo.vespa.config.ConfigKey;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Tony Vaagenes
@@ -36,7 +33,7 @@ public class FallbackToGuiceInjectorTest {
private final Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configs = new HashMap<>();
- @Before
+ @BeforeEach
public void createGraph() {
injector = Guice.createInjector();
componentGraph = new ComponentGraph(0);
@@ -70,7 +67,7 @@ public class FallbackToGuiceInjectorTest {
}
@Test
- public void guice_injector_is_used_when_no_global_component_exists() {
+ void guice_injector_is_used_when_no_global_component_exists() {
setInjector(
Guice.createInjector(new AbstractModule() {
@Override
@@ -89,7 +86,7 @@ public class FallbackToGuiceInjectorTest {
}
@Test
- public void guice_injector_creates_a_new_instance_with_default_ctor_when_no_explicit_binding_exists() {
+ void guice_injector_creates_a_new_instance_with_default_ctor_when_no_explicit_binding_exists() {
setInjector(emptyGuiceInjector());
register(ComponentTakingDefaultString.class);
complete();
@@ -99,7 +96,7 @@ public class FallbackToGuiceInjectorTest {
}
@Test
- public void guice_injector_fails_when_no_explicit_binding_exists_and_class_has_no_default_ctor() {
+ void guice_injector_fails_when_no_explicit_binding_exists_and_class_has_no_default_ctor() {
setInjector(emptyGuiceInjector());
register(ComponentThatCannotBeConstructed.class);
try {
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java
index 2215fcdf4dd..edd06e37e64 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java
@@ -14,16 +14,14 @@ import com.yahoo.container.di.componentgraph.core.ComponentGraphTest.ExecutorPro
import com.yahoo.container.di.componentgraph.core.ComponentGraphTest.SimpleComponent;
import com.yahoo.container.di.componentgraph.core.ComponentGraphTest.SimpleComponent2;
import com.yahoo.vespa.config.ConfigKey;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.function.Supplier;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author gjoranv
@@ -32,7 +30,7 @@ import static org.junit.Assert.assertSame;
*/
public class ReuseComponentsTest {
@Test
- public void require_that_component_is_reused_when_componentNode_is_unmodified() {
+ void require_that_component_is_reused_when_componentNode_is_unmodified() {
reuseAndTest(SimpleComponent.class, SimpleComponent.class);
reuseAndTest(ExecutorProvider.class, Executor.class);
}
@@ -48,23 +46,25 @@ public class ReuseComponentsTest {
assertSame(instance2, instance);
}
- @Test(expected = IllegalStateException.class)
- public void require_that_component_is_not_reused_when_class_is_changed() {
- ComponentGraph graph = buildGraphAndSetNoConfigs(SimpleComponent.class);
- SimpleComponent instance = getComponent(graph, SimpleComponent.class);
-
- ComponentGraph newGraph = buildGraphAndSetNoConfigs(SimpleComponent2.class);
- newGraph.reuseNodes(graph);
- SimpleComponent2 instance2 = getComponent(newGraph, SimpleComponent2.class);
-
- assertEquals(instance2.getId(),instance.getId());
- @SuppressWarnings("unused")
- SimpleComponent throwsException = getComponent(newGraph, SimpleComponent.class);
+ @Test
+ void require_that_component_is_not_reused_when_class_is_changed() {
+ assertThrows(IllegalStateException.class, () -> {
+ ComponentGraph graph = buildGraphAndSetNoConfigs(SimpleComponent.class);
+ SimpleComponent instance = getComponent(graph, SimpleComponent.class);
+
+ ComponentGraph newGraph = buildGraphAndSetNoConfigs(SimpleComponent2.class);
+ newGraph.reuseNodes(graph);
+ SimpleComponent2 instance2 = getComponent(newGraph, SimpleComponent2.class);
+
+ assertEquals(instance2.getId(), instance.getId());
+ @SuppressWarnings("unused")
+ SimpleComponent throwsException = getComponent(newGraph, SimpleComponent.class);
+ });
}
@SuppressWarnings("deprecation")
@Test
- public void require_that_component_is_not_reused_when_config_is_changed() {
+ void require_that_component_is_not_reused_when_config_is_changed() {
Class<ComponentTakingConfig> componentClass = ComponentTakingConfig.class;
ComponentGraph graph = buildGraph(componentClass);
@@ -83,7 +83,7 @@ public class ReuseComponentsTest {
@SuppressWarnings("deprecation")
@Test
- public void require_that_component_is_not_reused_when_injected_component_is_changed() {
+ void require_that_component_is_not_reused_when_injected_component_is_changed() {
Function<String, ComponentGraph> buildGraph = config -> {
ComponentGraph graph = new ComponentGraph();
@@ -115,7 +115,7 @@ public class ReuseComponentsTest {
}
@Test
- public void require_that_component_is_not_reused_when_injected_component_registry_has_one_component_removed() {
+ void require_that_component_is_not_reused_when_injected_component_registry_has_one_component_removed() {
Function<Boolean, ComponentGraph> buildGraph = useBothInjectedComponents -> {
ComponentGraph graph = new ComponentGraph();
graph.add(mockComponentNode(ComponentTakingAllSimpleComponents.class, "root_component"));
@@ -148,7 +148,7 @@ public class ReuseComponentsTest {
@SuppressWarnings("deprecation")
@Test
- public void require_that_injected_component_is_reused_even_when_dependent_component_is_changed() {
+ void require_that_injected_component_is_reused_even_when_dependent_component_is_changed() {
Function<String, ComponentGraph> buildGraph = config -> {
ComponentGraph graph = new ComponentGraph();
@@ -183,7 +183,7 @@ public class ReuseComponentsTest {
}
@Test
- public void require_that_node_depending_on_guice_node_is_reused() {
+ void require_that_node_depending_on_guice_node_is_reused() {
Supplier<ComponentGraph> makeGraph = () -> {
ComponentGraph graph = new ComponentGraph();
graph.add(mockComponentNode(ComponentTakingExecutor.class, "dummyId"));
@@ -202,7 +202,7 @@ public class ReuseComponentsTest {
}
@Test
- public void require_that_node_equals_only_checks_first_level_components_to_inject() {
+ void require_that_node_equals_only_checks_first_level_components_to_inject() {
Function<String, Node> createNodeWithInjectedNodeWithInjectedNode = indirectlyInjectedComponentId -> {
ComponentNode targetComponent = mockComponentNode(SimpleComponent.class, "target");
ComponentNode directlyInjectedComponent = mockComponentNode(SimpleComponent.class, "directlyInjected");
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java
index 65fbdc578aa..b7ce61c2f1a 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java
@@ -2,7 +2,7 @@
package com.yahoo.container.di.componentgraph.cycle;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
@@ -10,7 +10,7 @@ import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertic
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.B;
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.C;
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.D;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author gjoranv
@@ -20,7 +20,7 @@ public class CycleFinderTest {
enum Vertices {A, B, C, D}
@Test
- public void graph_without_cycles_returns_no_cycle() {
+ void graph_without_cycles_returns_no_cycle() {
var graph = new Graph<Vertices>();
graph.edge(A, B);
graph.edge(B, C);
@@ -32,7 +32,7 @@ public class CycleFinderTest {
}
@Test
- public void graph_with_cycle_returns_cycle() {
+ void graph_with_cycle_returns_cycle() {
var graph = new Graph<Vertices>();
graph.edge(A, B);
graph.edge(B, C);
@@ -43,7 +43,7 @@ public class CycleFinderTest {
}
@Test
- public void graph_with_self_referencing_vertex_returns_cycle() {
+ void graph_with_self_referencing_vertex_returns_cycle() {
var graph = new Graph<Vertices>();
graph.edge(A, A);
@@ -52,7 +52,7 @@ public class CycleFinderTest {
}
@Test
- public void leading_nodes_are_stripped_from_cycle() {
+ void leading_nodes_are_stripped_from_cycle() {
var graph = new Graph<Vertices>();
graph.edge(A, B);
graph.edge(B, C);
@@ -63,7 +63,7 @@ public class CycleFinderTest {
}
@Test
- public void findCycle_is_idempotent_with_cycle() {
+ void findCycle_is_idempotent_with_cycle() {
var graph = new Graph<Vertices>();
graph.edge(A, A);
@@ -73,7 +73,7 @@ public class CycleFinderTest {
}
@Test
- public void findCycle_is_idempotent_without_cycle() {
+ void findCycle_is_idempotent_without_cycle() {
var graph = new Graph<Vertices>();
graph.edge(A, B);
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java
index 526e683ad46..d945b4f0544 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java
@@ -2,16 +2,14 @@
package com.yahoo.container.di.componentgraph.cycle;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
import static com.yahoo.container.di.componentgraph.cycle.GraphTest.Vertices.A;
import static com.yahoo.container.di.componentgraph.cycle.GraphTest.Vertices.B;
import static com.yahoo.container.di.componentgraph.cycle.GraphTest.Vertices.C;
-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
@@ -21,7 +19,7 @@ public class GraphTest {
enum Vertices {A, B, C}
@Test
- public void vertices_and_edges_are_added_and_can_be_retrieved() {
+ void vertices_and_edges_are_added_and_can_be_retrieved() {
var graph = new Graph<Vertices>();
graph.edge(A, B);
graph.edge(B, C);
@@ -34,7 +32,7 @@ public class GraphTest {
}
@Test
- public void null_vertices_are_not_allowed() {
+ void null_vertices_are_not_allowed() {
var graph = new Graph<Vertices>();
try {
@@ -46,7 +44,7 @@ public class GraphTest {
}
@Test
- public void duplicate_edges_are_ignored() {
+ void duplicate_edges_are_ignored() {
var graph = new Graph<Vertices>();
graph.edge(A, B);
graph.edge(A, B);
@@ -55,7 +53,7 @@ public class GraphTest {
}
@Test
- public void self_edges_are_allowed() {
+ void self_edges_are_allowed() {
var graph = new Graph<Vertices>();
graph.edge(A, A);
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
}
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();
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);
}
}