diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java index 5b08d24afbfda..757a5d41444bf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/ServiceTestUtils.java @@ -51,8 +51,9 @@ import org.apache.hadoop.yarn.service.utils.SliderFileSystem; import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin; import org.apache.hadoop.yarn.util.ProcfsBasedProcessTree; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -393,17 +394,22 @@ protected CuratorService getCuratorService() throws IOException { * Watcher to initialize yarn service base path under target and deletes the * the test directory when finishes. */ - public static class ServiceFSWatcher extends TestWatcher { + public static class ServiceFSWatcher implements BeforeEachCallback, AfterEachCallback { private YarnConfiguration conf; private SliderFileSystem fs; private java.nio.file.Path serviceBasePath; @Override - protected void starting(Description description) { + public void afterEach(ExtensionContext context) throws Exception { + delete(context); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { conf = new YarnConfiguration(); - delete(description); + delete(context); serviceBasePath = Paths.get("target", - description.getClassName(), description.getMethodName()); + getClassName(context), getMethodName(context)); conf.set(YARN_SERVICE_BASE_PATH, serviceBasePath.toString()); try { Files.createDirectories(serviceBasePath); @@ -415,14 +421,17 @@ protected void starting(Description description) { } } - @Override - protected void finished(Description description) { - delete(description); + private void delete(ExtensionContext context) { + FileUtils.deleteQuietly(Paths.get("target", getClassName(context)).toFile()); + } + + private String getClassName(ExtensionContext context) { + Class requiredTestClass = context.getRequiredTestClass(); + return requiredTestClass.getName(); } - private void delete(Description description) { - FileUtils.deleteQuietly(Paths.get("target", - description.getClassName()).toFile()); + private String getMethodName(ExtensionContext context) { + return context.getTestMethod().get().getName(); } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java index 012f204239bdb..e72250594b148 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java @@ -22,12 +22,12 @@ import org.apache.hadoop.yarn.service.api.records.ConfigFile; import org.apache.hadoop.yarn.service.api.records.Configuration; import org.apache.hadoop.yarn.service.api.records.Service; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link UpgradeComponentsFinder.DefaultUpgradeComponentsFinder}. @@ -44,9 +44,9 @@ public void testServiceArtifactChange() { targetDef.getComponents().forEach(x -> x.setArtifact( TestServiceManager.createTestArtifact("v1"))); - assertEquals("all components need upgrade", - targetDef.getComponents(), finder.findTargetComponentSpecs(currentDef, - targetDef)); + assertEquals(targetDef.getComponents(), + finder.findTargetComponentSpecs(currentDef, + targetDef), "all components need upgrade"); } @Test @@ -60,7 +60,7 @@ public void testServiceUpgradeWithNewComponentAddition() { try { finder.findTargetComponentSpecs(currentDef, targetDef); - Assert.fail("Expected error since component does not exist in service " + fail("Expected error since component does not exist in service " + "definition"); } catch (UnsupportedOperationException usoe) { assertEquals( @@ -83,9 +83,8 @@ public void testComponentArtifactChange() { List expected = new ArrayList<>(); expected.add(targetDef.getComponents().get(0)); - assertEquals("single components needs upgrade", - expected, finder.findTargetComponentSpecs(currentDef, - targetDef)); + assertEquals(expected, finder.findTargetComponentSpecs(currentDef, + targetDef), "single components needs upgrade"); } @Test @@ -117,7 +116,7 @@ public void testChangeInConfigFileProperty() { List expected = new ArrayList<>(); expected.addAll(targetDef.getComponents()); - assertEquals("all components needs upgrade", - expected, finder.findTargetComponentSpecs(currentDef, targetDef)); + assertEquals(expected, finder.findTargetComponentSpecs(currentDef, targetDef), + "all components needs upgrade"); } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceAM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceAM.java index 69c0c2cee57f9..3902c0ba6dabe 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceAM.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceAM.java @@ -51,11 +51,11 @@ import org.apache.hadoop.yarn.service.conf.YarnServiceConf; import org.apache.hadoop.yarn.util.DockerClientConfigHandler; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,7 +71,9 @@ import java.util.concurrent.TimeoutException; import static org.apache.hadoop.registry.client.api.RegistryConstants.KEY_REGISTRY_ZK_QUORUM; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -83,11 +85,11 @@ public class TestServiceAM extends ServiceTestUtils{ private File basedir; YarnConfiguration conf = new YarnConfiguration(); TestingCluster zkCluster; - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); - @Before + @BeforeEach public void setup() throws Exception { basedir = new File("target", "apps"); if (basedir.exists()) { @@ -101,7 +103,7 @@ public void setup() throws Exception { LOG.info("ZK cluster: {}", zkCluster.getConnectString()); } - @After + @AfterEach public void tearDown() throws IOException { if (basedir != null) { FileUtils.deleteDirectory(basedir); @@ -147,15 +149,15 @@ public void testContainerCompleted() throws TimeoutException, am.waitForCompInstanceState(compa0, ComponentInstanceState.INIT); // still 1 pending instance - Assert.assertEquals(1, - am.getComponent("compa").getPendingInstances().size()); + assertEquals(1, am.getComponent("compa").getPendingInstances().size()); am.stop(); } // Test to verify that the containers of previous attempt are not prematurely // released. These containers are sent by the RM to the AM in the // heartbeat response. - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testContainersFromPreviousAttemptsWithRMRestart() throws Exception { ApplicationId applicationId = ApplicationId.newInstance( @@ -182,23 +184,23 @@ public void testContainersFromPreviousAttemptsWithRMRestart() am.waitForCompInstanceState(comp10, ComponentInstanceState.STARTED); // 0 pending instance - Assert.assertEquals(0, + assertEquals(0, am.getComponent(comp1Name).getPendingInstances().size()); GenericTestUtils.waitFor(() -> am.getCompInstance(comp1Name, comp1InstName) .getContainerStatus() != null, 2000, 200000); - Assert.assertEquals("container state", - org.apache.hadoop.yarn.api.records.ContainerState.RUNNING, + assertEquals(org.apache.hadoop.yarn.api.records.ContainerState.RUNNING, am.getCompInstance(comp1Name, comp1InstName).getContainerStatus() - .getState()); + .getState(), "container state"); am.stop(); } // Test to verify that the containers of previous attempt are released and the // component instance is added to the pending queue when the recovery wait // time interval elapses. - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testContainersReleasedWhenExpired() throws Exception { ApplicationId applicationId = ApplicationId.newInstance( @@ -225,22 +227,22 @@ public void testContainersReleasedWhenExpired() .equals(ComponentState.FLEXING), 100, 2000); // 1 pending instance - Assert.assertEquals(1, am.getComponent(comp1Name).getPendingInstances() + assertEquals(1, am.getComponent(comp1Name).getPendingInstances() .size()); am.feedContainerToComp(exampleApp, 2, comp1Name); GenericTestUtils.waitFor(() -> am.getCompInstance(comp1Name, comp1InstName) .getContainerStatus() != null, 2000, 200000); - Assert.assertEquals("container state", - org.apache.hadoop.yarn.api.records.ContainerState.RUNNING, + assertEquals(org.apache.hadoop.yarn.api.records.ContainerState.RUNNING, am.getCompInstance(comp1Name, comp1InstName).getContainerStatus() - .getState()); + .getState(), "container state"); } // Test to verify that the AM doesn't wait for containers of a different app // even though it corresponds to the same service. - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testContainersFromDifferentApp() throws Exception { ApplicationId applicationId = ApplicationId.newInstance( @@ -268,17 +270,16 @@ public void testContainersFromDifferentApp() am.start(); // 1 pending instance since the container in registry belongs to a different // app. - Assert.assertEquals(1, + assertEquals(1, am.getComponent(comp1Name).getPendingInstances().size()); am.feedContainerToComp(exampleApp, 1, comp1Name); GenericTestUtils.waitFor(() -> am.getCompInstance(comp1Name, comp1InstName) .getContainerStatus() != null, 2000, 200000); - Assert.assertEquals("container state", - org.apache.hadoop.yarn.api.records.ContainerState.RUNNING, + assertEquals(org.apache.hadoop.yarn.api.records.ContainerState.RUNNING, am.getCompInstance(comp1Name, comp1InstName).getContainerStatus() - .getState()); + .getState(), "container state"); am.stop(); } @@ -314,13 +315,12 @@ public void testScheduleWithMultipleResourceTypes() Collection rr = amrmClientAsync.getMatchingRequests(0); - Assert.assertEquals(1, rr.size()); + assertEquals(1, rr.size()); org.apache.hadoop.yarn.api.records.Resource capability = rr.iterator().next().getCapability(); - Assert.assertEquals(3333L, capability.getResourceValue("resource-1")); - Assert.assertEquals("Gi", - capability.getResourceInformation("resource-1").getUnits()); + assertEquals(3333L, capability.getResourceValue("resource-1")); + assertEquals("Gi", capability.getResourceInformation("resource-1").getUnits()); am.stop(); } @@ -432,8 +432,7 @@ public void testRecordTokensForContainers() throws Exception { assertEquals(2, amCreds.numberOfTokens()); for (Token tk : amCreds.getAllTokens()) { - Assert.assertTrue( - tk.getKind().equals(DockerCredentialTokenIdentifier.KIND)); + assertTrue(tk.getKind().equals(DockerCredentialTokenIdentifier.KIND)); } am.stop(); @@ -463,7 +462,7 @@ public void testIPChange() throws TimeoutException, GenericTestUtils.waitFor(() -> comp1inst0.getContainerStatus() != null, 2000, 200000); // first host status will match the container nodeId - Assert.assertEquals("localhost", + assertEquals("localhost", comp1inst0.getContainerStatus().getHost()); LOG.info("Change the IP and host"); @@ -491,7 +490,8 @@ public void testIPChange() throws TimeoutException, In case the id is set to null or unset so it is effectively null, Path.checkPathArg throws an IllegalArgumentException. **/ - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testContainersReleasedWhenPreLaunchFails() throws Exception { ApplicationId applicationId = ApplicationId.newInstance( @@ -522,12 +522,12 @@ public void testContainersReleasedWhenPreLaunchFails() am.getComponent(compA.getName()).getPendingInstances() .contains(compAinst0), 2000, 30000); - Assert.assertEquals(1, - am.getComponent("compa").getPendingInstances().size()); + assertEquals(1, am.getComponent("compa").getPendingInstances().size()); am.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testSyncSysFS() { ApplicationId applicationId = ApplicationId.newInstance( System.currentTimeMillis(), 1); @@ -554,7 +554,7 @@ public void testSyncSysFS() { am.close(); } catch (Exception e) { LOG.error("Fail to sync sysfs.", e); - Assert.fail("Fail to sync sysfs."); + fail("Fail to sync sysfs."); } } @@ -593,14 +593,14 @@ public void testScheduleWithResourceAttributes() throws Exception { Collection rr = amrmClientAsync.getMatchingRequests(0); - Assert.assertEquals(1, rr.size()); + assertEquals(1, rr.size()); org.apache.hadoop.yarn.api.records.Resource capability = rr.iterator().next().getCapability(); - Assert.assertEquals(1234L, capability.getResourceValue("test-resource")); - Assert.assertEquals("Gi", + assertEquals(1234L, capability.getResourceValue("test-resource")); + assertEquals("Gi", capability.getResourceInformation("test-resource").getUnits()); - Assert.assertEquals(2, capability.getResourceInformation("test-resource") + assertEquals(2, capability.getResourceInformation("test-resource") .getAttributes().size()); am.stop(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceManager.java index 1d8ccff4f6fda..a388b6f45201c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestServiceManager.java @@ -32,33 +32,40 @@ import org.apache.hadoop.yarn.service.component.instance.ComponentInstanceEventType; import org.apache.hadoop.yarn.service.exceptions.SliderException; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.RegisterExtension; import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.concurrent.TimeoutException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * Tests for {@link ServiceManager}. */ public class TestServiceManager { - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); - @Test (timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testUpgrade() throws Exception { ServiceContext context = createServiceContext("testUpgrade"); initUpgrade(context, "v2", false, false, false); - Assert.assertEquals("service not upgraded", ServiceState.UPGRADING, - context.getServiceManager().getServiceSpec().getState()); + assertEquals(ServiceState.UPGRADING, + context.getServiceManager().getServiceSpec().getState(), "service not upgraded"); } - @Test (timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testRestartNothingToUpgrade() throws Exception { ServiceContext context = createServiceContext( @@ -73,11 +80,12 @@ public void testRestartNothingToUpgrade() GenericTestUtils.waitFor(()-> context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service not re-started", ServiceState.STABLE, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, + manager.getServiceSpec().getState(), "service not re-started"); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testAutoFinalizeNothingToUpgrade() throws Exception { ServiceContext context = createServiceContext( "testAutoFinalizeNothingToUpgrade"); @@ -89,11 +97,12 @@ public void testAutoFinalizeNothingToUpgrade() throws Exception { GenericTestUtils.waitFor(()-> context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service stable", ServiceState.STABLE, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, + manager.getServiceSpec().getState(), "service stable"); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testRestartWithPendingUpgrade() throws Exception { ServiceContext context = createServiceContext("testRestart"); @@ -103,17 +112,18 @@ public void testRestartWithPendingUpgrade() context.scheduler.getDispatcher().getEventHandler().handle( new ServiceEvent(ServiceEventType.START)); context.scheduler.getDispatcher().stop(); - Assert.assertEquals("service should still be upgrading", - ServiceState.UPGRADING, manager.getServiceSpec().getState()); + assertEquals(ServiceState.UPGRADING, + manager.getServiceSpec().getState(), "service should still be upgrading"); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testFinalize() throws Exception { ServiceContext context = createServiceContext("testCheckState"); initUpgrade(context, "v2", true, false, false); ServiceManager manager = context.getServiceManager(); - Assert.assertEquals("service not upgrading", ServiceState.UPGRADING, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.UPGRADING, + manager.getServiceSpec().getState(), "service not upgrading"); //make components stable by upgrading all instances upgradeAndReadyAllInstances(context); @@ -124,13 +134,14 @@ public void testFinalize() throws Exception { GenericTestUtils.waitFor(()-> context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service not re-started", ServiceState.STABLE, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, + manager.getServiceSpec().getState(), "service not re-started"); validateUpgradeFinalization(manager.getName(), "v2"); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testAutoFinalize() throws Exception { ServiceContext context = createServiceContext("testCheckStateAutoFinalize"); ServiceManager manager = context.getServiceManager(); @@ -144,8 +155,8 @@ public void testAutoFinalize() throws Exception { GenericTestUtils.waitFor(() -> context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service not stable", - ServiceState.STABLE, manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, + manager.getServiceSpec().getState(), "service not stable"); validateUpgradeFinalization(manager.getName(), "v2"); } @@ -165,13 +176,14 @@ public void testInvalidUpgrade() throws Exception { try { manager.processUpgradeRequest("v2", true, false); } catch (Exception ex) { - Assert.assertTrue(ex instanceof UnsupportedOperationException); + assertTrue(ex instanceof UnsupportedOperationException); return; } - Assert.fail(); + fail(); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testExpressUpgrade() throws Exception { ServiceContext context = createServiceContext("testExpressUpgrade"); ServiceManager manager = context.getServiceManager(); @@ -191,19 +203,20 @@ public void testExpressUpgrade() throws Exception { context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service not stable", - ServiceState.STABLE, manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, manager.getServiceSpec().getState(), + "service not stable"); validateUpgradeFinalization(manager.getName(), "v2"); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testCancelUpgrade() throws Exception { ServiceContext context = createServiceContext("testCancelUpgrade"); writeInitialDef(context.service); initUpgrade(context, "v2", true, false, false); ServiceManager manager = context.getServiceManager(); - Assert.assertEquals("service not upgrading", ServiceState.UPGRADING, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.UPGRADING, + manager.getServiceSpec().getState(), "service not upgrading"); List comps = ServiceApiUtil.resolveCompsDependency(context.service); // wait till instances of first component are upgraded and ready @@ -220,20 +233,21 @@ public void testCancelUpgrade() throws Exception { GenericTestUtils.waitFor(()-> context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service upgrade not cancelled", ServiceState.STABLE, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, + manager.getServiceSpec().getState(), "service upgrade not cancelled"); validateUpgradeFinalization(manager.getName(), "v1"); } - @Test(timeout = TIMEOUT) + @Test + @Timeout(value = TIMEOUT) public void testCancelUpgradeAfterInitiate() throws Exception { ServiceContext context = createServiceContext("testCancelUpgrade"); writeInitialDef(context.service); initUpgrade(context, "v2", true, false, false); ServiceManager manager = context.getServiceManager(); - Assert.assertEquals("service not upgrading", ServiceState.UPGRADING, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.UPGRADING, + manager.getServiceSpec().getState(), "service not upgrading"); // cancel upgrade context.scheduler.getDispatcher().getEventHandler().handle( @@ -241,8 +255,8 @@ public void testCancelUpgradeAfterInitiate() throws Exception { GenericTestUtils.waitFor(()-> context.service.getState().equals(ServiceState.STABLE), CHECK_EVERY_MILLIS, TIMEOUT); - Assert.assertEquals("service upgrade not cancelled", ServiceState.STABLE, - manager.getServiceSpec().getState()); + assertEquals(ServiceState.STABLE, + manager.getServiceSpec().getState(), "service upgrade not cancelled"); validateUpgradeFinalization(manager.getName(), "v1"); } @@ -250,14 +264,14 @@ public void testCancelUpgradeAfterInitiate() throws Exception { private void validateUpgradeFinalization(String serviceName, String expectedVersion) throws IOException { Service savedSpec = ServiceApiUtil.loadService(rule.getFs(), serviceName); - Assert.assertEquals("service def not re-written", expectedVersion, - savedSpec.getVersion()); - Assert.assertNotNull("app id not present", savedSpec.getId()); - Assert.assertEquals("state not stable", ServiceState.STABLE, - savedSpec.getState()); + assertEquals(expectedVersion, + savedSpec.getVersion(), "service def not re-written"); + assertNotNull(savedSpec.getId(), "app id not present"); + assertEquals(ServiceState.STABLE, + savedSpec.getState(), "state not stable"); savedSpec.getComponents().forEach(compSpec -> - Assert.assertEquals("comp not stable", ComponentState.STABLE, - compSpec.getState())); + assertEquals(ComponentState.STABLE, + compSpec.getState(), "comp not stable")); } private void initUpgrade(ServiceContext context, String version, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java index 56aca5c89ab61..75985f5c8441d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java @@ -49,13 +49,10 @@ import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.apache.hadoop.yarn.service.utils.SliderFileSystem; -import org.hamcrest.CoreMatchers; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,6 +64,11 @@ import java.util.concurrent.TimeoutException; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.apache.hadoop.yarn.api.records.YarnApplicationState.FINISHED; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.*; import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_COMMAND_ARGUMENT_ERROR; @@ -81,16 +83,13 @@ public class TestYarnNativeServices extends ServiceTestUtils { private static final Logger LOG = LoggerFactory.getLogger(TestYarnNativeServices.class); - @Rule - public TemporaryFolder tmpFolder = new TemporaryFolder(); - - @Before + @BeforeEach public void setup() throws Exception { File tmpYarnDir = new File("target", "tmp"); FileUtils.deleteQuietly(tmpYarnDir); } - @After + @AfterEach public void tearDown() throws IOException { shutdown(); } @@ -102,7 +101,8 @@ public void tearDown() throws IOException { // 4. Flex up each component to 2 containers and check the component instance names // 5. Stop the service // 6. Destroy the service - @Test (timeout = 200000) + @Test + @Timeout(value = 200) public void testCreateFlexStopDestroyService() throws Exception { setupInternal(NUM_NMS); ServiceClient client = createClient(getConf()); @@ -111,7 +111,7 @@ public void testCreateFlexStopDestroyService() throws Exception { SliderFileSystem fileSystem = new SliderFileSystem(getConf()); Path appDir = fileSystem.buildClusterDirPath(exampleApp.getName()); // check app.json is persisted. - Assert.assertTrue( + assertTrue( getFS().exists(new Path(appDir, exampleApp.getName() + ".json"))); waitForServiceToBeStable(client, exampleApp); @@ -140,35 +140,36 @@ public void testCreateFlexStopDestroyService() throws Exception { ApplicationReport report = client.getYarnClient() .getApplicationReport(ApplicationId.fromString(exampleApp.getId())); // AM unregisters with RM successfully - Assert.assertEquals(FINISHED, report.getYarnApplicationState()); - Assert.assertEquals(FinalApplicationStatus.ENDED, + assertEquals(FINISHED, report.getYarnApplicationState()); + assertEquals(FinalApplicationStatus.ENDED, report.getFinalApplicationStatus()); String serviceZKPath = RegistryUtils.servicePath(RegistryUtils .currentUser(), YarnServiceConstants.APP_TYPE, exampleApp.getName()); - Assert.assertFalse("Registry ZK service path still exists after stop", - getCuratorService().zkPathExists(serviceZKPath)); + assertFalse(getCuratorService().zkPathExists(serviceZKPath), + "Registry ZK service path still exists after stop"); LOG.info("Destroy the service"); // destroy the service and check the app dir is deleted from fs. - Assert.assertEquals(0, client.actionDestroy(exampleApp.getName())); + assertEquals(0, client.actionDestroy(exampleApp.getName())); // check the service dir on hdfs (in this case, local fs) are deleted. - Assert.assertFalse(getFS().exists(appDir)); + assertFalse(getFS().exists(appDir)); // check that destroying again does not succeed - Assert.assertEquals(EXIT_NOT_FOUND, client.actionDestroy(exampleApp.getName())); + assertEquals(EXIT_NOT_FOUND, client.actionDestroy(exampleApp.getName())); } // Save a service without starting it and ensure that stop does not NPE and // that service can be successfully destroyed - @Test (timeout = 200000) + @Test + @Timeout(value = 200) public void testStopDestroySavedService() throws Exception { setupInternal(NUM_NMS); ServiceClient client = createClient(getConf()); Service exampleApp = createExampleApplication(); client.actionBuild(exampleApp); - Assert.assertEquals(EXIT_COMMAND_ARGUMENT_ERROR, client.actionStop( + assertEquals(EXIT_COMMAND_ARGUMENT_ERROR, client.actionStop( exampleApp.getName())); - Assert.assertEquals(0, client.actionDestroy(exampleApp.getName())); + assertEquals(0, client.actionDestroy(exampleApp.getName())); } // Create compa with 2 containers @@ -176,7 +177,8 @@ public void testStopDestroySavedService() throws Exception { // Create compc with 2 containers which depends on compb // Check containers for compa started before containers for compb before // containers for compc - @Test (timeout = 200000) + @Test + @Timeout(value = 200) public void testComponentStartOrder() throws Exception { setupInternal(NUM_NMS); ServiceClient client = createClient(getConf()); @@ -206,7 +208,8 @@ public void testComponentStartOrder() throws Exception { client.actionDestroy(exampleApp.getName()); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testCreateServiceSameNameDifferentUser() throws Exception { String sameAppName = "same-name"; String userA = "usera"; @@ -239,8 +242,7 @@ public void testCreateServiceSameNameDifferentUser() throws Exception { getConf().set(YARN_SERVICE_BASE_PATH, userBBasePath.getAbsolutePath()); client.actionBuild(userBApp); } catch (Exception e) { - Assert - .fail("Exception should not be thrown - " + e.getLocalizedMessage()); + fail("Exception should not be thrown - " + e.getLocalizedMessage()); } finally { if (userABasePath != null) { getConf().set(YARN_SERVICE_BASE_PATH, userABasePath.getAbsolutePath()); @@ -258,7 +260,8 @@ public void testCreateServiceSameNameDifferentUser() throws Exception { // Need to test create followed by create. } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testCreateServiceSameNameSameUser() throws Exception { String sameAppName = "same-name"; String user = UserGroupInformation.getCurrentUser().getUserName(); @@ -283,10 +286,9 @@ public void testCreateServiceSameNameSameUser() throws Exception { } catch (Exception e) { String expectedMsg = "Service Instance dir already exists:"; if (e.getLocalizedMessage() != null) { - Assert.assertThat(e.getLocalizedMessage(), - CoreMatchers.containsString(expectedMsg)); + assertThat(e.getLocalizedMessage()).contains(expectedMsg); } else { - Assert.fail("Message cannot be null. It has to say - " + expectedMsg); + fail("Message cannot be null. It has to say - " + expectedMsg); } } finally { // cleanup @@ -303,10 +305,9 @@ public void testCreateServiceSameNameSameUser() throws Exception { String expectedMsg = "Failed to create service " + sameAppName + ", because it already exists."; if (e.getLocalizedMessage() != null) { - Assert.assertThat(e.getLocalizedMessage(), - CoreMatchers.containsString(expectedMsg)); + assertThat(e.getLocalizedMessage()).contains(expectedMsg); } else { - Assert.fail("Message cannot be null. It has to say - " + expectedMsg); + fail("Message cannot be null. It has to say - " + expectedMsg); } } finally { // cleanup @@ -320,7 +321,8 @@ public void testCreateServiceSameNameSameUser() throws Exception { // 2. Restart RM. // 3. Fail the application attempt. // 4. Verify ServiceMaster recovers. - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testRecoverComponentsAfterRMRestart() throws Exception { YarnConfiguration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true); @@ -348,8 +350,8 @@ public void testRecoverComponentsAfterRMRestart() throws Exception { GenericTestUtils.waitFor(() -> getYarnCluster().getResourceManager().getServiceState() == org.apache.hadoop.service.Service.STATE.STARTED, 2000, 200000); - Assert.assertTrue("node managers connected", - getYarnCluster().waitForNodeManagersToConnect(5000)); + assertTrue(getYarnCluster().waitForNodeManagersToConnect(5000), + "node managers connected"); ApplicationId exampleAppId = ApplicationId.fromString(exampleApp.getId()); ApplicationAttemptId applicationAttemptId = client.getYarnClient() @@ -372,10 +374,10 @@ public void testRecoverComponentsAfterRMRestart() throws Exception { Multimap containersAfterFailure = waitForAllCompToBeReady( client, exampleApp); containersBeforeFailure.keys().forEach(compName -> { - Assert.assertEquals("num containers after by restart for " + compName, - containersBeforeFailure.get(compName).size(), + assertEquals(containersBeforeFailure.get(compName).size(), containersAfterFailure.get(compName) == null ? 0 : - containersAfterFailure.get(compName).size()); + containersAfterFailure.get(compName).size(), + "num containers after by restart for " + compName); }); LOG.info("Stop/destroy service {}", exampleApp); @@ -383,7 +385,8 @@ public void testRecoverComponentsAfterRMRestart() throws Exception { client.actionDestroy(exampleApp.getName()); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testUpgrade() throws Exception { setupInternal(NUM_NMS); getConf().setBoolean(YARN_SERVICE_UPGRADE_ENABLED, true); @@ -405,8 +408,8 @@ public void testUpgrade() throws Exception { SliderFileSystem fs = new SliderFileSystem(getConf()); Service fromFs = ServiceApiUtil.loadServiceUpgrade(fs, service.getName(), service.getVersion()); - Assert.assertEquals(service.getName(), fromFs.getName()); - Assert.assertEquals(service.getVersion(), fromFs.getVersion()); + assertEquals(service.getName(), fromFs.getName()); + assertEquals(service.getVersion(), fromFs.getVersion()); // upgrade containers Service liveService = client.getStatus(service.getName()); @@ -418,17 +421,17 @@ public void testUpgrade() throws Exception { client.actionStart(service.getName()); waitForServiceToBeStable(client, service); Service active = client.getStatus(service.getName()); - Assert.assertEquals("component not stable", ComponentState.STABLE, - active.getComponent(component.getName()).getState()); - Assert.assertEquals("comp does not have new env", "val1", - active.getComponent(component.getName()).getConfiguration() - .getEnv("key1")); + assertEquals(ComponentState.STABLE, + active.getComponent(component.getName()).getState(), "component not stable"); + assertEquals("val1", active.getComponent(component.getName()).getConfiguration() + .getEnv("key1"), "comp does not have new env"); LOG.info("Stop/destroy service {}", service); client.actionStop(service.getName(), true); client.actionDestroy(service.getName()); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testExpressUpgrade() throws Exception { setupInternal(NUM_NMS); getConf().setBoolean(YARN_SERVICE_UPGRADE_ENABLED, true); @@ -452,22 +455,21 @@ public void testExpressUpgrade() throws Exception { // wait for upgrade to complete waitForServiceToBeStable(client, service); Service active = client.getStatus(service.getName()); - Assert.assertEquals("version mismatch", service.getVersion(), - active.getVersion()); - Assert.assertEquals("component not stable", ComponentState.STABLE, - active.getComponent(component.getName()).getState()); - Assert.assertEquals("compa does not have new env", "val1", - active.getComponent(component.getName()).getConfiguration() - .getEnv("key1")); - Assert.assertEquals("compb does not have new env", "val2", - active.getComponent(component2.getName()).getConfiguration() - .getEnv("key2")); + assertEquals(service.getVersion(), + active.getVersion(), "version mismatch"); + assertEquals(ComponentState.STABLE, + active.getComponent(component.getName()).getState(), "component not stable"); + assertEquals("val1", active.getComponent(component.getName()).getConfiguration() + .getEnv("key1"), "compa does not have new env"); + assertEquals("val2", active.getComponent(component2.getName()).getConfiguration() + .getEnv("key2"), "compb does not have new env"); LOG.info("Stop/destroy service {}", service); client.actionStop(service.getName(), true); client.actionDestroy(service.getName()); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testCancelUpgrade() throws Exception { setupInternal(NUM_NMS); getConf().setBoolean(YARN_SERVICE_UPGRADE_ENABLED, true); @@ -500,11 +502,11 @@ public void testCancelUpgrade() throws Exception { client.actionCancelUpgrade(service.getName()); waitForServiceToBeStable(client, service); Service active = client.getStatus(service.getName()); - Assert.assertEquals("component not stable", ComponentState.STABLE, - active.getComponent(component.getName()).getState()); - Assert.assertEquals("comp does not have new env", "val0", + assertEquals(ComponentState.STABLE, + active.getComponent(component.getName()).getState(), "component not stable"); + assertEquals("val0", active.getComponent(component.getName()).getConfiguration() - .getEnv("key1")); + .getEnv("key1"), "comp does not have new env"); LOG.info("Stop/destroy service {}", service); client.actionStop(service.getName(), true); client.actionDestroy(service.getName()); @@ -518,7 +520,8 @@ public void testCancelUpgrade() throws Exception { // 4. Flex the component to 4 containers // 5. Verify that the 4th container does not even get allocated since there // are only 3 NMs - @Test (timeout = 200000) + @Test + @Timeout(value = 200) public void testCreateServiceWithPlacementPolicy() throws Exception { // We need to enable scheduler placement-constraint at the cluster level to // let apps use placement policies. @@ -549,10 +552,10 @@ public void testCreateServiceWithPlacementPolicy() throws Exception { // Check service is stable and all 3 containers are running Service service = client.getStatus(exampleApp.getName()); Component component = service.getComponent("compa"); - Assert.assertEquals("Service state should be STABLE", ServiceState.STABLE, - service.getState()); - Assert.assertEquals("3 containers are expected to be running", 3, - component.getContainers().size()); + assertEquals(ServiceState.STABLE, + service.getState(), "Service state should be STABLE"); + assertEquals(3, + component.getContainers().size(), "3 containers are expected to be running"); // Prepare a map of non-AM containers for later lookup Set nonAMContainerIdSet = new HashSet<>(); for (Container cont : component.getContainers()) { @@ -573,7 +576,7 @@ public void testCreateServiceWithPlacementPolicy() throws Exception { continue; } if (hosts.contains(contReport.getNodeHttpAddress())) { - Assert.fail("Container " + contReport.getContainerId() + fail("Container " + contReport.getContainerId() + " came up in the same host as another container."); } else { hosts.add(contReport.getNodeHttpAddress()); @@ -590,19 +593,19 @@ public void testCreateServiceWithPlacementPolicy() throws Exception { // this test is that it has to wait that long. Setting a higher wait time // will add to the total time taken by tests to run. waitForServiceToBeStable(client, exampleApp, 10000); - Assert.fail("Service should not be in a stable state. It should throw " + fail("Service should not be in a stable state. It should throw " + "a timeout exception."); } catch (Exception e) { // Check that service state is not STABLE and only 3 containers are // running and the fourth one should not get allocated. service = client.getStatus(exampleApp.getName()); component = service.getComponent("compa"); - Assert.assertNotEquals("Service state should not be STABLE", - ServiceState.STABLE, service.getState()); - Assert.assertEquals("Component state should be FLEXING", - ComponentState.FLEXING, component.getState()); - Assert.assertEquals("3 containers are expected to be running", 3, - component.getContainers().size()); + assertNotEquals(ServiceState.STABLE, service.getState(), + "Service state should not be STABLE"); + assertEquals(ComponentState.FLEXING, component.getState(), + "Component state should be FLEXING"); + assertEquals(3, component.getContainers().size(), + "3 containers are expected to be running"); } // Flex compa down to 4 now, which is still more containers than the no of @@ -619,19 +622,19 @@ public void testCreateServiceWithPlacementPolicy() throws Exception { // this test is that it has to wait that long. Setting a higher wait time // will add to the total time taken by tests to run. waitForServiceToBeStable(client, exampleApp, 10000); - Assert.fail("Service should not be in a stable state. It should throw " + fail("Service should not be in a stable state. It should throw " + "a timeout exception."); } catch (Exception e) { // Check that service state is not STABLE and only 3 containers are // running and the fourth one should not get allocated. service = client.getStatus(exampleApp.getName()); component = service.getComponent("compa"); - Assert.assertNotEquals("Service state should not be STABLE", - ServiceState.STABLE, service.getState()); - Assert.assertEquals("Component state should be FLEXING", - ComponentState.FLEXING, component.getState()); - Assert.assertEquals("3 containers are expected to be running", 3, - component.getContainers().size()); + assertNotEquals(ServiceState.STABLE, service.getState(), + "Service state should not be STABLE"); + assertEquals(ComponentState.FLEXING, component.getState(), + "Component state should be FLEXING"); + assertEquals(3, component.getContainers().size(), + "3 containers are expected to be running"); } // Finally flex compa down to 3, which is exactly the number of containers @@ -648,12 +651,14 @@ public void testCreateServiceWithPlacementPolicy() throws Exception { client.actionDestroy(exampleApp.getName()); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testAMSigtermDoesNotKillApplication() throws Exception { runAMSignalTest(SignalContainerCommand.GRACEFUL_SHUTDOWN); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testAMSigkillDoesNotKillApplication() throws Exception { runAMSignalTest(SignalContainerCommand.FORCEFUL_SHUTDOWN); } @@ -685,7 +690,7 @@ public void runAMSignalTest(SignalContainerCommand signal) throws Exception { ApplicationReport ar = client.getYarnClient() .getApplicationReport(exampleAppId); YarnApplicationState state = ar.getYarnApplicationState(); - Assert.assertTrue(state == YarnApplicationState.RUNNING || + assertTrue(state == YarnApplicationState.RUNNING || state == YarnApplicationState.ACCEPTED); if (state != YarnApplicationState.RUNNING) { return false; @@ -698,7 +703,7 @@ public void runAMSignalTest(SignalContainerCommand signal) throws Exception { if (appStatus2.getState() != ServiceState.STABLE) { return false; } - Assert.assertEquals(getSortedContainerIds(appStatus1).toString(), + assertEquals(getSortedContainerIds(appStatus1).toString(), getSortedContainerIds(appStatus2).toString()); return true; } catch (YarnException | IOException e) { @@ -729,7 +734,8 @@ private static List getSortedContainerIds(Service s) { // threshold the service will continue to run beyond the window of 3 secs. // 4. Flex the component to 5 containers. This makes health = 60%, so based on // threshold the service will be stopped after the window of 3 secs. - @Test (timeout = 200000) + @Test + @Timeout(value = 200) public void testComponentHealthThresholdMonitor() throws Exception { // We need to enable scheduler placement-constraint at the cluster level to // let apps use placement policies. @@ -772,10 +778,10 @@ public void testComponentHealthThresholdMonitor() throws Exception { // Check service is stable and all 3 containers are running Service service = client.getStatus(exampleApp.getName()); Component component = service.getComponent("compa"); - Assert.assertEquals("Service state should be STABLE", ServiceState.STABLE, - service.getState()); - Assert.assertEquals("3 containers are expected to be running", 3, - component.getContainers().size()); + assertEquals(ServiceState.STABLE, + service.getState(), "Service state should be STABLE"); + assertEquals(3, component.getContainers().size(), + "3 containers are expected to be running"); // Flex compa up to 4 - will make health 75% (3 out of 4 running), but still // above threshold of 65%, so service will continue to run. @@ -790,18 +796,18 @@ public void testComponentHealthThresholdMonitor() throws Exception { // the timeout the service should continue to run since health is 75% // which is above the threshold of 65%. waitForServiceToBeStable(client, exampleApp, 6000); - Assert.fail("Service should not be in a stable state. It should throw " + fail("Service should not be in a stable state. It should throw " + "a timeout exception."); } catch (Exception e) { // Check that service state is STARTED and only 3 containers are running service = client.getStatus(exampleApp.getName()); component = service.getComponent("compa"); - Assert.assertEquals("Service state should be STARTED", - ServiceState.STARTED, service.getState()); - Assert.assertEquals("Component state should be FLEXING", - ComponentState.FLEXING, component.getState()); - Assert.assertEquals("3 containers are expected to be running", 3, - component.getContainers().size()); + assertEquals(ServiceState.STARTED, service.getState(), + "Service state should be STARTED"); + assertEquals(ComponentState.FLEXING, component.getState(), + "Component state should be FLEXING"); + assertEquals(3, component.getContainers().size(), + "3 containers are expected to be running"); } // Flex compa up to 5 - will make health 60% (3 out of 5 running), so @@ -817,7 +823,7 @@ public void testComponentHealthThresholdMonitor() throws Exception { waitForServiceToBeInState(client, exampleApp, ServiceState.FAILED, 14000); } catch (Exception e) { - Assert.fail("Should not have thrown exception"); + fail("Should not have thrown exception"); } LOG.info("Destroy service {}", exampleApp); @@ -848,7 +854,7 @@ private void checkContainerLaunchDependencies(ServiceClient client, String compInstanceName = containerList.get(index).getComponentInstanceName(); String compName = compInstanceName.substring(0, compInstanceName.lastIndexOf('-')); - Assert.assertEquals(comp, compName); + assertEquals(comp, compName); index++; } } @@ -922,7 +928,8 @@ private void checkEachCompInstancesInOrder(Component component, String } } - @Test (timeout = 200000) + @Test + @Timeout(value = 200) public void testRestartServiceForNonExistingInRM() throws Exception { YarnConfiguration conf = new YarnConfiguration(); conf.setInt(YarnConfiguration.RM_MAX_COMPLETED_APPLICATIONS, 0); @@ -940,11 +947,12 @@ public void testRestartServiceForNonExistingInRM() throws Exception { client.actionStart(exampleApp.getName()); waitForServiceToBeStable(client, exampleApp); Service service = client.getStatus(exampleApp.getName()); - Assert.assertEquals("Restarted service state should be STABLE", - ServiceState.STABLE, service.getState()); + assertEquals(ServiceState.STABLE, service.getState(), + "Restarted service state should be STABLE"); } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testAMFailureValidity() throws Exception { setupInternal(NUM_NMS); ServiceClient client = createClient(getConf()); @@ -972,7 +980,7 @@ public void testAMFailureValidity() throws Exception { yarnClient.signalToContainer(attemptReport.getAMContainerId(), SignalContainerCommand.GRACEFUL_SHUTDOWN); waitForServiceToBeStable(client, exampleApp); - Assert.assertEquals(ServiceState.STABLE, client.getStatus( + assertEquals(ServiceState.STABLE, client.getStatus( exampleApp.getName()).getState()); // kill AM2 after 'yarn.service.am-failure.validity-interval-ms' @@ -983,7 +991,7 @@ public void testAMFailureValidity() throws Exception { yarnClient.signalToContainer(attemptReport.getAMContainerId(), SignalContainerCommand.GRACEFUL_SHUTDOWN); waitForServiceToBeStable(client, exampleApp); - Assert.assertEquals(ServiceState.STABLE, client.getStatus( + assertEquals(ServiceState.STABLE, client.getStatus( exampleApp.getName()).getState()); } @@ -1003,22 +1011,23 @@ public Service createServiceWithSingleComp(int memory){ return service; } - @Test(timeout = 200000) + @Test + @Timeout(value = 200) public void testServiceSameNameWithFailure() throws Exception{ setupInternal(NUM_NMS); ServiceClient client = createClient(getConf()); try { client.actionCreate(createServiceWithSingleComp(1024000)); - Assert.fail("Service should throw YarnException as memory is " + + fail("Service should throw YarnException as memory is " + "configured as 1000GB, which is more than allowed"); } catch (YarnException e) { - Assert.assertTrue(true); + assertTrue(true); } Service service = createServiceWithSingleComp(128); try { client.actionCreate(service); } catch (SliderException e){ - Assert.fail("Not able to submit service as the files related to" + + fail("Not able to submit service as the files related to" + " failed service with same name are not cleared"); } waitForServiceToBeStable(client,service); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestBuildExternalComponents.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestBuildExternalComponents.java index 6d5bb205cb120..c04ff693f639f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestBuildExternalComponents.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestBuildExternalComponents.java @@ -25,10 +25,9 @@ import org.apache.hadoop.yarn.service.conf.ExampleAppJson; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.apache.hadoop.yarn.service.utils.SliderFileSystem; -import org.junit.After; -import org.junit.Assert; -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.File; import java.io.IOException; @@ -37,6 +36,8 @@ import java.util.Set; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.YARN_SERVICE_BASE_PATH; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test for building / resolving components of type SERVICE. @@ -49,9 +50,9 @@ public class TestBuildExternalComponents { // Check component names match with expected private static void checkComponentNames(List components, Set expectedComponents) { - Assert.assertEquals(expectedComponents.size(), components.size()); + assertEquals(expectedComponents.size(), components.size()); for (Component comp : components) { - Assert.assertTrue(expectedComponents.contains(comp.getName())); + assertTrue(expectedComponents.contains(comp.getName())); } } @@ -70,7 +71,7 @@ private void buildAndCheckComponents(String appName, String appDef, checkComponentNames(components, names); } - @Before + @BeforeEach public void setup() throws IOException { basedir = new File("target", "apps"); if (basedir.exists()) { @@ -81,7 +82,7 @@ public void setup() throws IOException { conf.set(YARN_SERVICE_BASE_PATH, basedir.getAbsolutePath()); } - @After + @AfterEach public void tearDown() throws IOException { if (basedir != null) { FileUtils.deleteDirectory(basedir); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java index f75c0afdbebb6..fb0c528e11e0c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceCLI.java @@ -34,12 +34,11 @@ import org.apache.hadoop.yarn.service.conf.YarnServiceConstants; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.apache.hadoop.yarn.service.utils.SliderFileSystem; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,20 +50,21 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.spy; import static org.apache.hadoop.yarn.client.api.AppAdminClient.YARN_APP_ADMIN_CLIENT_PREFIX; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.DEPENDENCY_TARBALL_PATH; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf.YARN_SERVICE_BASE_PATH; import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_SUCCESS; import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_UNAUTHORIZED; -import static org.mockito.Mockito.spy; public class TestServiceCLI { private static final Logger LOG = LoggerFactory.getLogger(TestServiceCLI .class); - @Rule - public TemporaryFolder tmpFolder = new TemporaryFolder(); - private Configuration conf = new YarnConfiguration(); private SliderFileSystem fs; private ApplicationCLI cli; @@ -97,7 +97,7 @@ private void buildApp(String serviceName, String appDef) throws Throwable { "-D", basedirProp, "-save", serviceName, ExampleAppJson.resourceName(appDef), "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_SUCCESS, runCLI(args)); + assertEquals(EXIT_SUCCESS, runCLI(args)); } private void buildApp(String serviceName, String appDef, @@ -108,7 +108,7 @@ private void buildApp(String serviceName, String appDef, "-appTypes", DUMMY_APP_TYPE, "-updateLifetime", lifetime, "-changeQueue", queue}; - Assert.assertEquals(EXIT_SUCCESS, runCLI(args)); + assertEquals(EXIT_SUCCESS, runCLI(args)); } private static Path getDependencyTarGz(File dir) { @@ -117,13 +117,13 @@ private static Path getDependencyTarGz(File dir) { .DEPENDENCY_TAR_GZ_FILE_EXT).getAbsolutePath()); } - @Before - public void setup() throws Throwable { + @BeforeEach + public void setup(@TempDir java.nio.file.Path tempDir) throws Throwable { basedir = new File("target", "apps"); basedirProp = YARN_SERVICE_BASE_PATH + "=" + basedir.getAbsolutePath(); conf.set(YARN_SERVICE_BASE_PATH, basedir.getAbsolutePath()); fs = new SliderFileSystem(conf); - dependencyTarGzBaseDir = tmpFolder.getRoot(); + dependencyTarGzBaseDir = tempDir.toFile(); fs.getFileSystem() .setPermission(new Path(dependencyTarGzBaseDir.getAbsolutePath()), new FsPermission("755")); @@ -145,7 +145,7 @@ public void setup() throws Throwable { createCLI(); } - @After + @AfterEach public void tearDown() throws IOException { if (basedir != null) { FileUtils.deleteDirectory(basedir); @@ -153,7 +153,8 @@ public void tearDown() throws IOException { cli.stop(); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testFlexComponents() throws Throwable { // currently can only test building apps, since that is the only // operation that doesn't require an RM @@ -176,7 +177,8 @@ public void testInitiateServiceUpgrade() throws Exception { assertThat(result).isEqualTo(0); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testInitiateAutoFinalizeServiceUpgrade() throws Exception { String[] args = {"app", "-upgrade", "app-1", "-initiate", ExampleAppJson.resourceName(ExampleAppJson.APP_JSON), @@ -233,40 +235,43 @@ public void testCancelUpgrade() throws Exception { assertThat(result).isEqualTo(0); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testEnableFastLaunch() throws Exception { fs.getFileSystem().create(new Path(basedir.getAbsolutePath(), "test.jar")) .close(); Path defaultPath = new Path(dependencyTarGz.toString()); - Assert.assertFalse("Dependency tarball should not exist before the test", - fs.isFile(defaultPath)); + assertFalse(fs.isFile(defaultPath), + "Dependency tarball should not exist before the test"); String[] args = {"app", "-D", dependencyTarGzProp, "-enableFastLaunch", "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_SUCCESS, runCLI(args)); - Assert.assertTrue("Dependency tarball did not exist after the test", - fs.isFile(defaultPath)); + assertEquals(EXIT_SUCCESS, runCLI(args)); + assertTrue(fs.isFile(defaultPath), + "Dependency tarball did not exist after the test"); File secondBaseDir = new File(dependencyTarGzBaseDir, "2"); Path secondTarGz = getDependencyTarGz(secondBaseDir); - Assert.assertFalse("Dependency tarball should not exist before the test", - fs.isFile(secondTarGz)); + assertFalse(fs.isFile(secondTarGz), + "Dependency tarball should not exist before the test"); String[] args2 = {"app", "-D", yarnAdminNoneAclProp, "-D", dfsAdminAclProp, "-D", dependencyTarGzProp, "-enableFastLaunch", secondBaseDir.getAbsolutePath(), "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_SUCCESS, runCLI(args2)); - Assert.assertTrue("Dependency tarball did not exist after the test", - fs.isFile(secondTarGz)); + assertEquals(EXIT_SUCCESS, runCLI(args2)); + assertTrue(fs.isFile(secondTarGz), + "Dependency tarball did not exist after the test"); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testEnableFastLaunchUserPermissions() throws Exception { String[] args = {"app", "-D", yarnAdminNoneAclProp, "-D", dependencyTarGzProp, "-enableFastLaunch", "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_UNAUTHORIZED, runCLI(args)); + assertEquals(EXIT_UNAUTHORIZED, runCLI(args)); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testEnableFastLaunchFilePermissions() throws Exception { File badDir = new File(dependencyTarGzBaseDir, "bad"); badDir.mkdir(); @@ -275,7 +280,7 @@ public void testEnableFastLaunchFilePermissions() throws Exception { String[] args = {"app", "-D", dependencyTarGzProp, "-enableFastLaunch", badDir.getAbsolutePath(), "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_UNAUTHORIZED, runCLI(args)); + assertEquals(EXIT_UNAUTHORIZED, runCLI(args)); badDir = new File(badDir, "child"); badDir.mkdir(); @@ -284,7 +289,7 @@ public void testEnableFastLaunchFilePermissions() throws Exception { String[] args2 = {"app", "-D", dependencyTarGzProp, "-enableFastLaunch", badDir.getAbsolutePath(), "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_UNAUTHORIZED, runCLI(args2)); + assertEquals(EXIT_UNAUTHORIZED, runCLI(args2)); badDir = new File(dependencyTarGzBaseDir, "badx"); badDir.mkdir(); @@ -293,24 +298,24 @@ public void testEnableFastLaunchFilePermissions() throws Exception { String[] args3 = {"app", "-D", dependencyTarGzProp, "-enableFastLaunch", badDir.getAbsolutePath(), "-appTypes", DUMMY_APP_TYPE}; - Assert.assertEquals(EXIT_UNAUTHORIZED, runCLI(args3)); + assertEquals(EXIT_UNAUTHORIZED, runCLI(args3)); } private void checkApp(String serviceName, String compName, long count, Long lifetime, String queue) throws IOException { Service service = ServiceApiUtil.loadService(fs, serviceName); - Assert.assertEquals(serviceName, service.getName()); - Assert.assertEquals(lifetime, service.getLifetime()); - Assert.assertEquals(queue, service.getQueue()); + assertEquals(serviceName, service.getName()); + assertEquals(lifetime, service.getLifetime()); + assertEquals(queue, service.getQueue()); List components = service.getComponents(); for (Component component : components) { if (component.getName().equals(compName)) { - Assert.assertEquals(count, component.getNumberOfContainers() + assertEquals(count, component.getNumberOfContainers() .longValue()); return; } } - Assert.fail(); + fail(); } private static final String DUMMY_APP_TYPE = "dummy"; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java index 85da12f4d0a9e..51d9262719b30 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java @@ -49,9 +49,8 @@ import org.apache.hadoop.yarn.service.exceptions.ErrorStrings; import org.apache.hadoop.yarn.service.utils.FilterUtils; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +59,10 @@ import java.util.ArrayList; import java.util.List; -import static org.mockito.ArgumentMatchers.any; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -72,8 +74,8 @@ public class TestServiceClient { private static final Logger LOG = LoggerFactory.getLogger( TestServiceClient.class); - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); @Test @@ -89,12 +91,12 @@ public void testAMEnvCustomClasspath() throws Exception { client.getConfig().set("yarn.service.classpath", "{{VAR_1}},{{VAR_2}}"); String newPath = client.addAMEnv().get("CLASSPATH"); - Assert.assertEquals(originalPath + "{{VAR_1}}{{VAR_2}}", newPath); + assertEquals(originalPath + "{{VAR_1}}{{VAR_2}}", newPath); //restoring the original value for service classpath client.getConfig().set("yarn.service.classpath", oldParam); newPath = client.addAMEnv().get("CLASSPATH"); - Assert.assertEquals(originalPath, newPath); + assertEquals(originalPath, newPath); client.stop(); } @@ -109,11 +111,11 @@ public void testUpgradeDisabledByDefault() throws Exception { try { client.initiateUpgrade(service); } catch (YarnException ex) { - Assert.assertEquals(ErrorStrings.SERVICE_UPGRADE_DISABLED, + assertEquals(ErrorStrings.SERVICE_UPGRADE_DISABLED, ex.getMessage()); return; } - Assert.fail(); + fail(); } @Test @@ -127,8 +129,8 @@ public void testActionServiceUpgrade() throws Exception { Service fromFs = ServiceApiUtil.loadServiceUpgrade(rule.getFs(), service.getName(), service.getVersion()); - Assert.assertEquals(service.getName(), fromFs.getName()); - Assert.assertEquals(service.getVersion(), fromFs.getVersion()); + assertEquals(service.getName(), fromFs.getName()); + assertEquals(service.getVersion(), fromFs.getVersion()); client.stop(); } @@ -149,7 +151,7 @@ public void testActionCompInstanceUpgrade() throws Exception { client.actionUpgrade(service, comp.getContainers()); CompInstancesUpgradeResponseProto response = client.getLastProxyResponse( CompInstancesUpgradeResponseProto.class); - Assert.assertNotNull("upgrade did not complete", response); + assertNotNull(response, "upgrade did not complete"); client.stop(); } @@ -169,11 +171,11 @@ public void testGetCompInstances() throws Exception { ComponentContainers[] compContainers = client.getContainers( service.getName(), Lists.newArrayList("compa"), "v1", null); - Assert.assertEquals("num comp", 1, compContainers.length); - Assert.assertEquals("comp name", "compa", - compContainers[0].getComponentName()); - Assert.assertEquals("num containers", 2, - compContainers[0].getContainers().size()); + assertEquals(1, compContainers.length, "num comp"); + assertEquals("compa", + compContainers[0].getComponentName(), "comp name"); + assertEquals(2, + compContainers[0].getContainers().size(), "num containers"); client.stop(); } @@ -191,13 +193,13 @@ public void testUpgradeDisabledWhenAllCompsHaveNeverRestartPolicy() try { client.initiateUpgrade(service); } catch (YarnException ex) { - Assert.assertEquals("All the components of the service " + + assertEquals("All the components of the service " + service.getName() + " have " + Component.RestartPolicyEnum.NEVER + " restart policy, so it cannot be upgraded.", ex.getMessage()); return; } - Assert.fail(); + fail(); } private Service createService() throws IOException, @@ -241,8 +243,8 @@ static MockServiceClient create(ServiceTestUtils.ServiceFSWatcher rule, ApplicationAttemptReport attemptReport = ApplicationAttemptReport.newInstance(client.attemptId, "localhost", 0, - null, null, null, - YarnApplicationAttemptState.RUNNING, null); + null, null, null, + YarnApplicationAttemptState.RUNNING, null); when(yarnClient.getApplicationAttemptReport(any())) .thenReturn(attemptReport); when(yarnClient.getApplicationReport(client.appId)).thenReturn(appReport); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponent.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponent.java index f8f948dd88f0c..2da3010b384fc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponent.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponent.java @@ -31,9 +31,8 @@ import org.apache.hadoop.yarn.service.component.instance.ComponentInstanceEvent; import org.apache.hadoop.yarn.service.component.instance.ComponentInstanceEventType; import org.apache.log4j.Logger; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.util.Iterator; @@ -43,6 +42,7 @@ import static org.apache.hadoop.yarn.service.conf.YarnServiceConstants .CONTAINER_STATE_REPORT_AS_SERVICE_STATE; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for {@link Component}. @@ -51,8 +51,8 @@ public class TestComponent { static final Logger LOG = Logger.getLogger(TestComponent.class); - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); @Test @@ -64,8 +64,8 @@ public void testComponentUpgrade() throws Exception { ComponentEvent upgradeEvent = new ComponentEvent(comp.getName(), ComponentEventType.UPGRADE); comp.handle(upgradeEvent); - Assert.assertEquals("component not in need upgrade state", - ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState()); + assertEquals(ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState(), + "component not in need upgrade state"); } @Test @@ -83,18 +83,18 @@ public void testCheckState() throws Exception { comp.getUpgradeStatus().decContainersThatNeedUpgrade(); comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in need upgrade state", - ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState()); + assertEquals(ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState(), + "component not in need upgrade state"); // second instance finished upgrading comp.getUpgradeStatus().decContainersThatNeedUpgrade(); comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in stable state", - ComponentState.STABLE, comp.getComponentSpec().getState()); - Assert.assertEquals("component did not upgrade successfully", "val1", - comp.getComponentSpec().getConfiguration().getEnv("key1")); + assertEquals(ComponentState.STABLE, comp.getComponentSpec().getState(), + "component not in stable state"); + assertEquals("val1", comp.getComponentSpec().getConfiguration().getEnv("key1"), + "component did not upgrade successfully"); } @Test @@ -124,8 +124,8 @@ public void testContainerCompletedWhenUpgrading() throws Exception { comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in needs upgrade state", - ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState()); + assertEquals(ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState(), + "component not in needs upgrade state"); } @Test @@ -137,10 +137,10 @@ public void testCancelUpgrade() throws Exception { ComponentEvent upgradeEvent = new ComponentEvent(comp.getName(), ComponentEventType.CANCEL_UPGRADE); comp.handle(upgradeEvent); - Assert.assertEquals("component not in need upgrade state", - ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState()); + assertEquals(ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState(), + "component not in need upgrade state"); - Assert.assertEquals( + assertEquals( org.apache.hadoop.yarn.service.component.ComponentState .CANCEL_UPGRADING, comp.getState()); } @@ -190,16 +190,16 @@ public void testContainerCompletedCancelUpgrade() throws Exception { comp.handle(stopEvent); instance1.handle(new ComponentInstanceEvent( instance1.getContainer().getId(), STOP)); - Assert.assertEquals( + assertEquals( org.apache.hadoop.yarn.service.component.ComponentState .CANCEL_UPGRADING, comp.getState()); comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in needs upgrade state", - ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState()); - Assert.assertEquals( + assertEquals(ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState(), + "component not in needs upgrade state"); + assertEquals( org.apache.hadoop.yarn.service.component.ComponentState .CANCEL_UPGRADING, comp.getState()); @@ -214,18 +214,18 @@ public void testContainerCompletedCancelUpgrade() throws Exception { comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in flexing state", - ComponentState.FLEXING, comp.getComponentSpec().getState()); + assertEquals(ComponentState.FLEXING, comp.getComponentSpec().getState(), + "component not in flexing state"); // new container get allocated context.assignNewContainer(context.attemptId, 10, comp); comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in stable state", - ComponentState.STABLE, comp.getComponentSpec().getState()); - Assert.assertEquals("cancel upgrade failed", "val0", - comp.getComponentSpec().getConfiguration().getEnv("key1")); + assertEquals(ComponentState.STABLE, comp.getComponentSpec().getState(), + "component not in stable state"); + assertEquals("val0", comp.getComponentSpec().getConfiguration().getEnv("key1"), + "cancel upgrade failed"); } @Test @@ -249,10 +249,10 @@ public void testCancelUpgradeSuccessWhileUpgrading() throws Exception { comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in stable state", - ComponentState.STABLE, comp.getComponentSpec().getState()); - Assert.assertEquals("cancel upgrade failed", "val0", - comp.getComponentSpec().getConfiguration().getEnv("key1")); + assertEquals(ComponentState.STABLE, comp.getComponentSpec().getState(), + "component not in stable state"); + assertEquals("val0", comp.getComponentSpec().getConfiguration().getEnv("key1"), + "cancel upgrade failed"); } @Test @@ -272,8 +272,8 @@ public void testCancelUpgradeFailureWhileUpgrading() throws Exception { comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in flexing state", - ComponentState.FLEXING, comp.getComponentSpec().getState()); + assertEquals(ComponentState.FLEXING, comp.getComponentSpec().getState(), + "component not in flexing state"); for (ComponentInstance instance : comp.getAllComponentInstances()) { // new container get allocated @@ -283,10 +283,10 @@ public void testCancelUpgradeFailureWhileUpgrading() throws Exception { comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in stable state", - ComponentState.STABLE, comp.getComponentSpec().getState()); - Assert.assertEquals("cancel upgrade failed", "val0", - comp.getComponentSpec().getConfiguration().getEnv("key1")); + assertEquals(ComponentState.STABLE, comp.getComponentSpec().getState(), + "component not in stable state"); + assertEquals("val0", comp.getComponentSpec().getConfiguration().getEnv("key1"), + "cancel upgrade failed"); } private void cancelUpgradeWhileUpgrading( @@ -327,16 +327,16 @@ private void cancelUpgradeWhileUpgrading( instance1.getContainer().getId(), STOP)); // component should be in cancel upgrade - Assert.assertEquals( + assertEquals( org.apache.hadoop.yarn.service.component.ComponentState .CANCEL_UPGRADING, comp.getState()); comp.handle(new ComponentEvent(comp.getName(), ComponentEventType.CHECK_STABLE)); - Assert.assertEquals("component not in needs upgrade state", - ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState()); - Assert.assertEquals( + assertEquals(ComponentState.NEEDS_UPGRADE, comp.getComponentSpec().getState(), + "component not in needs upgrade state"); + assertEquals( org.apache.hadoop.yarn.service.component.ComponentState .CANCEL_UPGRADING, comp.getState()); } @@ -362,11 +362,11 @@ public void testComponentStateReachesStableStateWithTerminatingComponents() ComponentInstance componentInstance = instanceIter.next(); Container instanceContainer = componentInstance.getContainer(); - Assert.assertEquals(0, comp.getNumSucceededInstances()); - Assert.assertEquals(0, comp.getNumFailedInstances()); - Assert.assertEquals(2, comp.getNumRunningInstances()); - Assert.assertEquals(2, comp.getNumReadyInstances()); - Assert.assertEquals(0, comp.getPendingInstances().size()); + assertEquals(0, comp.getNumSucceededInstances()); + assertEquals(0, comp.getNumFailedInstances()); + assertEquals(2, comp.getNumRunningInstances()); + assertEquals(2, comp.getNumReadyInstances()); + assertEquals(0, comp.getPendingInstances().size()); //stop 1 container ContainerStatus containerStatus = ContainerStatus.newInstance( @@ -380,15 +380,15 @@ public void testComponentStateReachesStableStateWithTerminatingComponents() new ComponentInstanceEvent(componentInstance.getContainer().getId(), ComponentInstanceEventType.STOP).setStatus(containerStatus)); - Assert.assertEquals(1, comp.getNumSucceededInstances()); - Assert.assertEquals(0, comp.getNumFailedInstances()); - Assert.assertEquals(1, comp.getNumRunningInstances()); - Assert.assertEquals(1, comp.getNumReadyInstances()); - Assert.assertEquals(0, comp.getPendingInstances().size()); + assertEquals(1, comp.getNumSucceededInstances()); + assertEquals(0, comp.getNumFailedInstances()); + assertEquals(1, comp.getNumRunningInstances()); + assertEquals(1, comp.getNumReadyInstances()); + assertEquals(0, comp.getPendingInstances().size()); org.apache.hadoop.yarn.service.component.ComponentState componentState = Component.checkIfStable(comp); - Assert.assertEquals( + assertEquals( org.apache.hadoop.yarn.service.component.ComponentState.STABLE, componentState); } @@ -431,14 +431,14 @@ public void testComponentStateUpdatesWithTerminatingComponents() ComponentState componentState = comp.getComponentSpec().getState(); - Assert.assertEquals( + assertEquals( ComponentState.SUCCEEDED, componentState); } ServiceState serviceState = testService.getState(); - Assert.assertEquals( + assertEquals( ServiceState.SUCCEEDED, serviceState); } @@ -484,7 +484,7 @@ public void testComponentStateUpdatesWithTerminatingDominantComponents() } ComponentState componentState = comp.getComponentSpec().getState(); - Assert.assertEquals( + assertEquals( ComponentState.SUCCEEDED, componentState); } @@ -492,7 +492,7 @@ public void testComponentStateUpdatesWithTerminatingDominantComponents() ServiceState serviceState = testService.getState(); - Assert.assertEquals( + assertEquals( ServiceState.SUCCEEDED, serviceState); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentDecommissionInstances.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentDecommissionInstances.java index e617410b0a66f..1e2e8fe14f87e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentDecommissionInstances.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentDecommissionInstances.java @@ -27,12 +27,9 @@ import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.api.records.ServiceState; import org.apache.hadoop.yarn.service.client.ServiceClient; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +42,9 @@ import java.util.Set; import java.util.concurrent.TimeoutException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Test decommissioning component instances. */ @@ -55,16 +55,13 @@ public class TestComponentDecommissionInstances extends ServiceTestUtils { private static final String APP_NAME = "test-decommission"; private static final String COMPA = "compa"; - @Rule - public TemporaryFolder tmpFolder = new TemporaryFolder(); - - @Before + @BeforeEach public void setup() throws Exception { File tmpYarnDir = new File("target", "tmp"); FileUtils.deleteQuietly(tmpYarnDir); } - @After + @AfterEach public void tearDown() throws IOException { shutdown(); } @@ -129,19 +126,19 @@ private static void checkInstances(ServiceClient client, String... instances) throws IOException, YarnException { Service service = client.getStatus(APP_NAME); Component component = service.getComponent(COMPA); - Assert.assertEquals("Service state should be STABLE", ServiceState.STABLE, - service.getState()); - Assert.assertEquals(instances.length + " containers are expected to be " + - "running", instances.length, component.getContainers().size()); + assertEquals(ServiceState.STABLE, + service.getState(), "Service state should be STABLE"); + assertEquals(instances.length, component.getContainers().size(), + instances.length + " containers are expected to be running"); Set existingInstances = new HashSet<>(); for (Container cont : component.getContainers()) { existingInstances.add(cont.getComponentInstanceName()); } - Assert.assertEquals(instances.length + " instances are expected to be " + - "running", instances.length, existingInstances.size()); + assertEquals(instances.length, existingInstances.size(), + instances.length + " instances are expected to be running"); for (String instance : instances) { - Assert.assertTrue("Expected instance did not exist " + instance, - existingInstances.contains(instance)); + assertTrue(existingInstances.contains(instance), + "Expected instance did not exist " + instance); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentRestartPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentRestartPolicy.java index 3e3b4a1a3dcda..3b68e7d8438e4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentRestartPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/TestComponentRestartPolicy.java @@ -19,9 +19,9 @@ import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.service.component.instance.ComponentInstance; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java index 06bca6f1b0053..5eec09c7b6c11 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java @@ -42,9 +42,8 @@ import org.apache.hadoop.yarn.service.component.ComponentEventType; import org.apache.hadoop.yarn.service.component.TestComponent; import org.apache.hadoop.yarn.service.utils.ServiceUtils; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; import java.nio.file.Files; @@ -56,6 +55,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; @@ -71,8 +72,8 @@ */ public class TestComponentInstance { - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); @Test @@ -90,8 +91,8 @@ public void testContainerUpgrade() throws Exception { instance.handle(instanceEvent); Container containerSpec = component.getComponentSpec().getContainer( instance.getContainer().getId().toString()); - Assert.assertEquals("instance not upgrading", ContainerState.UPGRADING, - containerSpec.getState()); + assertEquals(ContainerState.UPGRADING, + containerSpec.getState(), "instance not upgrading"); } @Test @@ -110,15 +111,14 @@ public void testContainerReadyAfterUpgrade() throws Exception { instance.handle(instanceEvent); instance.handle(new ComponentInstanceEvent(instance.getContainer().getId(), ComponentInstanceEventType.START)); - Assert.assertEquals("instance not running", - ContainerState.RUNNING_BUT_UNREADY, + assertEquals(ContainerState.RUNNING_BUT_UNREADY, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance not running"); instance.handle(new ComponentInstanceEvent(instance.getContainer().getId(), ComponentInstanceEventType.BECOME_READY)); - Assert.assertEquals("instance not ready", ContainerState.READY, + assertEquals(ContainerState.READY, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance not ready"); } @@ -145,9 +145,9 @@ public void testContainerUpgradeFailed() throws Exception { .setStatus(containerStatus); // this is the call back from NM for the upgrade instance.handle(stopEvent); - Assert.assertEquals("instance did not fail", ContainerState.FAILED_UPGRADE, + assertEquals(ContainerState.FAILED_UPGRADE, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance did not fail"); } @Test @@ -168,10 +168,9 @@ public void testFailureAfterReinit() throws Exception { // NM finished updgrae instance.handle(new ComponentInstanceEvent(instance.getContainer().getId(), ComponentInstanceEventType.START)); - Assert.assertEquals("instance not running", - ContainerState.RUNNING_BUT_UNREADY, + assertEquals(ContainerState.RUNNING_BUT_UNREADY, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance not running"); ContainerStatus containerStatus = mock(ContainerStatus.class); when(containerStatus.getExitStatus()).thenReturn( @@ -181,9 +180,9 @@ public void testFailureAfterReinit() throws Exception { .setStatus(containerStatus); // this is the call back from NM for the upgrade instance.handle(stopEvent); - Assert.assertEquals("instance did not fail", ContainerState.FAILED_UPGRADE, + assertEquals(ContainerState.FAILED_UPGRADE, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance did not fail"); } @Test @@ -202,9 +201,9 @@ public void testCancelNothingToUpgrade() throws Exception { ComponentInstanceEventType.CANCEL_UPGRADE); instance.handle(cancelEvent); - Assert.assertEquals("instance not ready", ContainerState.READY, + assertEquals(ContainerState.READY, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance not ready"); } @Test @@ -225,8 +224,8 @@ public void testCancelUpgradeFailed() throws Exception { instance.handle(new ComponentInstanceEvent(instance.getContainer().getId(), ComponentInstanceEventType.STOP)); - Assert.assertEquals("instance not init", ComponentInstanceState.INIT, - instance.getState()); + assertEquals(ComponentInstanceState.INIT, + instance.getState(), "instance not init"); } @Test @@ -244,10 +243,9 @@ public void testCancelAfterCompProcessedCancel() throws Exception { instance.getContainer().getId(), ComponentInstanceEventType.UPGRADE); instance.handle(upgradeEvent); - Assert.assertEquals("instance should start upgrading", - ContainerState.NEEDS_UPGRADE, + assertEquals(ContainerState.NEEDS_UPGRADE, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance should start upgrading"); } @Test @@ -296,30 +294,26 @@ public void testUpdateLocalizationStatuses() throws Exception { LocalizationState.PENDING); instance.updateLocalizationStatuses(Lists.newArrayList(status)); - Assert.assertTrue("retriever should still be active", - instance.isLclRetrieverActive()); + assertTrue(instance.isLclRetrieverActive(), + "retriever should still be active"); Container container = instance.getContainerSpec(); - Assert.assertTrue(container.getLocalizationStatuses() != null); - Assert.assertEquals("dest file", - container.getLocalizationStatuses().get(0).getDestFile(), - status.getResourceKey()); - Assert.assertEquals("state", - container.getLocalizationStatuses().get(0).getState(), - status.getLocalizationState()); + assertTrue(container.getLocalizationStatuses() != null); + assertEquals(container.getLocalizationStatuses().get(0).getDestFile(), + status.getResourceKey(), "dest file"); + assertEquals(container.getLocalizationStatuses().get(0).getState(), + status.getLocalizationState(), "state"); status = LocalizationStatus.newInstance("file1", LocalizationState.COMPLETED); instance.updateLocalizationStatuses(Lists.newArrayList(status)); - Assert.assertTrue("retriever should not be active", - !instance.isLclRetrieverActive()); - Assert.assertTrue(container.getLocalizationStatuses() != null); - Assert.assertEquals("dest file", - container.getLocalizationStatuses().get(0).getDestFile(), - status.getResourceKey()); - Assert.assertEquals("state", - container.getLocalizationStatuses().get(0).getState(), - status.getLocalizationState()); + assertTrue(!instance.isLclRetrieverActive(), + "retriever should not be active"); + assertTrue(container.getLocalizationStatuses() != null); + assertEquals(container.getLocalizationStatuses().get(0).getDestFile(), + status.getResourceKey(), "dest file"); + assertEquals(container.getLocalizationStatuses().get(0).getState(), + status.getLocalizationState(), "state"); } private void validateCancelWhileUpgrading(boolean upgradeSuccessful, @@ -337,10 +331,9 @@ private void validateCancelWhileUpgrading(boolean upgradeSuccessful, instance.getContainer().getId(), ComponentInstanceEventType.UPGRADE); instance.handle(upgradeEvent); - Assert.assertEquals("instance should be upgrading", - ContainerState.UPGRADING, + assertEquals(ContainerState.UPGRADING, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance should be upgrading"); cancelCompUpgrade(component); ComponentInstanceEvent cancelEvent = new ComponentInstanceEvent( @@ -361,9 +354,9 @@ private void validateCancelWhileUpgrading(boolean upgradeSuccessful, ComponentInstanceEventType.STOP)); } - Assert.assertEquals("instance not upgrading", ContainerState.UPGRADING, + assertEquals(ContainerState.UPGRADING, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance not upgrading"); // response for cancel received if (cancelUpgradeSuccessful) { @@ -377,12 +370,12 @@ private void validateCancelWhileUpgrading(boolean upgradeSuccessful, instance.getContainer().getId(), ComponentInstanceEventType.STOP)); } if (cancelUpgradeSuccessful) { - Assert.assertEquals("instance not ready", ContainerState.READY, + assertEquals(ContainerState.READY, component.getComponentSpec().getContainer(instance.getContainer() - .getId().toString()).getState()); + .getId().toString()).getState(), "instance not ready"); } else { - Assert.assertEquals("instance not init", ComponentInstanceState.INIT, - instance.getState()); + assertEquals(ComponentInstanceState.INIT, + instance.getState(), "instance not init"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestAppJsonResolve.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestAppJsonResolve.java index 04c84dc1a2bb2..8d8bcbe7a1601 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestAppJsonResolve.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestAppJsonResolve.java @@ -28,8 +28,7 @@ import org.apache.hadoop.yarn.service.api.records.Configuration; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.apache.hadoop.yarn.service.utils.SliderFileSystem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,11 +40,15 @@ import java.util.Set; import static org.apache.hadoop.yarn.service.conf.ExampleAppJson.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test global configuration resolution. */ -public class TestAppJsonResolve extends Assert { +public class TestAppJsonResolve { protected static final Logger LOG = LoggerFactory.getLogger(TestAppJsonResolve.class); @@ -199,18 +202,18 @@ public void testOverrideExternalConfiguration() throws IOException { // Validate worker's resources Resource workerResource = orig.getComponent("worker").getResource(); - Assert.assertEquals(1, workerResource.getCpus().intValue()); - Assert.assertEquals(1024, workerResource.calcMemoryMB()); - Assert.assertNotNull(workerResource.getAdditional()); - Assert.assertEquals(2, workerResource.getAdditional().size()); - Assert.assertEquals(3333, workerResource.getAdditional().get( + assertEquals(1, workerResource.getCpus().intValue()); + assertEquals(1024, workerResource.calcMemoryMB()); + assertNotNull(workerResource.getAdditional()); + assertEquals(2, workerResource.getAdditional().size()); + assertEquals(3333, workerResource.getAdditional().get( "resource-1").getValue().longValue()); - Assert.assertEquals("Gi", workerResource.getAdditional().get( + assertEquals("Gi", workerResource.getAdditional().get( "resource-1").getUnit()); - Assert.assertEquals(5, workerResource.getAdditional().get( + assertEquals(5, workerResource.getAdditional().get( "yarn.io/gpu").getValue().longValue()); - Assert.assertEquals("", workerResource.getAdditional().get( + assertEquals("", workerResource.getAdditional().get( "yarn.io/gpu").getUnit()); other = orig.getComponent("other").getConfiguration(); @@ -221,16 +224,16 @@ public void testOverrideExternalConfiguration() throws IOException { public void testSetResourceAttributes() throws IOException { Service orig = ExampleAppJson.loadResource(EXTERNAL_JSON_3); Component component = orig.getComponent("volume-service"); - Assert.assertNotNull(component); + assertNotNull(component); Map adResource = component .getResource().getAdditional(); - Assert.assertNotNull(adResource); - Assert.assertEquals(1, adResource.size()); + assertNotNull(adResource); + assertEquals(1, adResource.size()); Map.Entry volume = adResource .entrySet().iterator().next(); - Assert.assertEquals("yarn.io/csi-volume", volume.getKey()); - Assert.assertEquals(100L, volume.getValue().getValue().longValue()); - Assert.assertEquals(2, volume.getValue().getAttributes().size()); - Assert.assertEquals(1, volume.getValue().getTags().size()); + assertEquals("yarn.io/csi-volume", volume.getKey()); + assertEquals(100L, volume.getValue().getValue().longValue()); + assertEquals(2, volume.getValue().getAttributes().size()); + assertEquals(1, volume.getValue().getTags().size()); } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestLoadExampleAppJson.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestLoadExampleAppJson.java index a813da3bff1e1..e424676b73101 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestLoadExampleAppJson.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestLoadExampleAppJson.java @@ -23,28 +23,23 @@ import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; import org.apache.hadoop.yarn.service.utils.SliderFileSystem; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; import static org.apache.hadoop.yarn.service.ServiceTestUtils.JSON_SER_DESER; -/** - * Test loading example resources. - */ -@RunWith(value = Parameterized.class) -public class TestLoadExampleAppJson extends Assert { + +public class TestLoadExampleAppJson extends Assertions { private String resource; - public TestLoadExampleAppJson(String resource) { - this.resource = resource; + public void initTestLoadExampleAppJson(String pResource) { + this.resource = pResource; } - @Parameterized.Parameters public static Collection filenames() { String[][] stringArray = new String[ExampleAppJson .ALL_EXAMPLE_RESOURCES.size()][1]; @@ -55,8 +50,10 @@ public static Collection filenames() { return Arrays.asList(stringArray); } - @Test - public void testLoadResource() throws Throwable { + @MethodSource("filenames") + @ParameterizedTest + public void testLoadResource(String pResource) throws Throwable { + initTestLoadExampleAppJson(pResource); try { Service service = JSON_SER_DESER.fromResource(resource); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestValidateServiceNames.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestValidateServiceNames.java index d7fa9a04dbb28..be061862a40bc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestValidateServiceNames.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/conf/TestValidateServiceNames.java @@ -20,12 +20,13 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; +import static org.junit.jupiter.api.Assertions.fail; + /** * Test cluster name validation. */ @@ -38,7 +39,7 @@ void assertValidName(String name) { void assertInvalidName(String name) { try { ServiceApiUtil.validateNameFormat(name, new Configuration()); - Assert.fail(); + fail(); } catch (IllegalArgumentException e) { // } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/containerlaunch/TestAbstractLauncher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/containerlaunch/TestAbstractLauncher.java index 05eec6855ba49..b58ce67802eb6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/containerlaunch/TestAbstractLauncher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/containerlaunch/TestAbstractLauncher.java @@ -27,9 +27,8 @@ import org.apache.hadoop.yarn.service.component.instance.ComponentInstance; import org.apache.hadoop.yarn.service.provider.defaultImpl .DefaultProviderService; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -41,6 +40,7 @@ .DEFAULT_CONTAINER_RETRY_INTERVAL; import static org.apache.hadoop.yarn.service.conf.YarnServiceConf .DEFAULT_CONTAINER_RETRY_MAX; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -53,7 +53,7 @@ public class TestAbstractLauncher { private AbstractLauncher launcher; - @Before + @BeforeEach public void setup() { launcher = new AbstractLauncher(mock(ServiceContext.class)); } @@ -68,7 +68,7 @@ public void testDockerContainerMounts() throws IOException { String dockerContainerMounts = launcher.containerLaunchContext .getEnvironment().get(AbstractLauncher.ENV_DOCKER_CONTAINER_MOUNTS); - Assert.assertEquals("s1:t1:ro,s2:t2:ro", dockerContainerMounts); + assertEquals("s1:t1:ro,s2:t2:ro", dockerContainerMounts); } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/TestServiceMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/TestServiceMonitor.java index c758e6fbeaa9e..6bcd09746df36 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/TestServiceMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/TestServiceMonitor.java @@ -29,10 +29,9 @@ import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.api.records.Component; import org.apache.hadoop.yarn.service.conf.YarnServiceConf; -import org.junit.After; -import org.junit.Assert; -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.File; import java.io.IOException; @@ -40,6 +39,8 @@ import static org.apache.hadoop.registry.client.api.RegistryConstants .KEY_REGISTRY_ZK_QUORUM; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestServiceMonitor extends ServiceTestUtils { @@ -47,7 +48,7 @@ public class TestServiceMonitor extends ServiceTestUtils { YarnConfiguration conf = new YarnConfiguration(); TestingCluster zkCluster; - @Before + @BeforeEach public void setup() throws Exception { basedir = new File("target", "apps"); if (basedir.exists()) { @@ -62,7 +63,7 @@ public void setup() throws Exception { System.out.println("ZK cluster: " + zkCluster.getConnectString()); } - @After + @AfterEach public void tearDown() throws IOException { if (basedir != null) { FileUtils.deleteDirectory(basedir); @@ -100,9 +101,9 @@ public void testComponentDependency() throws Exception{ am.start(); // compa ready - Assert.assertTrue(am.getComponent("compa").areDependenciesReady()); + assertTrue(am.getComponent("compa").areDependenciesReady()); //compb not ready - Assert.assertFalse(am.getComponent("compb").areDependenciesReady()); + assertFalse(am.getComponent("compb").areDependenciesReady()); // feed 1 container to compa, am.feedContainerToComp(exampleApp, 1, "compa"); @@ -120,7 +121,7 @@ public void testComponentDependency() throws Exception{ am.waitForNumDesiredContainers("compa", 2); // compb dependencies not satisfied again. - Assert.assertFalse(am.getComponent("compb").areDependenciesReady()); + assertFalse(am.getComponent("compb").areDependenciesReady()); am.stop(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/probe/TestDefaultProbe.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/probe/TestDefaultProbe.java index 8169e67b7c3a1..c3f7528c427e2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/probe/TestDefaultProbe.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/monitor/probe/TestDefaultProbe.java @@ -20,9 +20,8 @@ import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.service.api.records.ReadinessCheck; import org.apache.hadoop.yarn.service.component.instance.ComponentInstance; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -32,23 +31,21 @@ import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * Tests for default probe. */ -@RunWith(Parameterized.class) public class TestDefaultProbe { - private final DefaultProbe probe; + private DefaultProbe probe; - public TestDefaultProbe(Probe probe) { - this.probe = (DefaultProbe) probe; + public void initTestDefaultProbe(Probe paramProbe) { + this.probe = (DefaultProbe) paramProbe; } - @Parameterized.Parameters public static Collection data() { // test run 1: Default probe checks that container has an IP Probe p1 = MonitorUtils.getProbe(null); @@ -71,8 +68,10 @@ public static Collection data() { return Arrays.asList(new Object[][] {{p1}, {p2}, {p3}}); } - @Test - public void testDefaultProbe() { + @MethodSource("data") + @ParameterizedTest + public void testDefaultProbe(Probe paramProbe) { + initTestDefaultProbe(paramProbe); // component instance has a good hostname, so probe will eventually succeed // whether or not DNS checking is enabled ComponentInstance componentInstance = @@ -89,35 +88,34 @@ private static void checkPingResults(Probe probe, ComponentInstance componentInstance, boolean expectDNSCheckFailure) { // on the first ping, null container status results in failure ProbeStatus probeStatus = probe.ping(componentInstance); - assertFalse("Expected failure for " + probeStatus.toString(), - probeStatus.isSuccess()); - assertTrue("Expected IP failure for " + probeStatus.toString(), - probeStatus.toString().contains( - componentInstance.getCompInstanceName() + ": IP is not available yet")); + assertFalse(probeStatus.isSuccess(), + "Expected failure for " + probeStatus.toString()); + assertTrue(probeStatus.toString().contains( + componentInstance.getCompInstanceName() + ": IP is not available yet"), + "Expected IP failure for " + probeStatus.toString()); // on the second ping, container status is retrieved but there are no // IPs, resulting in failure probeStatus = probe.ping(componentInstance); - assertFalse("Expected failure for " + probeStatus.toString(), - probeStatus.isSuccess()); - assertTrue("Expected IP failure for " + probeStatus.toString(), - probeStatus.toString().contains(componentInstance - .getCompInstanceName() + ": IP is not available yet")); + assertFalse(probeStatus.isSuccess(), + "Expected failure for " + probeStatus.toString()); + assertTrue(probeStatus.toString().contains(componentInstance + .getCompInstanceName() + ": IP is not available yet"), + "Expected IP failure for " + probeStatus.toString()); // on the third ping, IPs are retrieved and success depends on whether or // not a DNS lookup can be performed for the component instance hostname probeStatus = probe.ping(componentInstance); if (expectDNSCheckFailure) { - assertFalse("Expected failure for " + probeStatus.toString(), - probeStatus.isSuccess()); - assertTrue("Expected DNS failure for " + probeStatus.toString(), - probeStatus.toString().contains(componentInstance - .getCompInstanceName() + ": DNS checking is enabled, but lookup" + - " for " + componentInstance.getHostname() + " is not available " + - "yet")); + assertFalse(probeStatus.isSuccess(), + "Expected failure for " + probeStatus.toString()); + assertTrue(probeStatus.toString().contains(componentInstance + .getCompInstanceName() + ": DNS checking is enabled, but lookup" + + " for " + componentInstance.getHostname() + " is not available " + + "yet"), "Expected DNS failure for " + probeStatus.toString()); } else { - assertTrue("Expected success for " + probeStatus.toString(), - probeStatus.isSuccess()); + assertTrue(probeStatus.isSuccess(), + "Expected success for " + probeStatus.toString()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestAbstractProviderService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestAbstractProviderService.java index b56ccb5cf3777..8b9a42fc751d5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestAbstractProviderService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestAbstractProviderService.java @@ -36,16 +36,16 @@ import org.apache.hadoop.yarn.service.containerlaunch.AbstractLauncher; import org.apache.hadoop.yarn.service.containerlaunch.ContainerLaunchService; import org.apache.hadoop.yarn.service.provider.docker.DockerProviderService; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.io.File; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -58,11 +58,11 @@ public class TestAbstractProviderService { private Service testService; private AbstractLauncher launcher; - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); - @Before + @BeforeEach public void setup() throws Exception { testService = TestServiceManager.createBaseDef("testService"); serviceContext = new MockRunningServiceContext(rule, testService); @@ -70,7 +70,7 @@ public void setup() throws Exception { rule.getFs().setAppDir(new Path("target/testAbstractProviderService")); } - @After + @AfterEach public void teardown() throws Exception { FileUtils.deleteQuietly( new File(rule.getFs().getAppDir().toUri().getPath())); @@ -91,8 +91,8 @@ public void testBuildContainerLaunchCommand() throws Exception { rule.getFs(), serviceContext.scheduler.getConfig(), container, clc, null); - Assert.assertEquals("commands", Lists.newArrayList(clc.getLaunchCommand()), - launcher.getCommands()); + assertEquals(Lists.newArrayList(clc.getLaunchCommand()), + launcher.getCommands(), "commands"); } @Test @@ -110,8 +110,8 @@ public void testBuildContainerLaunchCommandWithSpace() throws Exception { rule.getFs(), serviceContext.scheduler.getConfig(), container, clc, null); - Assert.assertEquals("commands don't match.", - Lists.newArrayList("ls,-l, space"), launcher.getCommands()); + assertEquals(Lists.newArrayList("ls,-l, space"), + launcher.getCommands(), "commands don't match."); } @Test @@ -132,8 +132,8 @@ public void testBuildContainerLaunchContext() throws Exception { providerService.buildContainerLaunchContext(launcher, testService, instance, rule.getFs(), serviceContext.scheduler.getConfig(), container, clc); - Assert.assertEquals("artifact", clc.getArtifact().getId(), - launcher.getDockerImage()); + assertEquals(clc.getArtifact().getId(), + launcher.getDockerImage(), "artifact"); } private static ContainerLaunchService.ComponentLaunchContext diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java index bfdcccd268c4a..c704ea1b4c59c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/provider/TestProviderUtils.java @@ -30,14 +30,14 @@ import org.apache.hadoop.yarn.service.containerlaunch.AbstractLauncher; import org.apache.hadoop.yarn.service.containerlaunch.ContainerLaunchService; import org.apache.hadoop.yarn.service.utils.SliderFileSystem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -169,8 +169,8 @@ public void setShouldBeUploadedToSharedCache( Mockito.verify(launcher).addLocalResource( Mockito.eq("sourceFile4"), any(LocalResource.class)); - Assert.assertEquals(3, resolved.getResolvedRsrcPaths().size()); - Assert.assertEquals(resolved.getResolvedRsrcPaths().get("destFile1"), + assertEquals(3, resolved.getResolvedRsrcPaths().size()); + assertEquals(resolved.getResolvedRsrcPaths().get("destFile1"), "destFile1"); } @@ -179,7 +179,7 @@ public void testReplaceSpacesWithDelimiter() { String command = "ls -l \" space\""; String expected = "ls,-l, space"; String actual = ProviderUtils.replaceSpacesWithDelimiter(command, ","); - Assert.assertEquals("replaceSpaceWithDelimiter produces unexpected result.", - expected, actual); + assertEquals(expected, actual, + "replaceSpaceWithDelimiter produces unexpected result."); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java index 8908a1d415b83..cd8c84cec6f70 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestAbstractClientProvider.java @@ -23,13 +23,13 @@ import org.apache.hadoop.yarn.service.api.records.Artifact; import org.apache.hadoop.yarn.service.api.records.ConfigFile; import org.apache.hadoop.yarn.service.provider.AbstractClientProvider; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -69,21 +69,21 @@ public void testConfigFiles() throws IOException { try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "null file type"); + fail(EXCEPTION_PREFIX + "null file type"); } catch (IllegalArgumentException e) { } configFile.setType(ConfigFile.TypeEnum.TEMPLATE); try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "empty src_file for type template"); + fail(EXCEPTION_PREFIX + "empty src_file for type template"); } catch (IllegalArgumentException e) { } configFile.setSrcFile("srcfile"); try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "empty dest file"); + fail(EXCEPTION_PREFIX + "empty dest file"); } catch (IllegalArgumentException e) { } @@ -91,7 +91,7 @@ public void testConfigFiles() throws IOException { try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } configFile = new ConfigFile(); @@ -101,7 +101,7 @@ public void testConfigFiles() throws IOException { configFiles.add(configFile); try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "dest file with multiple path elements"); + fail(EXCEPTION_PREFIX + "dest file with multiple path elements"); } catch (IllegalArgumentException e) { } @@ -109,13 +109,13 @@ public void testConfigFiles() throws IOException { try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } configFile.setDestFile("destfile"); try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "duplicate dest file"); + fail(EXCEPTION_PREFIX + "duplicate dest file"); } catch (IllegalArgumentException e) { } @@ -127,14 +127,14 @@ public void testConfigFiles() throws IOException { configFiles.add(configFile); try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "dest file with multiple path elements"); + fail(EXCEPTION_PREFIX + "dest file with multiple path elements"); } catch (IllegalArgumentException e) { } configFile.setDestFile("/path/destfile3"); try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "src file should be specified"); + fail(EXCEPTION_PREFIX + "src file should be specified"); } catch (IllegalArgumentException e) { } @@ -156,7 +156,7 @@ public void testConfigFiles() throws IOException { try { clientProvider.validateConfigFiles(configFiles, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + "src file is a directory"); + fail(EXCEPTION_PREFIX + "src file is a directory"); } catch (IllegalArgumentException e) { } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java index 6d6720bb7e6e2..f98e39712af91 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestDefaultClientProvider.java @@ -17,6 +17,8 @@ */ package org.apache.hadoop.yarn.service.providers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,8 +29,7 @@ import org.apache.hadoop.yarn.service.api.records.ConfigFile; import org.apache.hadoop.yarn.service.exceptions.RestApiErrorMessages; import org.apache.hadoop.yarn.service.provider.defaultImpl.DefaultClientProvider; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestDefaultClientProvider { private static final String EXCEPTION_PREFIX = "Should have thrown " @@ -48,19 +49,19 @@ public void testConfigFile() throws IOException { try { defaultClientProvider.validateConfigFile(configFile, compName, mockFs); - Assert.fail(EXCEPTION_PREFIX + " dest_file must be relative"); + fail(EXCEPTION_PREFIX + " dest_file must be relative"); } catch (IllegalArgumentException e) { String actualMsg = String.format( RestApiErrorMessages.ERROR_CONFIGFILE_DEST_FILE_FOR_COMP_NOT_ABSOLUTE, compName, "no", configFile.getDestFile()); - Assert.assertEquals(actualMsg, e.getLocalizedMessage()); + assertEquals(actualMsg, e.getLocalizedMessage()); } configFile.setDestFile("../a.txt"); try { defaultClientProvider.validateConfigFile(configFile, compName, mockFs); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getLocalizedMessage()); + fail(NO_EXCEPTION_PREFIX + e.getLocalizedMessage()); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestProviderFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestProviderFactory.java index 56f4555b16c01..e9d42672e62b8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestProviderFactory.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/providers/TestProviderFactory.java @@ -31,9 +31,9 @@ import org.apache.hadoop.yarn.service.provider.tarball.TarballProviderFactory; import org.apache.hadoop.yarn.service.provider.tarball.TarballProviderService; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test provider factories. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/timelineservice/TestServiceTimelinePublisher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/timelineservice/TestServiceTimelinePublisher.java index a77e6c8d31777..9638de5054f79 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/timelineservice/TestServiceTimelinePublisher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/timelineservice/TestServiceTimelinePublisher.java @@ -41,9 +41,9 @@ import org.apache.hadoop.yarn.service.api.records.Resource; import org.apache.hadoop.yarn.service.component.instance.ComponentInstance; import org.apache.hadoop.yarn.service.component.instance.ComponentInstanceId; -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.util.ArrayList; @@ -54,7 +54,7 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -78,7 +78,7 @@ public class TestServiceTimelinePublisher { private static String CONTAINER_BAREHOST = "localhost.com"; - @Before + @BeforeEach public void setUp() throws Exception { config = new Configuration(); config.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true); @@ -90,7 +90,7 @@ public void setUp() throws Exception { serviceTimelinePublisher.start(); } - @After + @AfterEach public void tearDown() throws Exception { if (serviceTimelinePublisher != null) { serviceTimelinePublisher.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestCoreFileSystem.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestCoreFileSystem.java index ba4a65813d2dc..f88f4640c325c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestCoreFileSystem.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestCoreFileSystem.java @@ -21,17 +21,18 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.yarn.service.ServiceTestUtils; import org.apache.hadoop.yarn.service.conf.YarnServiceConstants; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for {@link CoreFileSystem}. */ public class TestCoreFileSystem { - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); @Test @@ -40,7 +41,7 @@ public void testClusterUpgradeDirPath() { String version = "v1"; Path expectedPath = new Path(rule.getFs().buildClusterDirPath(serviceName), YarnServiceConstants.UPGRADE_DIR + "/" + version); - Assert.assertEquals("incorrect upgrade path", expectedPath, - rule.getFs().buildClusterUpgradeDirPath(serviceName, version)); + assertEquals(expectedPath, rule.getFs().buildClusterUpgradeDirPath(serviceName, version), + "incorrect upgrade path"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestFilterUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestFilterUtils.java index 59cc441818a83..b5f8a1a6bbf6d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestFilterUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestFilterUtils.java @@ -26,16 +26,17 @@ import org.apache.hadoop.yarn.service.TestServiceManager; import org.apache.hadoop.yarn.service.api.records.ComponentContainers; import org.apache.hadoop.yarn.service.api.records.ContainerState; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TestFilterUtils { - @Rule - public ServiceTestUtils.ServiceFSWatcher rule = + @RegisterExtension + private ServiceTestUtils.ServiceFSWatcher rule = new ServiceTestUtils.ServiceFSWatcher(); @Test @@ -45,9 +46,9 @@ public void testNoFilter() throws Exception { List compContainers = FilterUtils.filterInstances( new MockRunningServiceContext(rule, TestServiceManager.createBaseDef("service")), req); - Assert.assertEquals("num comps", 2, compContainers.size()); + assertEquals(2, compContainers.size(), "num comps"); compContainers.forEach(item -> { - Assert.assertEquals("num containers", 2, item.getContainers().size()); + assertEquals(2, item.getContainers().size(), "num containers"); }); } @@ -58,12 +59,9 @@ public void testFilterWithComp() throws Exception { List compContainers = FilterUtils.filterInstances( new MockRunningServiceContext(rule, TestServiceManager.createBaseDef("service")), req); - Assert.assertEquals("num comps", 1, compContainers.size()); - Assert.assertEquals("comp name", "compa", - compContainers.get(0).getComponentName()); - - Assert.assertEquals("num containers", 2, - compContainers.get(0).getContainers().size()); + assertEquals(1, compContainers.size(), "num comps"); + assertEquals("compa", compContainers.get(0).getComponentName(), "comp name"); + assertEquals(2, compContainers.get(0).getContainers().size(), "num containers"); } @Test @@ -74,15 +72,14 @@ public void testFilterWithVersion() throws Exception { GetCompInstancesRequestProto.newBuilder(); reqBuilder.setVersion("v2"); - Assert.assertEquals("num comps", 0, - FilterUtils.filterInstances(sc, reqBuilder.build()).size()); + assertEquals(0, FilterUtils.filterInstances(sc, reqBuilder.build()).size(), + "num comps"); reqBuilder.addAllComponentNames(Lists.newArrayList("compa")) .setVersion("v1").build(); - Assert.assertEquals("num containers", 2, - FilterUtils.filterInstances(sc, reqBuilder.build()).get(0) - .getContainers().size()); + assertEquals(2, FilterUtils.filterInstances(sc, reqBuilder.build()).get(0) + .getContainers().size(), "num containers"); } @Test @@ -96,16 +93,16 @@ public void testFilterWithState() throws Exception { ContainerState.READY.toString())); List compContainers = FilterUtils.filterInstances(sc, reqBuilder.build()); - Assert.assertEquals("num comps", 2, compContainers.size()); + assertEquals(2, compContainers.size(), "num comps"); compContainers.forEach(item -> { - Assert.assertEquals("num containers", 2, item.getContainers().size()); + assertEquals(2, item.getContainers().size(), "num containers"); }); reqBuilder.clearContainerStates(); reqBuilder.addAllContainerStates(Lists.newArrayList( ContainerState.STOPPED.toString())); - Assert.assertEquals("num comps", 0, - FilterUtils.filterInstances(sc, reqBuilder.build()).size()); + assertEquals(0, FilterUtils.filterInstances(sc, reqBuilder.build()).size(), + "num comps"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java index 5c80f85f57752..0c0a53fecd4bd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestServiceApiUtil.java @@ -32,9 +32,9 @@ import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.api.records.ServiceState; import org.apache.hadoop.yarn.service.exceptions.RestApiErrorMessages; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,13 +45,14 @@ import java.util.Collections; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.test.LambdaTestUtils.intercept; import static org.apache.hadoop.yarn.service.conf.RestApiConstants.DEFAULT_UNLIMITED_LIFETIME; import static org.apache.hadoop.yarn.service.exceptions.RestApiErrorMessages.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test for ServiceApiUtil helper methods. @@ -72,12 +73,13 @@ public class TestServiceApiUtil extends ServiceTestUtils { private static final YarnConfiguration CONF_DNS_ENABLED = new YarnConfiguration(); - @BeforeClass + @BeforeAll public static void init() { CONF_DNS_ENABLED.setBoolean(RegistryConstants.KEY_DNS_ENABLED, true); } - @Test(timeout = 90000) + @Test + @Timeout(value = 90) public void testResourceValidation() throws Exception { assertEquals(RegistryConstants.MAX_FQDN_LABEL_LENGTH + 1, LEN_64_STR .length()); @@ -89,7 +91,7 @@ public void testResourceValidation() throws Exception { // no name try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no name"); + fail(EXCEPTION_PREFIX + "service with no name"); } catch (IllegalArgumentException e) { assertEquals(ERROR_APPLICATION_NAME_INVALID, e.getMessage()); } @@ -98,7 +100,7 @@ public void testResourceValidation() throws Exception { // no version try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + " service with no version"); + fail(EXCEPTION_PREFIX + " service with no version"); } catch (IllegalArgumentException e) { assertEquals(String.format(ERROR_APPLICATION_VERSION_INVALID, app.getName()), e.getMessage()); @@ -111,7 +113,7 @@ public void testResourceValidation() throws Exception { app.setName(badName); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with bad name " + badName); + fail(EXCEPTION_PREFIX + "service with bad name " + badName); } catch (IllegalArgumentException e) { } @@ -123,7 +125,7 @@ public void testResourceValidation() throws Exception { app.addComponent(comp); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DEFAULT_DNS); - Assert.fail(EXCEPTION_PREFIX + "service with no launch command"); + fail(EXCEPTION_PREFIX + "service with no launch command"); } catch (IllegalArgumentException e) { assertEquals(RestApiErrorMessages.ERROR_ABSENT_LAUNCH_COMMAND, e.getMessage()); @@ -134,7 +136,7 @@ public void testResourceValidation() throws Exception { .MAX_FQDN_LABEL_LENGTH)); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no launch command"); + fail(EXCEPTION_PREFIX + "service with no launch command"); } catch (IllegalArgumentException e) { assertEquals(RestApiErrorMessages.ERROR_ABSENT_LAUNCH_COMMAND, e.getMessage()); @@ -146,7 +148,7 @@ public void testResourceValidation() throws Exception { app.setResource(res); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no memory"); + fail(EXCEPTION_PREFIX + "service with no memory"); } catch (IllegalArgumentException e) { assertEquals(String.format( RestApiErrorMessages.ERROR_RESOURCE_MEMORY_FOR_COMP_INVALID, @@ -158,7 +160,7 @@ public void testResourceValidation() throws Exception { res.setCpus(-2); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail( + fail( EXCEPTION_PREFIX + "service with invalid no of cpus"); } catch (IllegalArgumentException e) { assertEquals(String.format( @@ -170,9 +172,9 @@ public void testResourceValidation() throws Exception { res.setCpus(2); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no container count"); + fail(EXCEPTION_PREFIX + "service with no container count"); } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage() + assertTrue(e.getMessage() .contains(ERROR_CONTAINERS_COUNT_INVALID)); } @@ -180,7 +182,7 @@ public void testResourceValidation() throws Exception { res.setProfile("hbase_finance_large"); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + fail(EXCEPTION_PREFIX + "service with resource profile along with cpus/memory"); } catch (IllegalArgumentException e) { assertEquals(String.format(RestApiErrorMessages @@ -195,7 +197,7 @@ public void testResourceValidation() throws Exception { res.setMemory(null); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with resource profile only"); + fail(EXCEPTION_PREFIX + "service with resource profile only"); } catch (IllegalArgumentException e) { assertEquals(ERROR_RESOURCE_PROFILE_NOT_SUPPORTED_YET, e.getMessage()); @@ -209,9 +211,9 @@ public void testResourceValidation() throws Exception { // null number of containers try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "null number of containers"); + fail(EXCEPTION_PREFIX + "null number of containers"); } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage() + assertTrue(e.getMessage() .startsWith(ERROR_CONTAINERS_COUNT_INVALID)); } } @@ -236,7 +238,7 @@ public void testArtifacts() throws IOException { app.setComponents(Collections.singletonList(comp)); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no artifact id"); + fail(EXCEPTION_PREFIX + "service with no artifact id"); } catch (IllegalArgumentException e) { assertEquals(String.format(ERROR_ARTIFACT_ID_FOR_COMP_INVALID, compName), e.getMessage()); @@ -246,7 +248,7 @@ public void testArtifacts() throws IOException { artifact.setType(Artifact.TypeEnum.SERVICE); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no artifact id"); + fail(EXCEPTION_PREFIX + "service with no artifact id"); } catch (IllegalArgumentException e) { assertEquals(ERROR_ARTIFACT_ID_INVALID, e.getMessage()); } @@ -255,7 +257,7 @@ public void testArtifacts() throws IOException { artifact.setType(Artifact.TypeEnum.TARBALL); try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with no artifact id"); + fail(EXCEPTION_PREFIX + "service with no artifact id"); } catch (IllegalArgumentException e) { assertEquals(String.format(ERROR_ARTIFACT_ID_FOR_COMP_INVALID, compName), e.getMessage()); @@ -268,7 +270,7 @@ public void testArtifacts() throws IOException { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { LOG.error("service attributes specified should be valid here", e); - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } assertThat(app.getLifetime()).isEqualTo(DEFAULT_UNLIMITED_LIFETIME); @@ -315,7 +317,7 @@ public void testExternalApplication() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } assertEquals(1, app.getComponents().size()); @@ -333,7 +335,7 @@ public void testDuplicateComponents() throws IOException { // duplicate component name fails try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with component collision"); + fail(EXCEPTION_PREFIX + "service with component collision"); } catch (IllegalArgumentException e) { assertEquals("Component name collision: " + compName, e.getMessage()); } @@ -350,7 +352,7 @@ public void testComponentNameSameAsServiceName() throws IOException { //component name same as service name try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "component name matches service name"); + fail(EXCEPTION_PREFIX + "component name matches service name"); } catch (IllegalArgumentException e) { assertEquals("Component name test must not be same as service name test", e.getMessage()); @@ -372,7 +374,7 @@ public void testExternalDuplicateComponent() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } } @@ -390,7 +392,7 @@ public void testExternalComponent() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } assertEquals(1, app.getComponents().size()); @@ -403,7 +405,7 @@ public void testExternalComponent() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } assertEquals(1, app.getComponents().size()); @@ -440,7 +442,7 @@ public void testDependencySorting() throws IOException { c.setDependencies(Arrays.asList("e")); try { verifyDependencySorting(Arrays.asList(a, b, c, d, e)); - Assert.fail(EXCEPTION_PREFIX + "components with dependency cycle"); + fail(EXCEPTION_PREFIX + "components with dependency cycle"); } catch (IllegalArgumentException ex) { assertEquals(String.format( RestApiErrorMessages.ERROR_DEPENDENCY_CYCLE, Arrays.asList(c, d, @@ -453,7 +455,7 @@ public void testDependencySorting() throws IOException { try { ServiceApiUtil.validateAndResolveService(service, sfs, CONF_DEFAULT_DNS); - Assert.fail(EXCEPTION_PREFIX + "components with bad dependencies"); + fail(EXCEPTION_PREFIX + "components with bad dependencies"); } catch (IllegalArgumentException ex) { assertEquals(String.format( RestApiErrorMessages.ERROR_DEPENDENCY_INVALID, "b", "e"), ex @@ -476,7 +478,7 @@ public void testValidateCompName() { for (String name : invalidNames) { try { ServiceApiUtil.validateNameFormat(name, new Configuration()); - Assert.fail(); + fail(); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } @@ -496,7 +498,7 @@ private static void testComponent(SliderFileSystem sfs) // invalid component name fails if dns is enabled try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "service with invalid component name"); + fail(EXCEPTION_PREFIX + "service with invalid component name"); } catch (IllegalArgumentException e) { assertEquals(String.format(RestApiErrorMessages .ERROR_COMPONENT_NAME_INVALID, maxLen, compName), e.getMessage()); @@ -506,7 +508,7 @@ private static void testComponent(SliderFileSystem sfs) try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DEFAULT_DNS); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } compName = LEN_64_STR.substring(0, maxLen); @@ -517,7 +519,7 @@ private static void testComponent(SliderFileSystem sfs) try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } } @@ -534,7 +536,7 @@ public void testPlacementPolicy() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "constraint with no type"); + fail(EXCEPTION_PREFIX + "constraint with no type"); } catch (IllegalArgumentException e) { assertEquals(String.format( RestApiErrorMessages.ERROR_PLACEMENT_POLICY_CONSTRAINT_TYPE_NULL, @@ -546,7 +548,7 @@ public void testPlacementPolicy() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); - Assert.fail(EXCEPTION_PREFIX + "constraint with no scope"); + fail(EXCEPTION_PREFIX + "constraint with no scope"); } catch (IllegalArgumentException e) { assertEquals(String.format( RestApiErrorMessages.ERROR_PLACEMENT_POLICY_CONSTRAINT_SCOPE_NULL, @@ -564,7 +566,7 @@ public void testPlacementPolicy() throws IOException { try { ServiceApiUtil.validateAndResolveService(app, sfs, CONF_DNS_ENABLED); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } } @@ -581,7 +583,7 @@ public void testKerberosPrincipal() throws IOException { try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } // Keytab with no URI scheme should succeed too @@ -589,7 +591,7 @@ public void testKerberosPrincipal() throws IOException { try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } } @@ -602,7 +604,7 @@ public void testKerberosPrincipalNameFormat() throws IOException { try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); - Assert.fail(EXCEPTION_PREFIX + "service with invalid principal name " + + fail(EXCEPTION_PREFIX + "service with invalid principal name " + "format."); } catch (IllegalArgumentException e) { assertEquals( @@ -616,7 +618,7 @@ public void testKerberosPrincipalNameFormat() throws IOException { try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (IllegalArgumentException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } kp.setPrincipalName(null); @@ -624,7 +626,7 @@ public void testKerberosPrincipalNameFormat() throws IOException { try { ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal()); } catch (NullPointerException e) { - Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage()); + fail(NO_EXCEPTION_PREFIX + e.getMessage()); } } @@ -643,8 +645,8 @@ public void testResolveCompsDependency() { expected.add("compb"); expected.add("compa"); for (int i = 0; i < expected.size(); i++) { - Assert.assertEquals("Components are not equal.", expected.get(i), - order.get(i)); + assertEquals(expected.get(i), + order.get(i), "Components are not equal."); } } @@ -663,8 +665,8 @@ public void testResolveCompsDependencyReversed() { expected.add("compa"); expected.add("compb"); for (int i = 0; i < expected.size(); i++) { - Assert.assertEquals("Components are not equal.", expected.get(i), - order.get(i)); + assertEquals(expected.get(i), + order.get(i), "Components are not equal."); } } @@ -686,8 +688,8 @@ public void testResolveCompsCircularDependency() { expected.add("compa"); expected.add("compb"); for (int i = 0; i < expected.size(); i++) { - Assert.assertEquals("Components are not equal.", expected.get(i), - order.get(i)); + assertEquals(expected.get(i), + order.get(i), "Components are not equal."); } } @@ -703,12 +705,13 @@ public void testResolveNoCompsDependency() { expected.add("compa"); expected.add("compb"); for (int i = 0; i < expected.size(); i++) { - Assert.assertEquals("Components are not equal.", expected.get(i), - order.get(i)); + assertEquals(expected.get(i), + order.get(i), "Components are not equal."); } } - @Test(timeout = 1500) + @Test + @Timeout(value = 1) public void testNoServiceDependencies() { Service service = createExampleApplication(); Component compa = createComponent("compa"); @@ -743,7 +746,7 @@ public void run() { Thread.sleep(1000); } catch (InterruptedException e) { } - Assert.assertTrue(thread.isAlive()); + assertTrue(thread.isAlive()); } @Test