diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo/config')
18 files changed, 383 insertions, 382 deletions
diff --git a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java index ec5850b95b9..c1dd62316db 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java @@ -18,10 +18,9 @@ import com.yahoo.schema.Schema; import com.yahoo.vespa.config.ConfigDefinition; import com.yahoo.vespa.config.ConfigDefinitionKey; import com.yahoo.vespa.model.VespaModel; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.xml.sax.SAXException; import java.io.File; @@ -36,22 +35,18 @@ import java.util.Map; import java.util.Set; import java.util.jar.JarEntry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -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.*; public class ApplicationDeployTest { private static final String TESTDIR = "src/test/cfg/application/"; private static final String TEST_SCHEMAS_DIR = TESTDIR + "app1/schemas/"; - @Rule - public TemporaryFolder tmpFolder = new TemporaryFolder(); + @TempDir + public File tmpFolder; @Test - public void testVespaModel() throws SAXException, IOException { + void testVespaModel() throws SAXException, IOException { ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "app1"); new VespaModel(tester.app()); List<Schema> schemas = tester.getSchemas(); @@ -72,11 +67,11 @@ public class ApplicationDeployTest { } } assertEquals(Set.of(new File(TEST_SCHEMAS_DIR + "laptop.sd"), - new File(TEST_SCHEMAS_DIR + "music.sd"), - new File(TEST_SCHEMAS_DIR + "pc.sd"), - new File(TEST_SCHEMAS_DIR + "product.sd"), - new File(TEST_SCHEMAS_DIR + "sock.sd")), - new HashSet<>(tester.app().getSearchDefinitionFiles())); + new File(TEST_SCHEMAS_DIR + "music.sd"), + new File(TEST_SCHEMAS_DIR + "pc.sd"), + new File(TEST_SCHEMAS_DIR + "product.sd"), + new File(TEST_SCHEMAS_DIR + "sock.sd")), + new HashSet<>(tester.app().getSearchDefinitionFiles())); List<FilesApplicationPackage.Component> components = tester.app().getComponents(); assertEquals(1, components.size()); @@ -104,7 +99,7 @@ public class ApplicationDeployTest { } @Test - public void testGetFile() throws IOException { + void testGetFile() throws IOException { ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "app1"); try (Reader foo = tester.app().getFile(Path.fromString("files/foo.json")).createReader()) { assertEquals(IOUtils.readAll(foo), "foo : foo\n"); @@ -128,7 +123,7 @@ public class ApplicationDeployTest { } @Test - public void include_dirs_are_included() { + void include_dirs_are_included() { ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "include_dirs"); Set<String> includeDirs = new HashSet<>(tester.app().getUserIncludeDirs()); @@ -136,12 +131,12 @@ public class ApplicationDeployTest { } @Test - public void non_existent_include_dir_is_not_allowed() throws Exception { - File appDir = tmpFolder.newFolder("non-existent-include"); + void non_existent_include_dir_is_not_allowed() throws Exception { + File appDir = newFolder(tmpFolder, "non-existent-include"); String services = "<services version='1.0'>" + - " <include dir='non-existent' />" + - "</services>\n"; + " <include dir='non-existent' />" + + "</services>\n"; IOUtils.writeFile(new File(appDir, "services.xml"), services, false); try { @@ -149,13 +144,13 @@ public class ApplicationDeployTest { fail("Expected exception due to non-existent include dir"); } catch (IllegalArgumentException e) { assertEquals("Cannot include directory 'non-existent', as it does not exist. Directory must reside in application package, and path must be given relative to application package.", - e.getMessage()); + e.getMessage()); } } @Test - public void testThatModelIsRebuiltWhenSearchDefinitionIsAdded() throws IOException { - File tmpDir = tmpFolder.getRoot(); + void testThatModelIsRebuiltWhenSearchDefinitionIsAdded() throws IOException { + File tmpDir = tmpFolder; IOUtils.copyDirectory(new File(TESTDIR, "app1"), tmpDir); ApplicationPackageTester tester = ApplicationPackageTester.create(tmpDir.getAbsolutePath()); assertEquals(5, tester.getSchemas().size()); @@ -166,55 +161,57 @@ public class ApplicationDeployTest { } @Test - public void testThatAppWithDeploymentXmlIsValid() throws IOException { - File tmpDir = tmpFolder.getRoot(); + void testThatAppWithDeploymentXmlIsValid() throws IOException { + File tmpDir = tmpFolder; IOUtils.copyDirectory(new File(TESTDIR, "app1"), tmpDir); ApplicationPackageTester.create(tmpDir.getAbsolutePath()); } - @Test(expected = IllegalArgumentException.class) - public void testThatAppWithIllegalDeploymentXmlIsNotValid() throws IOException { - File tmpDir = tmpFolder.getRoot(); - IOUtils.copyDirectory(new File(TESTDIR, "app_invalid_deployment_xml"), tmpDir); - ApplicationPackageTester.create(tmpDir.getAbsolutePath()); + @Test + void testThatAppWithIllegalDeploymentXmlIsNotValid() throws IOException { + assertThrows(IllegalArgumentException.class, () -> { + File tmpDir = tmpFolder; + IOUtils.copyDirectory(new File(TESTDIR, "app_invalid_deployment_xml"), tmpDir); + ApplicationPackageTester.create(tmpDir.getAbsolutePath()); + }); } @Test - public void testComplicatedDeploymentSpec() throws IOException { - File tmpDir = tmpFolder.getRoot(); + void testComplicatedDeploymentSpec() throws IOException { + File tmpDir = tmpFolder; IOUtils.copyDirectory(new File(TESTDIR, "app_complicated_deployment_spec"), tmpDir); ApplicationPackageTester.create(tmpDir.getAbsolutePath()); } @Test - public void testAppWithEmptyProdRegion() throws IOException { - File tmpDir = tmpFolder.getRoot(); + void testAppWithEmptyProdRegion() throws IOException { + File tmpDir = tmpFolder; IOUtils.copyDirectory(new File(TESTDIR, "empty_prod_region_in_deployment_xml"), tmpDir); ApplicationPackageTester.create(tmpDir.getAbsolutePath()); } @Test - public void testThatAppWithInvalidParallelDeploymentFails() throws IOException { + void testThatAppWithInvalidParallelDeploymentFails() throws IOException { String expectedMessage = "4: <staging/>\n" + - "5: <prod global-service-id=\"query\">\n" + - "6: <parallel>\n" + - "7: <instance id=\"hello\" />\n" + - "8: </parallel>\n" + - "9: </prod>\n" + - "10:</deployment>\n"; - File tmpDir = tmpFolder.getRoot(); + "5: <prod global-service-id=\"query\">\n" + + "6: <parallel>\n" + + "7: <instance id=\"hello\" />\n" + + "8: </parallel>\n" + + "9: </prod>\n" + + "10:</deployment>\n"; + File tmpDir = tmpFolder; IOUtils.copyDirectory(new File(TESTDIR, "invalid_parallel_deployment_xml"), tmpDir); try { ApplicationPackageTester.create(tmpDir.getAbsolutePath()); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("Invalid XML according to XML schema, error in deployment.xml: element \"instance\" not allowed here; expected the element end-tag or element \"delay\", \"region\", \"steps\" or \"test\" [7:30], input:\n" + expectedMessage, - e.getMessage()); + e.getMessage()); } } @Test - public void testConfigDefinitionsFromJars() { + void testConfigDefinitionsFromJars() { String appName = "src/test/cfg//application/app1"; FilesApplicationPackage app = FilesApplicationPackage.fromFile(new File(appName), false); Map<ConfigDefinitionKey, UnparsedConfigDefinition> defs = app.getAllExistingConfigDefs(); @@ -222,25 +219,25 @@ public class ApplicationDeployTest { } @Test - public void testMetaData() throws IOException { + void testMetaData() throws IOException { File tmp = Files.createTempDir(); String appPkg = TESTDIR + "app1"; IOUtils.copyDirectory(new File(appPkg), tmp); ApplicationId applicationId = ApplicationId.from("tenant1", "application1", "instance1"); DeployData deployData = new DeployData("bar", - applicationId, - 13L, - false, - 1337L, - 3L); + applicationId, + 13L, + false, + 1337L, + 3L); FilesApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData); app.writeMetaData(); FilesApplicationPackage newApp = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData); ApplicationMetaData meta = newApp.getMetaData(); assertEquals("bar", meta.getDeployPath()); assertEquals(applicationId, meta.getApplicationId()); - assertEquals(13L, (long)meta.getDeployTimestamp()); - assertEquals(1337L, (long)meta.getGeneration()); + assertEquals(13L, (long) meta.getDeployTimestamp()); + assertEquals(1337L, (long) meta.getGeneration()); assertEquals(3L, meta.getPreviousActiveGeneration()); String checksum = meta.getChecksum(); assertNotNull(checksum); @@ -257,7 +254,7 @@ public class ApplicationDeployTest { } @Test - public void testGetJarEntryName() { + void testGetJarEntryName() { JarEntry e = new JarEntry("/schemas/foo.sd"); assertEquals(ApplicationPackage.getFileName(e), "foo.sd"); e = new JarEntry("bar"); @@ -267,7 +264,7 @@ public class ApplicationDeployTest { } @Test - public void testGetJarEntryNameForLegacyPath() { + void testGetJarEntryNameForLegacyPath() { JarEntry e = new JarEntry("/searchdefinitions/foo.sd"); assertEquals(ApplicationPackage.getFileName(e), "foo.sd"); e = new JarEntry("bar"); @@ -276,7 +273,7 @@ public class ApplicationDeployTest { assertEquals(ApplicationPackage.getFileName(e), ""); } - @After + @AfterEach public void cleanDirs() { IOUtils.recursiveDeleteDir(new File(TESTDIR + "app1/myDir")); IOUtils.recursiveDeleteDir(new File(TESTDIR + "app1/searchdefinitions/myDir2")); @@ -284,7 +281,7 @@ public class ApplicationDeployTest { } @SuppressWarnings("ResultOfMethodCallIgnored") - @After + @AfterEach public void cleanFiles() { new File(new File(TESTDIR + "app1"),"foo.txt").delete(); new File(new File(TESTDIR + "app1"),"searchdefinitions/bar.text").delete(); @@ -295,13 +292,13 @@ public class ApplicationDeployTest { * Tests that an invalid jar is identified as not being a jar file */ @Test - public void testInvalidJar() { + void testInvalidJar() { try { FilesApplicationPackage.getComponents(new File("src/test/cfg/application/validation/invalidjar_app")); fail(); } catch (IllegalArgumentException e) { assertEquals("Error opening jar file 'invalid.jar'. Please check that this is a valid jar file", - e.getMessage()); + e.getMessage()); } } @@ -312,7 +309,7 @@ public class ApplicationDeployTest { * definition without version in file name */ @Test - public void testConfigDefinitionsAndNamespaces() { + void testConfigDefinitionsAndNamespaces() { final File appDir = new File("src/test/cfg/application/configdeftest"); FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir); @@ -330,10 +327,21 @@ public class ApplicationDeployTest { assertEquals("bar", def.getName()); } - @Test(expected=IllegalArgumentException.class) - public void testDifferentNameOfSdFileAndSearchName() { - ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "sdfilenametest"); - new DeployState.Builder().applicationPackage(tester.app()).build(); + @Test + void testDifferentNameOfSdFileAndSearchName() { + assertThrows(IllegalArgumentException.class, () -> { + ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "sdfilenametest"); + new DeployState.Builder().applicationPackage(tester.app()).build(); + }); + } + + 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/config-model/src/test/java/com/yahoo/config/model/ConfigModelBuilderTest.java b/config-model/src/test/java/com/yahoo/config/model/ConfigModelBuilderTest.java index e5909091534..11de928c14c 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ConfigModelBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ConfigModelBuilderTest.java @@ -3,14 +3,14 @@ package com.yahoo.config.model; import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Element; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * @author Ulf Lilleengen @@ -18,33 +18,33 @@ import static org.junit.Assert.assertTrue; */ public class ConfigModelBuilderTest { @Test - public void testEquals() { + void testEquals() { ConfigModelBuilder<?> ba = new A.Builder(); ConfigModelBuilder<?> ba2 = new A2.Builder(); ConfigModelBuilder<?> bb = new B.Builder(); - ConfigModelBuilder <?>bb2 = new B2.Builder(); + ConfigModelBuilder<?> bb2 = new B2.Builder(); - assertTrue(ba.equals(ba)); - assertTrue(ba.equals(ba2)); - assertFalse(ba.equals(bb)); - assertFalse(ba.equals(bb2)); + assertEquals(ba, ba); + assertEquals(ba, ba2); + assertNotEquals(ba, bb); + assertNotEquals(ba, bb2); - assertTrue(ba2.equals(ba)); - assertTrue(ba2.equals(ba2)); - assertFalse(ba2.equals(bb)); - assertFalse(ba2.equals(bb2)); + assertEquals(ba2, ba); + assertEquals(ba2, ba2); + assertNotEquals(ba2, bb); + assertNotEquals(ba2, bb2); - assertFalse(bb.equals(ba)); - assertFalse(bb.equals(ba2)); - assertTrue(bb.equals(bb)); - assertFalse(bb.equals(bb2)); + assertNotEquals(bb, ba); + assertNotEquals(bb, ba2); + assertEquals(bb, bb); + assertNotEquals(bb, bb2); - assertFalse(bb2.equals(ba)); - assertFalse(bb2.equals(ba2)); - assertFalse(bb2.equals(bb)); - assertTrue(bb2.equals(bb2)); + assertNotEquals(bb2, ba); + assertNotEquals(bb2, ba2); + assertNotEquals(bb2, bb); + assertEquals(bb2, bb2); - assertFalse(ba.equals(new ArrayList<>())); + assertNotEquals(ba, new ArrayList<>()); } private static class A extends ConfigModel { diff --git a/config-model/src/test/java/com/yahoo/config/model/ConfigModelContextTest.java b/config-model/src/test/java/com/yahoo/config/model/ConfigModelContextTest.java index 532c446ec6f..55fe909e70d 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ConfigModelContextTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ConfigModelContextTest.java @@ -7,10 +7,10 @@ import com.yahoo.config.model.deploy.DeployState; import com.yahoo.config.model.producer.AbstractConfigProducer; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.model.test.MockRoot; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * @author Ulf Lilleengen @@ -18,7 +18,7 @@ import static org.junit.Assert.assertNotEquals; public class ConfigModelContextTest { @Test - public void testConfigModelContext() { + void testConfigModelContext() { MockRoot root = new MockRoot(); String id = "foobar"; ApplicationPackage pkg = new MockApplicationPackage.Builder() diff --git a/config-model/src/test/java/com/yahoo/config/model/ConfigModelUtilsTest.java b/config-model/src/test/java/com/yahoo/config/model/ConfigModelUtilsTest.java index 325361e0127..3db4948c8c3 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ConfigModelUtilsTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ConfigModelUtilsTest.java @@ -2,13 +2,13 @@ package com.yahoo.config.model; import com.yahoo.config.model.application.provider.Bundle; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; -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 Ulf Lilleengen @@ -19,38 +19,38 @@ public class ConfigModelUtilsTest { public static final String INVALID_TEST_BUNDLE = "src/test/cfg/application/validation/invalidjar_app/components"; @Test - public void all_def_files_in_correct_directory_are_handled_and_files_outside_are_ignored() { + void all_def_files_in_correct_directory_are_handled_and_files_outside_are_ignored() { List<Bundle> bundles = Bundle.getBundles(new File(VALID_TEST_BUNDLE)); assertEquals(1, bundles.size()); assertEquals(5, bundles.get(0).getDefEntries().size()); } @Test - public void def_file_with_namespace_is_handled() { + void def_file_with_namespace_is_handled() { Bundle.DefEntry defEntry = getDefEntry("test-namespace"); assertEquals("config", defEntry.defNamespace); } @Test - public void def_file_with_namespace_and_namespace_in_filename_is_handled() { + void def_file_with_namespace_and_namespace_in_filename_is_handled() { Bundle.DefEntry defEntry = getDefEntry("namespace-in-filename"); assertEquals("a.b", defEntry.defNamespace); } @Test - public void def_file_with_package_is_handled() { + void def_file_with_package_is_handled() { Bundle.DefEntry defEntry = getDefEntry("test-package"); assertEquals("com.mydomain.mypackage", defEntry.defNamespace); } @Test - public void def_file_with_package_and_pacakage_in_filename_is_handled() { + void def_file_with_package_and_pacakage_in_filename_is_handled() { Bundle.DefEntry defEntry = getDefEntry("package-in-filename"); assertEquals("com.mydomain.mypackage", defEntry.defNamespace); } @Test - public void def_file_with_both_package_and_namespace_gets_package_as_namespace() { + void def_file_with_both_package_and_namespace_gets_package_as_namespace() { Bundle.DefEntry defEntry = getDefEntry("namespace-and-package"); assertEquals("com.mydomain.mypackage", defEntry.defNamespace); } @@ -66,7 +66,7 @@ public class ConfigModelUtilsTest { } @Test - public void invalid_jar_file_fails_to_load() { + void invalid_jar_file_fails_to_load() { try { Bundle.getBundles(new File(INVALID_TEST_BUNDLE)); fail(); diff --git a/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java b/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java index e5e61459b44..84c1d66a507 100644 --- a/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/MapConfigModelRegistryTest.java @@ -3,14 +3,14 @@ package com.yahoo.config.model; import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.builder.xml.ConfigModelId; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.Element; import java.util.Collection; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Ulf Lilleengen @@ -19,7 +19,7 @@ import static org.junit.Assert.*; public class MapConfigModelRegistryTest { @Test - public void require_that_registry_finds_components() { + void require_that_registry_finds_components() { ModelABuilder ba = new ModelABuilder(); ModelBBuilder bb = new ModelBBuilder(); ConfigModelRegistry registry = MapConfigModelRegistry.createFromList(ba, bb); @@ -31,7 +31,7 @@ public class MapConfigModelRegistryTest { } @Test - public void require_all_builders_for_a_tag() { + void require_all_builders_for_a_tag() { ModelBBuilder b1 = new ModelBBuilder(); ModelB2Builder b2 = new ModelB2Builder(); ConfigModelRegistry registry = MapConfigModelRegistry.createFromList(b1, b2); diff --git a/config-model/src/test/java/com/yahoo/config/model/QrserverAndGatewayPortAllocationTest.java b/config-model/src/test/java/com/yahoo/config/model/QrserverAndGatewayPortAllocationTest.java index a06da645e17..5e696682e98 100644 --- a/config-model/src/test/java/com/yahoo/config/model/QrserverAndGatewayPortAllocationTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/QrserverAndGatewayPortAllocationTest.java @@ -5,11 +5,11 @@ import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.container.Container; import com.yahoo.vespa.model.container.ApplicationContainer; import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests that qrserver is assigned port Defaults.getDefaults().vespaWebServicePort() even if there is a HTTP gateway configured earlier in @@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals; public class QrserverAndGatewayPortAllocationTest { @Test - public void testPorts() { + void testPorts() { String appDir = "src/test/cfg/application/app_qrserverandgw/"; VespaModelCreatorWithFilePkg creator = new VespaModelCreatorWithFilePkg(appDir); VespaModel vespaModel = creator.create(); diff --git a/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java b/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java index 1bf8c834586..7d3e6e81cd0 100644 --- a/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/application/provider/SchemaValidatorTest.java @@ -3,14 +3,15 @@ package com.yahoo.config.model.application.provider; import com.yahoo.component.Version; import com.yahoo.vespa.config.VespaVersion; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; import java.io.StringReader; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author hmusum */ @@ -41,44 +42,43 @@ public class SchemaValidatorTest { " </admin>\n" + "</services>\n"; - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Test - public void testXMLParse() throws IOException { + void testXMLParse() throws IOException { SchemaValidator validator = createValidator(); validator.validate(new StringReader(okServices)); } @Test - public void testXMLParseError() throws IOException { - SchemaValidator validator = createValidator(); - expectedException.expect(RuntimeException.class); - expectedException.expectMessage(expectedErrorMessage("input")); - validator.validate(new StringReader(invalidServices)); + void testXMLParseError() throws IOException { + Throwable exception = assertThrows(RuntimeException.class, () -> { + SchemaValidator validator = createValidator(); + validator.validate(new StringReader(invalidServices)); + }); + assertTrue(exception.getMessage().contains(expectedErrorMessage("input"))); } @Test - public void testXMLParseWithReader() throws IOException { + void testXMLParseWithReader() throws IOException { SchemaValidator validator = createValidator(); validator.validate(new StringReader(okServices)); } @Test - public void testXMLParseErrorWithReader() throws IOException { - SchemaValidator validator = createValidator(); - expectedException.expect(RuntimeException.class); - expectedException.expectMessage(expectedErrorMessage("input")); - validator.validate(new StringReader(invalidServices)); + void testXMLParseErrorWithReader() throws IOException { + Throwable exception = assertThrows(RuntimeException.class, () -> { + SchemaValidator validator = createValidator(); + validator.validate(new StringReader(invalidServices)); + }); + assertTrue(exception.getMessage().contains(expectedErrorMessage("input"))); } @Test - public void testXMLParseErrorFromFile() throws IOException { - SchemaValidator validator = createValidator(); - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage(expectedErrorMessage("services.xml")); - validator.validate(new File("src/test/cfg/application/invalid-services-syntax/services.xml")); + void testXMLParseErrorFromFile() throws IOException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SchemaValidator validator = createValidator(); + validator.validate(new File("src/test/cfg/application/invalid-services-syntax/services.xml")); + }); + assertTrue(exception.getMessage().contains(expectedErrorMessage("services.xml"))); } private SchemaValidator createValidator() { diff --git a/config-model/src/test/java/com/yahoo/config/model/builder/xml/ConfigModelIdTest.java b/config-model/src/test/java/com/yahoo/config/model/builder/xml/ConfigModelIdTest.java index 931768b6fd9..b1354446d1f 100644 --- a/config-model/src/test/java/com/yahoo/config/model/builder/xml/ConfigModelIdTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/builder/xml/ConfigModelIdTest.java @@ -2,12 +2,9 @@ package com.yahoo.config.model.builder.xml; import com.yahoo.component.Version; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Ulf Lilleengen @@ -16,7 +13,7 @@ import static org.junit.Assert.assertTrue; public class ConfigModelIdTest { @Test - public void require_that_element_gets_correct_name() { + void require_that_element_gets_correct_name() { ConfigModelId id = ConfigModelId.fromName("foo"); assertEquals("foo", id.getName()); assertEquals(Version.fromString("1"), id.getVersion()); @@ -26,7 +23,7 @@ public class ConfigModelIdTest { } @Test - public void test_toString() { + void test_toString() { ConfigModelId id = ConfigModelId.fromNameAndVersion("bar", "1.0"); assertEquals("bar.1", id.toString()); id = ConfigModelId.fromNameAndVersion("foo", "1.1.3"); @@ -36,7 +33,7 @@ public class ConfigModelIdTest { } @Test - public void test_equality() { + void test_equality() { ConfigModelId a1 = ConfigModelId.fromName("a"); ConfigModelId a2 = ConfigModelId.fromName("a"); ConfigModelId b = ConfigModelId.fromName("b"); @@ -52,18 +49,18 @@ public class ConfigModelIdTest { } @Test - public void test_compare() { + void test_compare() { ConfigModelId a1 = ConfigModelId.fromName("a"); ConfigModelId a2 = ConfigModelId.fromName("a"); ConfigModelId b = ConfigModelId.fromName("b"); - assertTrue(a1.compareTo(a2) == 0); - assertTrue(a2.compareTo(a1) == 0); + assertEquals(a1.compareTo(a2), 0); + assertEquals(a2.compareTo(a1), 0); assertFalse(a1.compareTo(b) > 0); assertFalse(a2.compareTo(b) > 0); assertFalse(b.compareTo(a1) < 0); assertFalse(b.compareTo(a2) < 0); - assertTrue(a1.compareTo(a1) == 0); - assertTrue(a2.compareTo(a2) == 0); - assertTrue(b.compareTo(b) == 0); + assertEquals(a1.compareTo(a1), 0); + assertEquals(a2.compareTo(a2), 0); + assertEquals(b.compareTo(b), 0); } } diff --git a/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java b/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java index ee616f59d04..a19bc2347d4 100644 --- a/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java @@ -1,11 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.model.builder.xml; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; import java.io.FileReader; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author hmusum @@ -13,24 +13,24 @@ import static org.junit.Assert.assertEquals; public class XmlErrorHandlingTest { @Test - public void requireExceptionWithSourceAndFilenameAndLineNumber() { + void requireExceptionWithSourceAndFilenameAndLineNumber() { try { XmlHelper.getDocument(new FileReader("src/test/cfg/application/invalid-services-syntax/services.xml"), "services.xml"); } catch (Exception e) { assertEquals("Invalid XML in services.xml: The element type \"config\" must be terminated by the matching end-tag \"</config>\". [7:5]", - e.getMessage()); + e.getMessage()); } } @Test - public void requireExceptionWithLineNumber() { + void requireExceptionWithLineNumber() { try { XmlHelper.getDocumentBuilder().parse( new InputSource(new FileReader("src/test/cfg/application/invalid-services-syntax/services.xml"))); } catch (Exception e) { assertEquals("Invalid XML (unknown source): The element type \"config\" must be terminated by the matching end-tag \"</config>\". [7:5]", - e.getMessage()); + e.getMessage()); } } diff --git a/config-model/src/test/java/com/yahoo/config/model/builder/xml/test/DomBuilderTest.java b/config-model/src/test/java/com/yahoo/config/model/builder/xml/test/DomBuilderTest.java index 393522b4e33..29a842d8945 100644 --- a/config-model/src/test/java/com/yahoo/config/model/builder/xml/test/DomBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/builder/xml/test/DomBuilderTest.java @@ -2,8 +2,8 @@ package com.yahoo.config.model.builder.xml.test; import com.yahoo.config.model.test.TestUtil; +import org.junit.jupiter.api.BeforeEach; import com.yahoo.config.model.test.MockRoot; -import org.junit.Before; import org.w3c.dom.Element; /** @@ -22,7 +22,7 @@ abstract public class DomBuilderTest { protected MockRoot root; - @Before + @BeforeEach public void setup() { root = new MockRoot(); } diff --git a/config-model/src/test/java/com/yahoo/config/model/deploy/DeployStateTest.java b/config-model/src/test/java/com/yahoo/config/model/deploy/DeployStateTest.java index 64870ff8e49..f0b729a718c 100644 --- a/config-model/src/test/java/com/yahoo/config/model/deploy/DeployStateTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/deploy/DeployStateTest.java @@ -14,7 +14,7 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.config.ConfigDefinition; import com.yahoo.vespa.config.ConfigDefinitionKey; import com.yahoo.vespa.model.VespaModel; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import java.io.File; @@ -25,9 +25,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Ulf Lilleengen @@ -35,7 +33,7 @@ import static org.junit.Assert.assertTrue; public class DeployStateTest { @Test - public void testProvisionerIsSet() { + void testProvisionerIsSet() { DeployState.Builder builder = new DeployState.Builder(); HostProvisioner provisioner = new InMemoryProvisioner(true, false, "foo.yahoo.com"); builder.modelHostProvisioner(provisioner); @@ -44,7 +42,7 @@ public class DeployStateTest { } @Test - public void testBuilder() { + void testBuilder() { DeployState.Builder builder = new DeployState.Builder(); ApplicationPackage app = MockApplicationPackage.createEmpty(); builder.permanentApplicationPackage(Optional.of(app)); @@ -53,20 +51,20 @@ public class DeployStateTest { } @Test - public void testPreviousModelIsProvided() throws IOException, SAXException { + void testPreviousModelIsProvided() throws IOException, SAXException { VespaModel prevModel = new VespaModel(MockApplicationPackage.createEmpty()); DeployState.Builder builder = new DeployState.Builder(); assertEquals(prevModel, builder.previousModel(prevModel).build().getPreviousModel().get()); } @Test - public void testProperties() { + void testProperties() { DeployState.Builder builder = new DeployState.Builder(); DeployState state = builder.build(); assertEquals(ApplicationId.defaultId(), state.getProperties().applicationId()); ApplicationId customId = new ApplicationId.Builder() - .tenant("bar") - .applicationName("foo").instanceName("quux").build(); + .tenant("bar") + .applicationName("foo").instanceName("quux").build(); ModelContext.Properties properties = new TestProperties().setApplicationId(customId); builder.properties(properties); state = builder.build(); @@ -74,11 +72,11 @@ public class DeployStateTest { } @Test - public void testDefinitionRepoIsUsed() { + void testDefinitionRepoIsUsed() { Map<ConfigDefinitionKey, com.yahoo.vespa.config.buildergen.ConfigDefinition> defs = new LinkedHashMap<>(); defs.put(new ConfigDefinitionKey("foo", "bar"), new com.yahoo.vespa.config.buildergen.ConfigDefinition("foo", new String[]{"namespace=bar", "foo int default=0"})); defs.put(new ConfigDefinitionKey("test2", "a.b"), - new com.yahoo.vespa.config.buildergen.ConfigDefinition("namespace-in-filename", new String[]{"namespace=a.b", "doubleVal double default=1.0"})); + new com.yahoo.vespa.config.buildergen.ConfigDefinition("namespace-in-filename", new String[]{"namespace=a.b", "doubleVal double default=1.0"})); ApplicationPackage app = FilesApplicationPackage.fromFile(new File("src/test/cfg//application/app1")); DeployState state = createDeployState(app, defs); @@ -91,7 +89,7 @@ public class DeployStateTest { } @Test - public void testGetConfigDefinition() { + void testGetConfigDefinition() { Map<ConfigDefinitionKey, com.yahoo.vespa.config.buildergen.ConfigDefinition> defs = new LinkedHashMap<>(); defs.put(new ConfigDefinitionKey("test2", "a.b"), new com.yahoo.vespa.config.buildergen.ConfigDefinition("test2", new String[]{"namespace=a.b", "doubleVal double default=1.0"})); //defs.put(new ConfigDefinitionKey("test2", "c.d"), new com.yahoo.vespa.config.buildergen.ConfigDefinition("test2", new String[]{"namespace=c.d", "doubleVal double default=1.0"})); @@ -108,7 +106,7 @@ public class DeployStateTest { } @Test - public void testContainerEndpoints() { + void testContainerEndpoints() { assertTrue(new DeployState.Builder().endpoints(Set.of()).build().getEndpoints().isEmpty()); var endpoints = Set.of(new ContainerEndpoint("c1", ApplicationClusterEndpoint.Scope.global, List.of("c1.example.com", "c1-alias.example.com"))); assertEquals(endpoints, new DeployState.Builder().endpoints(endpoints).build().getEndpoints()); diff --git a/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java b/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java index 70b9fc54882..a9f97d95b74 100644 --- a/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java +++ b/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java @@ -16,16 +16,13 @@ import com.yahoo.vespa.model.test.ApiConfigModel; import com.yahoo.vespa.model.test.SimpleConfigModel; import com.yahoo.vespa.model.test.SimpleService; import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Iterator; import java.util.Map; import java.util.Set; -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 bratseth @@ -53,21 +50,21 @@ public class SystemModelTestCase { } @Test - public void testMetrics() { + void testMetrics() { VespaModel vespaModel = getVespaModelDoNotValidateXml(TESTDIR + "metricsconfig"); - SimpleService service0 = (SimpleService)vespaModel.getConfigProducer("simple/simpleservice.0").get(); + SimpleService service0 = (SimpleService) vespaModel.getConfigProducer("simple/simpleservice.0").get(); vespaModel.getConfigProducer("simple/simpleservice.1"); assertEquals("testClusterName", service0.getDefaultMetricDimensions().get("clustername")); } @Test - public void testVespaModel() { + void testVespaModel() { VespaModel vespaModel = getVespaModelDoNotValidateXml(TESTDIR + "simpleconfig/"); assertNotNull(vespaModel); - assertEquals("There are two instances of the simple model + Routing and AdminModel (set up implicitly)", 4, vespaModel.configModelRepo().asMap().size()); - assertNotNull("One gets the default name as there is no explicit id", vespaModel.configModelRepo().asMap().get("simple")); - assertNotNull("The other gets the explicit id as name", vespaModel.configModelRepo().asMap().get("second")); + assertEquals(4, vespaModel.configModelRepo().asMap().size(), "There are two instances of the simple model + Routing and AdminModel (set up implicitly)"); + assertNotNull(vespaModel.configModelRepo().asMap().get("simple"), "One gets the default name as there is no explicit id"); + assertNotNull(vespaModel.configModelRepo().asMap().get("second"), "The other gets the explicit id as name"); ApplicationConfigProducerRoot root = vespaModel.getVespa(); assertNotNull(root); @@ -108,7 +105,7 @@ public class SystemModelTestCase { } @Test - public void testHostSystem() { + void testHostSystem() { VespaModel vespaModel = getVespaModelDoNotValidateXml(TESTDIR + "simpleconfig/"); HostSystem hostSystem = vespaModel.hostSystem(); @@ -129,7 +126,7 @@ public class SystemModelTestCase { } @Test - public void testBasePorts() { + void testBasePorts() { VespaModel vespaModel = getVespaModelDoNotValidateXml(TESTDIR + "simpleconfig"); assertNotNull(vespaModel); @@ -142,7 +139,7 @@ public class SystemModelTestCase { * Be sure to update it as well if you change this. */ @Test - public void testPlugins() { + void testPlugins() { VespaModel vespaModel = getVespaModelDoNotValidateXml(TESTDIR + "plugins"); assertNotNull(vespaModel); @@ -169,14 +166,14 @@ public class SystemModelTestCase { assertEquals("routing", plugin.getId()); assertEquals(vespaModel.getConfig(StandardConfig.class, "api/apiservice.0").astring(), "apiservice"); - + assertEquals(vespaModel.getConfig(StandardConfig.class, "simple/simpleservice.0").astring(), "simpleservice"); assertEquals(vespaModel.getConfig(StandardConfig.class, "simple/simpleservice.1").astring(), "simpleservice"); assertEquals(vespaModel.getConfig(StandardConfig.class, "simple2/simpleservice.0").astring(), "simpleservice"); } @Test - public void testEqualPlugins() { + void testEqualPlugins() { try { getVespaModelDoNotValidateXml(TESTDIR + "doubleconfig"); fail("No exception upon two plugins with the same name"); diff --git a/config-model/src/test/java/com/yahoo/config/model/graph/ModelGraphTest.java b/config-model/src/test/java/com/yahoo/config/model/graph/ModelGraphTest.java index da8ce7fd425..753f4b11f9f 100644 --- a/config-model/src/test/java/com/yahoo/config/model/graph/ModelGraphTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/graph/ModelGraphTest.java @@ -3,16 +3,11 @@ package com.yahoo.config.model.graph; import com.yahoo.config.model.ConfigModelContext; import com.yahoo.config.model.test.MockRoot; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author Ulf Lilleengen @@ -30,7 +25,7 @@ public class ModelGraphTest { } @Test - public void require_that_dependencies_are_correctly_set() { + void require_that_dependencies_are_correctly_set() { ModelGraphBuilder builder = new ModelGraphBuilder(); builder.addBuilder(new GraphMock.BC()).addBuilder(new GraphMock.BB()).addBuilder(new GraphMock.BA()); ModelGraph graph = builder.build(); @@ -45,22 +40,24 @@ public class ModelGraphTest { } @Test - public void require_that_dependencies_are_correctly_sorted() { + void require_that_dependencies_are_correctly_sorted() { ModelGraph graph = new ModelGraphBuilder().addBuilder(new GraphMock.BC()).addBuilder(new GraphMock.BB()).addBuilder(new GraphMock.BA()).build(); assertOrdering(graph, "ABC"); } - @Test(expected = IllegalArgumentException.class) - public void require_that_cycles_are_detected() { - ModelGraph graph = new ModelGraphBuilder().addBuilder(new GraphMock.BD()).addBuilder(new GraphMock.BE()).build(); - assertEquals(2, graph.getNodes().size()); - assertTrue(graph.getNodes().get(0).dependsOn(graph.getNodes().get(1))); - assertTrue(graph.getNodes().get(1).dependsOn(graph.getNodes().get(0))); - graph.topologicalSort(); + @Test + void require_that_cycles_are_detected() { + assertThrows(IllegalArgumentException.class, () -> { + ModelGraph graph = new ModelGraphBuilder().addBuilder(new GraphMock.BD()).addBuilder(new GraphMock.BE()).build(); + assertEquals(2, graph.getNodes().size()); + assertTrue(graph.getNodes().get(0).dependsOn(graph.getNodes().get(1))); + assertTrue(graph.getNodes().get(1).dependsOn(graph.getNodes().get(0))); + graph.topologicalSort(); + }); } @Test - public void require_that_instance_can_be_created() { + void require_that_instance_can_be_created() { ModelGraph graph = new ModelGraphBuilder().addBuilder(new GraphMock.BC()).addBuilder(new GraphMock.BB()).addBuilder(new GraphMock.BA()).build(); List<ModelNode> nodes = graph.topologicalSort(); MockRoot root = new MockRoot(); @@ -83,30 +80,28 @@ public class ModelGraphTest { assertTrue(c.b.contains(b2)); } - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test - public void require_that_context_must_be_first_ctor_param() { - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Constructor for " + GraphMock.Bad.class.getName() + " must have as its first argument a " + ConfigModelContext.class.getName()); - ModelNode node = new ModelNode(new GraphMock.Bad.Builder()); - MockRoot root = new MockRoot(); - node.createModel(ConfigModelContext.create(root.getDeployState(), null, null, root, "foo")); + void require_that_context_must_be_first_ctor_param() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + ModelNode node = new ModelNode(new GraphMock.Bad.Builder()); + MockRoot root = new MockRoot(); + node.createModel(ConfigModelContext.create(root.getDeployState(), null, null, root, "foo")); + }); + assertTrue(exception.getMessage().contains("Constructor for " + GraphMock.Bad.class.getName() + " must have as its first argument a " + ConfigModelContext.class.getName())); } @Test - public void require_that_ctor_arguments_must_be_models_or_collections_of_models() { - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Unable to find constructor argument class java.lang.String for com.yahoo.config.model.graph.GraphMock$Bad2"); - ModelNode node = new ModelNode(new GraphMock.Bad2.Builder()); - MockRoot root = new MockRoot(); - node.createModel(ConfigModelContext.create(root.getDeployState(), null, null, root, "foo")); + void require_that_ctor_arguments_must_be_models_or_collections_of_models() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + ModelNode node = new ModelNode(new GraphMock.Bad2.Builder()); + MockRoot root = new MockRoot(); + node.createModel(ConfigModelContext.create(root.getDeployState(), null, null, root, "foo")); + }); + assertTrue(exception.getMessage().contains("Unable to find constructor argument class java.lang.String for com.yahoo.config.model.graph.GraphMock$Bad2")); } @Test - public void require_that_collections_can_be_empty() { + void require_that_collections_can_be_empty() { ModelGraph graph = new ModelGraphBuilder().addBuilder(new GraphMock.BC()).addBuilder(new GraphMock.BA()).build(); List<ModelNode> nodes = graph.topologicalSort(); MockRoot root = new MockRoot(); diff --git a/config-model/src/test/java/com/yahoo/config/model/producer/AbstractConfigProducerTest.java b/config-model/src/test/java/com/yahoo/config/model/producer/AbstractConfigProducerTest.java index 04ae4c76f27..763b9c25072 100644 --- a/config-model/src/test/java/com/yahoo/config/model/producer/AbstractConfigProducerTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/producer/AbstractConfigProducerTest.java @@ -2,10 +2,10 @@ package com.yahoo.config.model.producer; import com.yahoo.cloud.config.log.LogdConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Verifies some of the logic in the abstract config producer that is not tested in other classes. @@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals; public class AbstractConfigProducerTest { @Test - public void require_that_interface_is_found_if_directly_implemented() throws ReflectiveOperationException { + void require_that_interface_is_found_if_directly_implemented() throws ReflectiveOperationException { MockLogdProducer producer = new MockLogdProducer("mocky"); ClassLoader loader = producer.getConfigClassLoader(LogdConfig.Producer.class.getName()); assertNotNull(loader); @@ -29,7 +29,7 @@ public class AbstractConfigProducerTest { } @Test - public void require_that_interface_is_found_if_inherited() throws ReflectiveOperationException { + void require_that_interface_is_found_if_inherited() throws ReflectiveOperationException { MockLogdProducerSubclass producer = new MockLogdProducerSubclass("mocky"); ClassLoader loader = producer.getConfigClassLoader(LogdConfig.Producer.class.getName()); assertNotNull(loader); diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/HostSpecTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/HostSpecTest.java index 810e2c643f3..e678aaa673a 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/HostSpecTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/HostSpecTest.java @@ -2,15 +2,15 @@ package com.yahoo.config.model.provision; import com.yahoo.config.provision.HostSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * @author Ulf Lilleengen @@ -18,31 +18,31 @@ import static org.junit.Assert.assertTrue; public class HostSpecTest { @Test - public void testEquals() { + void testEquals() { HostSpec h1 = new HostSpec("foo", List.of(), Optional.empty()); HostSpec h2 = new HostSpec("foo", List.of(), Optional.empty()); HostSpec h3 = new HostSpec("foo", List.of("my", "alias"), Optional.empty()); HostSpec h4 = new HostSpec("bar", List.of(), Optional.empty()); - assertTrue(h1.equals(h1)); - assertTrue(h1.equals(h2)); - assertTrue(h1.equals(h3)); - assertFalse(h1.equals(h4)); - - assertTrue(h2.equals(h1)); - assertTrue(h2.equals(h2)); - assertTrue(h2.equals(h3)); - assertFalse(h2.equals(h4)); - - assertTrue(h3.equals(h1)); - assertTrue(h3.equals(h2)); - assertTrue(h3.equals(h3)); - assertFalse(h3.equals(h4)); - - assertFalse(h4.equals(h1)); - assertFalse(h4.equals(h2)); - assertFalse(h4.equals(h3)); - assertTrue(h4.equals(h4)); + assertEquals(h1, h1); + assertEquals(h1, h2); + assertEquals(h1, h3); + assertNotEquals(h1, h4); + + assertEquals(h2, h1); + assertEquals(h2, h2); + assertEquals(h2, h3); + assertNotEquals(h2, h4); + + assertEquals(h3, h1); + assertEquals(h3, h2); + assertEquals(h3, h3); + assertNotEquals(h3, h4); + + assertNotEquals(h4, h1); + assertNotEquals(h4, h2); + assertNotEquals(h4, h3); + assertEquals(h4, h4); } } diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java index 558e61fc1c2..9721e85c71d 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/HostsXmlProvisionerTest.java @@ -3,7 +3,7 @@ package com.yahoo.config.model.provision; import com.yahoo.config.provision.HostSpec; import com.yahoo.vespa.model.container.Container; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.StringReader; import java.util.ArrayList; @@ -15,8 +15,7 @@ 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.*; /** * @author hmusum @@ -46,7 +45,7 @@ public class HostsXmlProvisionerTest { "</hosts>"; @Test - public void require_basic_works() { + void require_basic_works() { HostsXmlProvisioner hostProvisioner = createProvisioner(threeHosts); // 4 services, 2 host aliases, mapping to 2 host. @@ -71,14 +70,16 @@ public class HostsXmlProvisionerTest { assertEquals(3, map.size()); assertCorrectNumberOfHosts(map, 3); assertTrue(map.keySet().containsAll(aliases)); - + assertEquals("", System.getProperty("zookeeper.vespa.clients")); } - @Test(expected = IllegalArgumentException.class) - public void require_exception_when_unknown_hosts_alias() { - HostsXmlProvisioner hostProvisioner = createProvisioner(oneHost); - hostProvisioner.allocateHost("unknown"); + @Test + void require_exception_when_unknown_hosts_alias() { + assertThrows(IllegalArgumentException.class, () -> { + HostsXmlProvisioner hostProvisioner = createProvisioner(oneHost); + hostProvisioner.allocateHost("unknown"); + }); } private void assertCorrectNumberOfHosts(Map<String, HostSpec> hostToServiceMap, int expectedHostCount) { @@ -117,7 +118,7 @@ public class HostsXmlProvisionerTest { } @Test - public void require_singlenode_HostAlias_is_used_if_hosts_xml() { + void require_singlenode_HostAlias_is_used_if_hosts_xml() { HostsXmlProvisioner hostProvisioner = createProvisioner(oneHost); HostSpec hostSpec = hostProvisioner.allocateHost(Container.SINGLENODE_CONTAINER_SERVICESPEC); assertEquals("test1.yahoo.com", hostSpec.hostname()); diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java index 03ab4f46c60..30b848da7f1 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java @@ -38,7 +38,8 @@ import com.yahoo.vespa.model.search.SearchNode; import com.yahoo.vespa.model.test.VespaModelTester; import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; import com.yahoo.yolean.Exceptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; + import java.io.StringReader; import java.util.ArrayList; import java.util.List; @@ -57,12 +58,13 @@ import static com.yahoo.vespa.defaults.Defaults.getDefaults; import static com.yahoo.vespa.model.search.NodeResourcesTuning.GB; import static com.yahoo.vespa.model.search.NodeResourcesTuning.reservedMemoryGb; import static com.yahoo.vespa.model.test.utils.ApplicationPackageUtils.generateSchemas; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test cases for provisioning nodes to entire Vespa models. @@ -219,10 +221,10 @@ public class ModelProvisioningTest { tester.addHosts(8); VespaModel model = tester.createModel(xmlWithNodes, true); - assertEquals("Nodes in content1", 2, model.getContentClusters().get("content1").getRootGroup().getNodes().size()); - assertEquals("Nodes in container1", 1, model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Nodes in cluster without ID", 2, model.getContentClusters().get("content").getRootGroup().getNodes().size()); - assertEquals("Heap size for container", 70, physicalMemoryPercentage(model.getContainerClusters().get("container1"))); + assertEquals(2, model.getContentClusters().get("content1").getRootGroup().getNodes().size(), "Nodes in content1"); + assertEquals(1, model.getContainerClusters().get("container1").getContainers().size(), "Nodes in container1"); + assertEquals(2, model.getContentClusters().get("content").getRootGroup().getNodes().size(), "Nodes in cluster without ID"); + assertEquals(70, physicalMemoryPercentage(model.getContainerClusters().get("container1")), "Heap size for container"); assertProvisioned(2, ClusterSpec.Id.from("content1"), ClusterSpec.Type.content, model); assertProvisioned(1, ClusterSpec.Id.from("container1"), ClusterSpec.Type.container, model); assertProvisioned(2, ClusterSpec.Id.from("content"), ClusterSpec.Type.content, model); @@ -272,13 +274,11 @@ public class ModelProvisioningTest { tester.addHosts(5); TestLogger logger = new TestLogger(); VespaModel model = tester.createModel(xmlWithNodes, true, new DeployState.Builder().deployLogger(logger)); - assertEquals("Nodes in content1", 2, model.getContentClusters().get("content1").getRootGroup().getNodes().size()); - assertEquals("Nodes in container1", 2, model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Heap size is lowered with combined clusters", - 18, physicalMemoryPercentage(model.getContainerClusters().get("container1"))); - assertEquals("Memory for proton is lowered to account for the jvm heap", - (long) ((3 - reservedMemoryGb) * (Math.pow(1024, 3)) * (1 - 0.18)), protonMemorySize(model.getContentClusters() - .get("content1"))); + assertEquals(2, model.getContentClusters().get("content1").getRootGroup().getNodes().size(), "Nodes in content1"); + assertEquals(2, model.getContainerClusters().get("container1").getContainers().size(), "Nodes in container1"); + assertEquals(18, physicalMemoryPercentage(model.getContainerClusters().get("container1")), "Heap size is lowered with combined clusters"); + assertEquals((long) ((3 - reservedMemoryGb) * (Math.pow(1024, 3)) * (1 - 0.18)), protonMemorySize(model.getContentClusters() + .get("content1")), "Memory for proton is lowered to account for the jvm heap"); assertProvisioned(0, ClusterSpec.Id.from("container1"), ClusterSpec.Type.container, model); assertProvisioned(2, ClusterSpec.Id.from("content1"), ClusterSpec.Id.from("container1"), ClusterSpec.Type.combined, model); assertEquals(1, logger.msgs().size()); @@ -311,13 +311,11 @@ public class ModelProvisioningTest { VespaModelTester tester = new VespaModelTester(); tester.addHosts(5); VespaModel model = tester.createModel(xmlWithNodes, true); - assertEquals("Nodes in content1", 2, model.getContentClusters().get("content1").getRootGroup().getNodes().size()); - assertEquals("Nodes in container1", 2, model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Heap size is lowered with combined clusters", - 30, physicalMemoryPercentage(model.getContainerClusters().get("container1"))); - assertEquals("Memory for proton is lowered to account for the jvm heap", - (long) ((3 - reservedMemoryGb) * (Math.pow(1024, 3)) * (1 - 0.30)), protonMemorySize(model.getContentClusters() - .get("content1"))); + assertEquals(2, model.getContentClusters().get("content1").getRootGroup().getNodes().size(), "Nodes in content1"); + assertEquals(2, model.getContainerClusters().get("container1").getContainers().size(), "Nodes in container1"); + assertEquals(30, physicalMemoryPercentage(model.getContainerClusters().get("container1")), "Heap size is lowered with combined clusters"); + assertEquals((long) ((3 - reservedMemoryGb) * (Math.pow(1024, 3)) * (1 - 0.30)), protonMemorySize(model.getContentClusters() + .get("content1")), "Memory for proton is lowered to account for the jvm heap"); assertProvisioned(0, ClusterSpec.Id.from("container1"), ClusterSpec.Type.container, model); assertProvisioned(2, ClusterSpec.Id.from("content1"), ClusterSpec.Id.from("container1"), ClusterSpec.Type.combined, model); } @@ -345,12 +343,10 @@ public class ModelProvisioningTest { VespaModelTester tester = new VespaModelTester(); tester.addHosts(7); VespaModel model = tester.createModel(xmlWithNodes, true); - assertEquals("Nodes in content1", 2, model.getContentClusters().get("content1").getRootGroup().getNodes().size()); - assertEquals("Nodes in container1", 2, model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Heap size is normal", - 70, physicalMemoryPercentage(model.getContainerClusters().get("container1"))); - assertEquals("Memory for proton is normal", - (long) ((3 - reservedMemoryGb) * (Math.pow(1024, 3))), protonMemorySize(model.getContentClusters().get("content1"))); + assertEquals(2, model.getContentClusters().get("content1").getRootGroup().getNodes().size(), "Nodes in content1"); + assertEquals(2, model.getContainerClusters().get("container1").getContainers().size(), "Nodes in container1"); + assertEquals(70, physicalMemoryPercentage(model.getContainerClusters().get("container1")), "Heap size is normal"); + assertEquals((long) ((3 - reservedMemoryGb) * (Math.pow(1024, 3))), protonMemorySize(model.getContentClusters().get("content1")), "Memory for proton is normal"); } @Test @@ -376,8 +372,8 @@ public class ModelProvisioningTest { tester.addHosts(5); VespaModel model = tester.createModel(xmlWithNodes, true); - assertEquals("Nodes in content1", 2, model.getContentClusters().get("content1").getRootGroup().getNodes().size()); - assertEquals("Nodes in container1", 2, model.getContainerClusters().get("container1").getContainers().size()); + assertEquals(2, model.getContentClusters().get("content1").getRootGroup().getNodes().size(), "Nodes in content1"); + assertEquals(2, model.getContainerClusters().get("container1").getContainers().size(), "Nodes in container1"); for (Container container : model.getContainerClusters().get("container1").getContainers()) assertTrue(container.getJvmOptions().contains("testoption")); } @@ -412,10 +408,10 @@ public class ModelProvisioningTest { tester.addHosts(8); VespaModel model = tester.createModel(xmlWithNodes, true); - assertEquals("Nodes in content1", 2, model.getContentClusters().get("content1").getRootGroup().getNodes().size()); - assertEquals("Nodes in container1", 2, model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Nodes in content2", 3, model.getContentClusters().get("content2").getRootGroup().getNodes().size()); - assertEquals("Nodes in container2", 3, model.getContainerClusters().get("container2").getContainers().size()); + assertEquals(2, model.getContentClusters().get("content1").getRootGroup().getNodes().size(), "Nodes in content1"); + assertEquals(2, model.getContainerClusters().get("container1").getContainers().size(), "Nodes in container1"); + assertEquals(3, model.getContentClusters().get("content2").getRootGroup().getNodes().size(), "Nodes in content2"); + assertEquals(3, model.getContainerClusters().get("container2").getContainers().size(), "Nodes in container2"); } @Test @@ -535,10 +531,10 @@ public class ModelProvisioningTest { .stream().map(cc -> cc.getHostResource()).collect(Collectors.toSet()); Set<HostResource> slobrokHosts = admin.getSlobroks().stream().map(Slobrok::getHost).collect(Collectors.toSet()); assertEquals(3, slobrokHosts.size()); - assertTrue("Slobroks are assigned on cluster controller nodes", clusterControllerHosts.containsAll(slobrokHosts)); - assertTrue("Logserver is assigned from container nodes", containerHosts.contains(admin.getLogserver().getHost())); - assertEquals("No in-cluster config servers in a hosted environment", 0, admin.getConfigservers().size()); - assertEquals("Dedicated admin cluster controllers when hosted", 3, admin.getClusterControllers().getContainers().size()); + assertTrue(clusterControllerHosts.containsAll(slobrokHosts), "Slobroks are assigned on cluster controller nodes"); + assertTrue(containerHosts.contains(admin.getLogserver().getHost()), "Logserver is assigned from container nodes"); + assertEquals(0, admin.getConfigservers().size(), "No in-cluster config servers in a hosted environment"); + assertEquals(3, admin.getClusterControllers().getContainers().size(), "Dedicated admin cluster controllers when hosted"); // Check content clusters ContentCluster cluster = model.getContentClusters().get("bar"); @@ -626,10 +622,10 @@ public class ModelProvisioningTest { Admin admin = model.getAdmin(); Set<HostResource> slobrokHosts = admin.getSlobroks().stream().map(Slobrok::getHost).collect(Collectors.toSet()); assertEquals(3, slobrokHosts.size()); - assertTrue("Slobroks are assigned from container nodes", - containerHosts.containsAll(slobrokHosts)); - assertTrue("Logserver is assigned from container nodes", containerHosts.contains(admin.getLogserver().getHost())); - assertEquals("No in-cluster config servers in a hosted environment", 0, admin.getConfigservers().size()); + assertTrue(containerHosts.containsAll(slobrokHosts), + "Slobroks are assigned from container nodes"); + assertTrue(containerHosts.contains(admin.getLogserver().getHost()), "Logserver is assigned from container nodes"); + assertEquals(0, admin.getConfigservers().size(), "No in-cluster config servers in a hosted environment"); } @Test @@ -676,9 +672,9 @@ public class ModelProvisioningTest { .stream().map(cc -> cc.getHostResource()).collect(Collectors.toSet()); Set<HostResource> slobrokHosts = admin.getSlobroks().stream().map(Slobrok::getHost).collect(Collectors.toSet()); assertEquals(3, slobrokHosts.size()); - assertTrue("Slobroks are assigned on cluster controller nodes", clusterControllerHosts.containsAll(slobrokHosts)); - assertTrue("Logserver is assigned from container nodes", containerHosts.contains(admin.getLogserver().getHost())); - assertEquals("No in-cluster config servers in a hosted environment", 0, admin.getConfigservers().size()); + assertTrue(clusterControllerHosts.containsAll(slobrokHosts), "Slobroks are assigned on cluster controller nodes"); + assertTrue(containerHosts.contains(admin.getLogserver().getHost()), "Logserver is assigned from container nodes"); + assertEquals(0, admin.getConfigservers().size(), "No in-cluster config servers in a hosted environment"); assertEquals(3, admin.getClusterControllers().getContainers().size()); // Check content clusters @@ -814,11 +810,11 @@ public class ModelProvisioningTest { assertEquals(numberOfHosts, model.getRoot().hostSystem().getHosts().size()); // Check slobroks clusters - assertEquals("Includes retired node", 1+3, model.getAdmin().getSlobroks().size()); + assertEquals(1+3, model.getAdmin().getSlobroks().size(), "Includes retired node"); assertEquals("node-1-3-50-11", model.getAdmin().getSlobroks().get(0).getHostName()); assertEquals("node-1-3-50-10", model.getAdmin().getSlobroks().get(1).getHostName()); assertEquals("node-1-3-50-08", model.getAdmin().getSlobroks().get(2).getHostName()); - assertEquals("Included in addition because it is retired", "node-1-3-50-09", model.getAdmin().getSlobroks().get(3).getHostName()); + assertEquals("node-1-3-50-09", model.getAdmin().getSlobroks().get(3).getHostName(), "Included in addition because it is retired"); } @Test @@ -839,12 +835,12 @@ public class ModelProvisioningTest { assertEquals(10+2, model.getRoot().hostSystem().getHosts().size()); // Check slobroks clusters - assertEquals("Includes retired node", 3+2, model.getAdmin().getSlobroks().size()); + assertEquals(3+2, model.getAdmin().getSlobroks().size(), "Includes retired node"); assertEquals("node-1-3-50-12", model.getAdmin().getSlobroks().get(0).getHostName()); assertEquals("node-1-3-50-11", model.getAdmin().getSlobroks().get(1).getHostName()); assertEquals("node-1-3-50-10", model.getAdmin().getSlobroks().get(2).getHostName()); - assertEquals("Included in addition because it is retired", "node-1-3-50-04", model.getAdmin().getSlobroks().get(3).getHostName()); - assertEquals("Included in addition because it is retired", "node-1-3-50-03", model.getAdmin().getSlobroks().get(4).getHostName()); + assertEquals("node-1-3-50-04", model.getAdmin().getSlobroks().get(3).getHostName(), "Included in addition because it is retired"); + assertEquals("node-1-3-50-03", model.getAdmin().getSlobroks().get(4).getHostName(), "Included in addition because it is retired"); } @Test @@ -869,14 +865,14 @@ public class ModelProvisioningTest { // Check slobroks clusters // ... from cluster default - assertEquals("Includes retired node", 7, model.getAdmin().getSlobroks().size()); + assertEquals(7, model.getAdmin().getSlobroks().size(), "Includes retired node"); assertEquals("node-1-3-50-16", model.getAdmin().getSlobroks().get(0).getHostName()); assertEquals("node-1-3-50-14", model.getAdmin().getSlobroks().get(1).getHostName()); - assertEquals("Included in addition because it is retired", "node-1-3-50-15", model.getAdmin().getSlobroks().get(2).getHostName()); + assertEquals("node-1-3-50-15", model.getAdmin().getSlobroks().get(2).getHostName(), "Included in addition because it is retired"); // ... from cluster bar assertEquals("node-1-3-50-03", model.getAdmin().getSlobroks().get(3).getHostName()); - assertEquals("Included in addition because it is retired", "node-1-3-50-05", model.getAdmin().getSlobroks().get(5).getHostName()); - assertEquals("Included in addition because it is retired", "node-1-3-50-04", model.getAdmin().getSlobroks().get(6).getHostName()); + assertEquals("node-1-3-50-05", model.getAdmin().getSlobroks().get(5).getHostName(), "Included in addition because it is retired"); + assertEquals("node-1-3-50-04", model.getAdmin().getSlobroks().get(6).getHostName(), "Included in addition because it is retired"); } @Test @@ -1255,44 +1251,48 @@ public class ModelProvisioningTest { assertEquals("bar/storage/0", cluster.getRootGroup().getNodes().get(0).getConfigId()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRequiringMoreNodesThanAreAvailable() { - String services = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<services>" + - " <content version='1.0' id='bar'>" + - " <redundancy>1</redundancy>" + - " <documents>" + - " <document type='type1' mode='index'/>" + - " </documents>" + - " <nodes count='3' required='true'/>" + - " </content>" + - "</services>"; - - int numberOfHosts = 2; - VespaModelTester tester = new VespaModelTester(); - tester.addHosts(numberOfHosts); - tester.createModel(services, false); + assertThrows(IllegalArgumentException.class, () -> { + String services = + "<?xml version='1.0' encoding='utf-8' ?>\n" + + "<services>" + + " <content version='1.0' id='bar'>" + + " <redundancy>1</redundancy>" + + " <documents>" + + " <document type='type1' mode='index'/>" + + " </documents>" + + " <nodes count='3' required='true'/>" + + " </content>" + + "</services>"; + + int numberOfHosts = 2; + VespaModelTester tester = new VespaModelTester(); + tester.addHosts(numberOfHosts); + tester.createModel(services, false); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testRequiredNodesAndDedicatedClusterControllers() { - String services = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<services>" + - " <content version='1.0' id='foo'>" + - " <redundancy>1</redundancy>" + - " <documents>" + - " <document type='type1' mode='index'/>" + - " </documents>" + - " <nodes count='2' required='true'/>" + - " </content>" + - "</services>"; - - int numberOfHosts = 4; // needs 2 for foo and 3 for cluster controllers. - VespaModelTester tester = new VespaModelTester(); - tester.addHosts(numberOfHosts); - tester.createModel(services, false); + assertThrows(IllegalArgumentException.class, () -> { + String services = + "<?xml version='1.0' encoding='utf-8' ?>\n" + + "<services>" + + " <content version='1.0' id='foo'>" + + " <redundancy>1</redundancy>" + + " <documents>" + + " <document type='type1' mode='index'/>" + + " </documents>" + + " <nodes count='2' required='true'/>" + + " </content>" + + "</services>"; + + int numberOfHosts = 4; // needs 2 for foo and 3 for cluster controllers. + VespaModelTester tester = new VespaModelTester(); + tester.addHosts(numberOfHosts); + tester.createModel(services, false); + }); } @Test @@ -1654,7 +1654,7 @@ public class ModelProvisioningTest { tester.setHosted(true); tester.addHosts(4); VespaModel model = tester.createModel(new Zone(Environment.dev, RegionName.from("us-central-1")), services, true); - assertEquals("We get 1 node per cluster and no admin node apart from the dedicated cluster controller", 3, model.getHosts().size()); + assertEquals(3, model.getHosts().size(), "We get 1 node per cluster and no admin node apart from the dedicated cluster controller"); assertEquals(1, model.getContainerClusters().size()); assertEquals(1, model.getContainerClusters().get("foo").getContainers().size()); assertEquals(1, model.getContentClusters().get("bar").getRootGroup().countNodes(true)); @@ -1715,10 +1715,12 @@ public class ModelProvisioningTest { tester.addHosts(3); VespaModel model = tester.createModel(services, true); - assertEquals("Nodes in container cluster", 1, - model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Nodes in content cluster (downscaled)", 1, - model.getContentClusters().get("content").getRootGroup().getNodes().size()); + assertEquals(1, + model.getContainerClusters().get("container1").getContainers().size(), + "Nodes in container cluster"); + assertEquals(1, + model.getContentClusters().get("content").getRootGroup().getNodes().size(), + "Nodes in content cluster (downscaled)"); assertEquals(1, model.getAdmin().getSlobroks().size()); @@ -1771,10 +1773,12 @@ public class ModelProvisioningTest { tester.addHosts(3); VespaModel model = tester.createModel(services, hosts, true); - assertEquals("Nodes in container cluster", 1, - model.getContainerClusters().get("container1").getContainers().size()); - assertEquals("Nodes in content cluster (downscaled)", 1, - model.getContentClusters().get("content").getRootGroup().getNodes().size()); + assertEquals(1, + model.getContainerClusters().get("container1").getContainers().size(), + "Nodes in container cluster"); + assertEquals(1, + model.getContentClusters().get("content").getRootGroup().getNodes().size(), + "Nodes in content cluster (downscaled)"); assertEquals(1, model.getAdmin().getSlobroks().size()); @@ -2111,10 +2115,10 @@ public class ModelProvisioningTest { .collect(Collectors.groupingBy(h -> h.spec().membership().get().cluster().id().value())); tests.forEach((clusterId, stateful) -> { List<HostResource> hosts = hostsByCluster.getOrDefault(clusterId, List.of()); - assertFalse("Hosts are provisioned for '" + clusterId + "'", hosts.isEmpty()); - assertEquals("Hosts in cluster '" + clusterId + "' are " + (stateful ? "" : "not ") + "stateful", - stateful, - hosts.stream().allMatch(h -> h.spec().membership().get().cluster().isStateful())); + assertFalse(hosts.isEmpty(), "Hosts are provisioned for '" + clusterId + "'"); + assertEquals(stateful, + hosts.stream().allMatch(h -> h.spec().membership().get().cluster().isStateful()), + "Hosts in cluster '" + clusterId + "' are " + (stateful ? "" : "not ") + "stateful"); }); } @@ -2156,7 +2160,7 @@ public class ModelProvisioningTest { ZookeeperServerConfig.Builder config = new ZookeeperServerConfig.Builder(); cluster.getContainers().forEach(c -> c.getConfig(config)); cluster.getConfig(config); - assertTrue("Initial servers are not joining", config.build().server().stream().noneMatch(ZookeeperServerConfig.Server::joining)); + assertTrue(config.build().server().stream().noneMatch(ZookeeperServerConfig.Server::joining), "Initial servers are not joining"); } { VespaModel nextModel = tester.createModel(Zone.defaultZone(), servicesXml.apply(3), true, false, false, 0, Optional.of(model), new DeployState.Builder(), "node-1-3-50-04", "node-1-3-50-03"); @@ -2164,22 +2168,22 @@ public class ModelProvisioningTest { ZookeeperServerConfig.Builder config = new ZookeeperServerConfig.Builder(); cluster.getContainers().forEach(c -> c.getConfig(config)); cluster.getConfig(config); - assertEquals("New nodes are joining", - Map.of(0, false, + assertEquals(Map.of(0, false, 1, false, 2, false, 3, true, 4, true), config.build().server().stream().collect(Collectors.toMap(ZookeeperServerConfig.Server::id, - ZookeeperServerConfig.Server::joining))); - assertEquals("Retired nodes are retired", - Map.of(0, false, + ZookeeperServerConfig.Server::joining)), + "New nodes are joining"); + assertEquals(Map.of(0, false, 1, true, 2, true, 3, false, 4, false), config.build().server().stream().collect(Collectors.toMap(ZookeeperServerConfig.Server::id, - ZookeeperServerConfig.Server::retired))); + ZookeeperServerConfig.Server::retired)), + "Retired nodes are retired"); } } @@ -2322,11 +2326,12 @@ public class ModelProvisioningTest { private static void assertProvisioned(int nodeCount, ClusterSpec.Id id, ClusterSpec.Id combinedId, ClusterSpec.Type type, VespaModel model) { - assertEquals("Nodes in cluster " + id + " with type " + type + (combinedId != null ? ", combinedId " + combinedId : ""), nodeCount, + assertEquals(nodeCount, model.hostSystem().getHosts().stream() .map(h -> h.spec().membership().get().cluster()) .filter(spec -> spec.id().equals(id) && spec.type().equals(type) && spec.combinedId().equals(Optional.ofNullable(combinedId))) - .count()); + .count(), + "Nodes in cluster " + id + " with type " + type + (combinedId != null ? ", combinedId " + combinedId : "")); } private static void assertProvisioned(int nodeCount, ClusterSpec.Id id, ClusterSpec.Type type, VespaModel model) { diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java index 446350a734f..00acc715a39 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/SingleNodeProvisionerTest.java @@ -6,7 +6,7 @@ import com.yahoo.config.model.api.HostProvisioner; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.HostSpec; import com.yahoo.vespa.model.VespaModel; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import java.io.IOException; @@ -21,7 +21,7 @@ import java.util.Set; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author hmusum @@ -29,7 +29,7 @@ import static org.junit.Assert.assertTrue; public class SingleNodeProvisionerTest { @Test - public void require_basic_works() { + void require_basic_works() { SingleNodeProvisioner hostProvisioner = new SingleNodeProvisioner(); // 4 services, 2 host aliases, mapping to 2 host. @@ -56,16 +56,16 @@ public class SingleNodeProvisionerTest { } @Test - public void require_allocate_clustermembership_works() throws IOException, SAXException { + void require_allocate_clustermembership_works() throws IOException, SAXException { String servicesXml = "<services version='1.0'>" - + " <admin version='3.0'>" - + " <nodes count='1' />" - + " </admin>" - + " <container version='1.0'>" - + " <search />" - + " <nodes count='1' />" - + " </container>" - + "</services>"; + + " <admin version='3.0'>" + + " <nodes count='1' />" + + " </admin>" + + " <container version='1.0'>" + + " <search />" + + " <nodes count='1' />" + + " </container>" + + "</services>"; ApplicationPackage app = new MockApplicationPackage.Builder().withServices(servicesXml).build(); VespaModel model = new VespaModel(app); assertThat(model.getHosts().size(), is(1)); |