YARN-11339. Upgrade Junit 4 to 5 in hadoop-yarn-services-api (#4995)

Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com>
Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
Ashutosh Gupta 2022-10-29 19:07:16 +01:00 committed by GitHub
parent d6a65a4180
commit c096803387
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 251 additions and 232 deletions

View File

@ -197,6 +197,16 @@
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId> <artifactId>hadoop-minicluster</artifactId>
@ -211,7 +221,17 @@
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minikdc</artifactId> <artifactId>hadoop-minikdc</artifactId>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -17,7 +17,7 @@
package org.apache.hadoop.yarn.service; package org.apache.hadoop.yarn.service;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -47,9 +47,9 @@ import org.apache.hadoop.yarn.service.api.records.ServiceState;
import org.apache.hadoop.yarn.service.api.records.ServiceStatus; import org.apache.hadoop.yarn.service.api.records.ServiceStatus;
import org.apache.hadoop.yarn.service.conf.RestApiConstants; import org.apache.hadoop.yarn.service.conf.RestApiConstants;
import org.apache.hadoop.yarn.service.webapp.ApiServer; import org.apache.hadoop.yarn.service.webapp.ApiServer;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
/** /**
@ -61,7 +61,7 @@ public class TestApiServer {
private HttpServletRequest request; private HttpServletRequest request;
private ServiceClientTest mockServerClient; private ServiceClientTest mockServerClient;
@Before @BeforeEach
public void setup() throws Exception { public void setup() throws Exception {
request = Mockito.mock(HttpServletRequest.class); request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getRemoteUser()) Mockito.when(request.getRemoteUser())
@ -74,40 +74,41 @@ public class TestApiServer {
apiServer.setServiceClient(mockServerClient); apiServer.setServiceClient(mockServerClient);
} }
@After @AfterEach
public void teardown() { public void teardown() {
mockServerClient.forceStop(); mockServerClient.forceStop();
} }
@Test @Test
public void testPathAnnotation() { void testPathAnnotation() {
assertNotNull(this.apiServer.getClass().getAnnotation(Path.class)); assertNotNull(this.apiServer.getClass().getAnnotation(Path.class));
assertTrue("The controller has the annotation Path", assertTrue(this.apiServer.getClass().isAnnotationPresent(Path.class),
this.apiServer.getClass().isAnnotationPresent(Path.class)); "The controller has the annotation Path");
final Path path = this.apiServer.getClass() final Path path = this.apiServer.getClass()
.getAnnotation(Path.class); .getAnnotation(Path.class);
assertEquals("The path has /v1 annotation", "/v1", path.value()); assertEquals("/v1", path.value(), "The path has /v1 annotation");
} }
@Test @Test
public void testGetVersion() { void testGetVersion() {
final Response actual = apiServer.getVersion(); final Response actual = apiServer.getVersion();
assertEquals("Version number is", Response.ok().build().getStatus(), assertEquals(Response.ok().build().getStatus(),
actual.getStatus()); actual.getStatus(),
"Version number is");
} }
@Test @Test
public void testBadCreateService() { void testBadCreateService() {
Service service = new Service(); Service service = new Service();
// Test for invalid argument // Test for invalid argument
final Response actual = apiServer.createService(request, service); final Response actual = apiServer.createService(request, service);
assertEquals("Create service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Create service is ");
} }
@Test @Test
public void testGoodCreateService() throws Exception { void testGoodCreateService() throws Exception {
String json = "{\"auths\": " String json = "{\"auths\": "
+ "{\"https://index.docker.io/v1/\": " + "{\"https://index.docker.io/v1/\": "
+ "{\"auth\": \"foobarbaz\"}," + "{\"auth\": \"foobarbaz\"},"
@ -122,13 +123,13 @@ public class TestApiServer {
bw.close(); bw.close();
Service service = ServiceClientTest.buildGoodService(); Service service = ServiceClientTest.buildGoodService();
final Response actual = apiServer.createService(request, service); final Response actual = apiServer.createService(request, service);
assertEquals("Create service is ", assertEquals(Response.status(Status.ACCEPTED).build().getStatus(),
Response.status(Status.ACCEPTED).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Create service is ");
} }
@Test @Test
public void testInternalServerErrorDockerClientConfigMissingCreateService() { void testInternalServerErrorDockerClientConfigMissingCreateService() {
Service service = new Service(); Service service = new Service();
service.setName("jenkins"); service.setName("jenkins");
service.setVersion("v1"); service.setVersion("v1");
@ -149,97 +150,94 @@ public class TestApiServer {
components.add(c); components.add(c);
service.setComponents(components); service.setComponents(components);
final Response actual = apiServer.createService(request, service); final Response actual = apiServer.createService(request, service);
assertEquals("Create service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Create service is ");
} }
@Test @Test
public void testBadGetService() { void testBadGetService() {
final String serviceName = "nonexistent-jenkins"; final String serviceName = "nonexistent-jenkins";
final Response actual = apiServer.getService(request, serviceName); final Response actual = apiServer.getService(request, serviceName);
assertEquals("Get service is ", assertEquals(Response.status(Status.NOT_FOUND).build().getStatus(),
Response.status(Status.NOT_FOUND).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Get service is ");
ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity(); ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Response code don't match", assertEquals(RestApiConstants.ERROR_CODE_APP_NAME_INVALID, serviceStatus.getCode(),
RestApiConstants.ERROR_CODE_APP_NAME_INVALID, serviceStatus.getCode()); "Response code don't match");
assertEquals("Response diagnostics don't match", assertEquals("Service " + serviceName + " not found", serviceStatus.getDiagnostics(),
"Service " + serviceName + " not found", "Response diagnostics don't match");
serviceStatus.getDiagnostics());
} }
@Test @Test
public void testBadGetService2() { void testBadGetService2() {
final Response actual = apiServer.getService(request, null); final Response actual = apiServer.getService(request, null);
assertEquals("Get service is ", assertEquals(Response.status(Status.NOT_FOUND).build().getStatus(), actual.getStatus(),
Response.status(Status.NOT_FOUND).build().getStatus(), "Get service is ");
actual.getStatus());
ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity(); ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Response code don't match", assertEquals(RestApiConstants.ERROR_CODE_APP_NAME_INVALID, serviceStatus.getCode(),
RestApiConstants.ERROR_CODE_APP_NAME_INVALID, serviceStatus.getCode()); "Response code don't match");
assertEquals("Response diagnostics don't match", assertEquals("Service name cannot be null.", serviceStatus.getDiagnostics(),
"Service name cannot be null.", serviceStatus.getDiagnostics()); "Response diagnostics don't match");
} }
@Test @Test
public void testGoodGetService() { void testGoodGetService() {
final Response actual = apiServer.getService(request, "jenkins"); final Response actual = apiServer.getService(request, "jenkins");
assertEquals("Get service is ", assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
Response.status(Status.OK).build().getStatus(), actual.getStatus()); "Get service is ");
} }
@Test @Test
public void testBadDeleteService() { void testBadDeleteService() {
final Response actual = apiServer.deleteService(request, "no-jenkins"); final Response actual = apiServer.deleteService(request, "no-jenkins");
assertEquals("Delete service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Delete service is ");
} }
@Test @Test
public void testBadDeleteService2() { void testBadDeleteService2() {
final Response actual = apiServer.deleteService(request, null); final Response actual = apiServer.deleteService(request, null);
assertEquals("Delete service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Delete service is ");
} }
@Test @Test
public void testBadDeleteService3() { void testBadDeleteService3() {
final Response actual = apiServer.deleteService(request, final Response actual = apiServer.deleteService(request,
"jenkins-doesn't-exist"); "jenkins-doesn't-exist");
assertEquals("Delete service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Delete service is ");
} }
@Test @Test
public void testBadDeleteService4() { void testBadDeleteService4() {
final Response actual = apiServer.deleteService(request, final Response actual = apiServer.deleteService(request,
"jenkins-error-cleaning-registry"); "jenkins-error-cleaning-registry");
assertEquals("Delete service is ", assertEquals(Response.status(Status.INTERNAL_SERVER_ERROR).build().getStatus(),
Response.status(Status.INTERNAL_SERVER_ERROR).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Delete service is ");
} }
@Test @Test
public void testGoodDeleteService() { void testGoodDeleteService() {
final Response actual = apiServer.deleteService(request, "jenkins"); final Response actual = apiServer.deleteService(request, "jenkins");
assertEquals("Delete service is ", assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
Response.status(Status.OK).build().getStatus(), actual.getStatus()); "Delete service is ");
} }
@Test @Test
public void testDeleteStoppedService() { void testDeleteStoppedService() {
final Response actual = apiServer.deleteService(request, final Response actual = apiServer.deleteService(request, "jenkins-already-stopped");
"jenkins-already-stopped"); assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
assertEquals("Delete service is ", "Delete service is ");
Response.status(Status.OK).build().getStatus(), actual.getStatus());
} }
@Test @Test
public void testDecreaseContainerAndStop() { void testDecreaseContainerAndStop() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STOPPED); service.setState(ServiceState.STOPPED);
service.setName("jenkins"); service.setName("jenkins");
@ -260,12 +258,12 @@ public class TestApiServer {
service.setComponents(components); service.setComponents(components);
final Response actual = apiServer.updateService(request, "jenkins", final Response actual = apiServer.updateService(request, "jenkins",
service); service);
assertEquals("update service is ", assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
Response.status(Status.OK).build().getStatus(), actual.getStatus()); "update service is ");
} }
@Test @Test
public void testBadDecreaseContainerAndStop() { void testBadDecreaseContainerAndStop() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STOPPED); service.setState(ServiceState.STOPPED);
service.setName("no-jenkins"); service.setName("no-jenkins");
@ -287,13 +285,13 @@ public class TestApiServer {
System.out.println("before stop"); System.out.println("before stop");
final Response actual = apiServer.updateService(request, "no-jenkins", final Response actual = apiServer.updateService(request, "no-jenkins",
service); service);
assertEquals("flex service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "flex service is ");
} }
@Test @Test
public void testIncreaseContainersAndStart() { void testIncreaseContainersAndStart() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STARTED); service.setState(ServiceState.STARTED);
service.setName("jenkins"); service.setName("jenkins");
@ -314,12 +312,12 @@ public class TestApiServer {
service.setComponents(components); service.setComponents(components);
final Response actual = apiServer.updateService(request, "jenkins", final Response actual = apiServer.updateService(request, "jenkins",
service); service);
assertEquals("flex service is ", assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
Response.status(Status.OK).build().getStatus(), actual.getStatus()); "flex service is ");
} }
@Test @Test
public void testBadStartServices() { void testBadStartServices() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STARTED); service.setState(ServiceState.STARTED);
service.setName("no-jenkins"); service.setName("no-jenkins");
@ -340,13 +338,13 @@ public class TestApiServer {
service.setComponents(components); service.setComponents(components);
final Response actual = apiServer.updateService(request, "no-jenkins", final Response actual = apiServer.updateService(request, "no-jenkins",
service); service);
assertEquals("start service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "start service is ");
} }
@Test @Test
public void testGoodStartServices() { void testGoodStartServices() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STARTED); service.setState(ServiceState.STARTED);
service.setName("jenkins"); service.setName("jenkins");
@ -367,12 +365,12 @@ public class TestApiServer {
service.setComponents(components); service.setComponents(components);
final Response actual = apiServer.updateService(request, "jenkins", final Response actual = apiServer.updateService(request, "jenkins",
service); service);
assertEquals("start service is ", assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
Response.status(Status.OK).build().getStatus(), actual.getStatus()); "start service is ");
} }
@Test @Test
public void testBadStopServices() { void testBadStopServices() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STOPPED); service.setState(ServiceState.STOPPED);
service.setName("no-jenkins"); service.setName("no-jenkins");
@ -394,25 +392,25 @@ public class TestApiServer {
System.out.println("before stop"); System.out.println("before stop");
final Response actual = apiServer.updateService(request, "no-jenkins", final Response actual = apiServer.updateService(request, "no-jenkins",
service); service);
assertEquals("stop service is ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "stop service is ");
} }
@Test @Test
public void testGoodStopServices() { void testGoodStopServices() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STOPPED); service.setState(ServiceState.STOPPED);
service.setName("jenkins"); service.setName("jenkins");
System.out.println("before stop"); System.out.println("before stop");
final Response actual = apiServer.updateService(request, "jenkins", final Response actual = apiServer.updateService(request, "jenkins",
service); service);
assertEquals("stop service is ", assertEquals(Response.status(Status.OK).build().getStatus(), actual.getStatus(),
Response.status(Status.OK).build().getStatus(), actual.getStatus()); "stop service is ");
} }
@Test @Test
public void testBadSecondStopServices() throws Exception { void testBadSecondStopServices() throws Exception {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STOPPED); service.setState(ServiceState.STOPPED);
service.setName("jenkins-second-stop"); service.setName("jenkins-second-stop");
@ -420,17 +418,17 @@ public class TestApiServer {
System.out.println("before second stop"); System.out.println("before second stop");
final Response actual = apiServer.updateService(request, final Response actual = apiServer.updateService(request,
"jenkins-second-stop", service); "jenkins-second-stop", service);
assertEquals("stop service should have thrown 400 Bad Request: ", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "stop service should have thrown 400 Bad Request: ");
ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity(); ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Stop service should have failed with service already stopped", assertEquals("Service jenkins-second-stop is already stopped",
"Service jenkins-second-stop is already stopped", serviceStatus.getDiagnostics(),
serviceStatus.getDiagnostics()); "Stop service should have failed with service already stopped");
} }
@Test @Test
public void testUpdateService() { void testUpdateService() {
Service service = new Service(); Service service = new Service();
service.setState(ServiceState.STARTED); service.setState(ServiceState.STARTED);
service.setName("no-jenkins"); service.setName("no-jenkins");
@ -452,72 +450,71 @@ public class TestApiServer {
System.out.println("before stop"); System.out.println("before stop");
final Response actual = apiServer.updateService(request, "no-jenkins", final Response actual = apiServer.updateService(request, "no-jenkins",
service); service);
assertEquals("update service is ", assertEquals(Response.status(Status.BAD_REQUEST)
Response.status(Status.BAD_REQUEST) .build().getStatus(), actual.getStatus(), "update service is ");
.build().getStatus(), actual.getStatus());
} }
@Test @Test
public void testUpdateComponent() { void testUpdateComponent() {
Response actual = apiServer.updateComponent(request, "jenkins", Response actual = apiServer.updateComponent(request, "jenkins",
"jenkins-master", null); "jenkins-master", null);
ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity(); ServiceStatus serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Update component should have failed with 400 bad request", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Update component should have failed with 400 bad request");
assertEquals("Update component should have failed with no data error", assertEquals("No component data provided", serviceStatus.getDiagnostics(),
"No component data provided", serviceStatus.getDiagnostics()); "Update component should have failed with no data error");
Component comp = new Component(); Component comp = new Component();
actual = apiServer.updateComponent(request, "jenkins", "jenkins-master", actual = apiServer.updateComponent(request, "jenkins", "jenkins-master",
comp); comp);
serviceStatus = (ServiceStatus) actual.getEntity(); serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Update component should have failed with 400 bad request", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Update component should have failed with 400 bad request");
assertEquals("Update component should have failed with no count error", assertEquals("No container count provided", serviceStatus.getDiagnostics(),
"No container count provided", serviceStatus.getDiagnostics()); "Update component should have failed with no count error");
comp.setNumberOfContainers(-1L); comp.setNumberOfContainers(-1L);
actual = apiServer.updateComponent(request, "jenkins", "jenkins-master", actual = apiServer.updateComponent(request, "jenkins", "jenkins-master",
comp); comp);
serviceStatus = (ServiceStatus) actual.getEntity(); serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Update component should have failed with 400 bad request", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Update component should have failed with 400 bad request");
assertEquals("Update component should have failed with no count error", assertEquals("Invalid number of containers specified -1", serviceStatus.getDiagnostics(),
"Invalid number of containers specified -1", serviceStatus.getDiagnostics()); "Update component should have failed with no count error");
comp.setName("jenkins-slave"); comp.setName("jenkins-slave");
comp.setNumberOfContainers(1L); comp.setNumberOfContainers(1L);
actual = apiServer.updateComponent(request, "jenkins", "jenkins-master", actual = apiServer.updateComponent(request, "jenkins", "jenkins-master",
comp); comp);
serviceStatus = (ServiceStatus) actual.getEntity(); serviceStatus = (ServiceStatus) actual.getEntity();
assertEquals("Update component should have failed with 400 bad request", assertEquals(Response.status(Status.BAD_REQUEST).build().getStatus(),
Response.status(Status.BAD_REQUEST).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Update component should have failed with 400 bad request");
assertEquals( assertEquals(
"Update component should have failed with component name mismatch "
+ "error",
"Component name in the request object (jenkins-slave) does not match " "Component name in the request object (jenkins-slave) does not match "
+ "that in the URI path (jenkins-master)", + "that in the URI path (jenkins-master)",
serviceStatus.getDiagnostics()); serviceStatus.getDiagnostics(),
"Update component should have failed with component name mismatch "
+ "error");
} }
@Test @Test
public void testInitiateUpgrade() { void testInitiateUpgrade() {
Service goodService = ServiceClientTest.buildLiveGoodService(); Service goodService = ServiceClientTest.buildLiveGoodService();
goodService.setVersion("v2"); goodService.setVersion("v2");
goodService.setState(ServiceState.UPGRADING); goodService.setState(ServiceState.UPGRADING);
final Response actual = apiServer.updateService(request, final Response actual = apiServer.updateService(request,
goodService.getName(), goodService); goodService.getName(), goodService);
assertEquals("Initiate upgrade is ", assertEquals(Response.status(Status.ACCEPTED).build().getStatus(),
Response.status(Status.ACCEPTED).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Initiate upgrade is ");
} }
@Test @Test
public void testUpgradeSingleInstance() { void testUpgradeSingleInstance() {
Service goodService = ServiceClientTest.buildLiveGoodService(); Service goodService = ServiceClientTest.buildLiveGoodService();
Component comp = goodService.getComponents().iterator().next(); Component comp = goodService.getComponents().iterator().next();
Container container = comp.getContainers().iterator().next(); Container container = comp.getContainers().iterator().next();
@ -536,13 +533,13 @@ public class TestApiServer {
final Response actual = apiServer.updateComponentInstance(request, final Response actual = apiServer.updateComponentInstance(request,
goodService.getName(), comp.getName(), goodService.getName(), comp.getName(),
container.getComponentInstanceName(), container); container.getComponentInstanceName(), container);
assertEquals("Instance upgrade is ", assertEquals(Response.status(Status.ACCEPTED).build().getStatus(),
Response.status(Status.ACCEPTED).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Instance upgrade is ");
} }
@Test @Test
public void testUpgradeMultipleInstances() { void testUpgradeMultipleInstances() {
Service goodService = ServiceClientTest.buildLiveGoodService(); Service goodService = ServiceClientTest.buildLiveGoodService();
Component comp = goodService.getComponents().iterator().next(); Component comp = goodService.getComponents().iterator().next();
comp.getContainers().forEach(container -> comp.getContainers().forEach(container ->
@ -563,13 +560,13 @@ public class TestApiServer {
final Response actual = apiServer.updateComponentInstances(request, final Response actual = apiServer.updateComponentInstances(request,
goodService.getName(), comp.getContainers()); goodService.getName(), comp.getContainers());
assertEquals("Instance upgrade is ", assertEquals(Response.status(Status.ACCEPTED).build().getStatus(),
Response.status(Status.ACCEPTED).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Instance upgrade is ");
} }
@Test @Test
public void testUpgradeComponent() { void testUpgradeComponent() {
Service goodService = ServiceClientTest.buildLiveGoodService(); Service goodService = ServiceClientTest.buildLiveGoodService();
Component comp = goodService.getComponents().iterator().next(); Component comp = goodService.getComponents().iterator().next();
comp.setState(ComponentState.UPGRADING); comp.setState(ComponentState.UPGRADING);
@ -589,13 +586,13 @@ public class TestApiServer {
final Response actual = apiServer.updateComponent(request, final Response actual = apiServer.updateComponent(request,
goodService.getName(), comp.getName(), comp); goodService.getName(), comp.getName(), comp);
assertEquals("Component upgrade is ", assertEquals(Response.status(Status.ACCEPTED).build().getStatus(),
Response.status(Status.ACCEPTED).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Component upgrade is ");
} }
@Test @Test
public void testUpgradeMultipleComps() { void testUpgradeMultipleComps() {
Service goodService = ServiceClientTest.buildLiveGoodService(); Service goodService = ServiceClientTest.buildLiveGoodService();
goodService.getComponents().forEach(comp -> goodService.getComponents().forEach(comp ->
comp.setState(ComponentState.UPGRADING)); comp.setState(ComponentState.UPGRADING));
@ -616,8 +613,8 @@ public class TestApiServer {
final Response actual = apiServer.updateComponents(request, final Response actual = apiServer.updateComponents(request,
goodService.getName(), goodService.getComponents()); goodService.getName(), goodService.getComponents());
assertEquals("Component upgrade is ", assertEquals(Response.status(Status.ACCEPTED).build().getStatus(),
Response.status(Status.ACCEPTED).build().getStatus(), actual.getStatus(),
actual.getStatus()); "Component upgrade is ");
} }
} }

View File

@ -27,16 +27,19 @@ import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.service.api.records.Service; import org.apache.hadoop.yarn.service.api.records.Service;
import org.apache.hadoop.yarn.service.client.ServiceClient; import org.apache.hadoop.yarn.service.client.ServiceClient;
import org.apache.hadoop.yarn.service.conf.YarnServiceConstants; import org.apache.hadoop.yarn.service.conf.YarnServiceConstants;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Rule; import org.junit.jupiter.api.Timeout;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
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 java.io.IOException; import java.io.IOException;
/** /**
@ -47,22 +50,20 @@ public class TestCleanupAfterKill extends ServiceTestUtils {
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(TestCleanupAfterKill.class); LoggerFactory.getLogger(TestCleanupAfterKill.class);
@Rule @BeforeEach
public TemporaryFolder tmpFolder = new TemporaryFolder();
@Before
public void setup() throws Exception { public void setup() throws Exception {
File tmpYarnDir = new File("target", "tmp"); File tmpYarnDir = new File("target", "tmp");
FileUtils.deleteQuietly(tmpYarnDir); FileUtils.deleteQuietly(tmpYarnDir);
} }
@After @AfterEach
public void tearDown() throws IOException { public void tearDown() throws IOException {
shutdown(); shutdown();
} }
@Test(timeout = 200000) @Test
public void testRegistryCleanedOnLifetimeExceeded() throws Exception { @Timeout(200000)
void testRegistryCleanedOnLifetimeExceeded() throws Exception {
setupInternal(NUM_NMS); setupInternal(NUM_NMS);
ServiceClient client = createClient(getConf()); ServiceClient client = createClient(getConf());
Service exampleApp = createExampleApplication(); Service exampleApp = createExampleApplication();
@ -71,8 +72,8 @@ public class TestCleanupAfterKill extends ServiceTestUtils {
waitForServiceToBeStable(client, exampleApp); waitForServiceToBeStable(client, exampleApp);
String serviceZKPath = RegistryUtils.servicePath(RegistryUtils String serviceZKPath = RegistryUtils.servicePath(RegistryUtils
.currentUser(), YarnServiceConstants.APP_TYPE, exampleApp.getName()); .currentUser(), YarnServiceConstants.APP_TYPE, exampleApp.getName());
Assert.assertTrue("Registry ZK service path doesn't exist", assertTrue(getCuratorService().zkPathExists(serviceZKPath),
getCuratorService().zkPathExists(serviceZKPath)); "Registry ZK service path doesn't exist");
// wait for app to be killed by RM // wait for app to be killed by RM
ApplicationId exampleAppId = ApplicationId.fromString(exampleApp.getId()); ApplicationId exampleAppId = ApplicationId.fromString(exampleApp.getId());
@ -85,10 +86,10 @@ public class TestCleanupAfterKill extends ServiceTestUtils {
throw new RuntimeException("while waiting", e); throw new RuntimeException("while waiting", e);
} }
}, 2000, 200000); }, 2000, 200000);
Assert.assertFalse("Registry ZK service path still exists after killed", assertFalse(getCuratorService().zkPathExists(serviceZKPath),
getCuratorService().zkPathExists(serviceZKPath)); "Registry ZK service path still exists after killed");
LOG.info("Destroy the service"); LOG.info("Destroy the service");
Assert.assertEquals(0, client.actionDestroy(exampleApp.getName())); assertEquals(0, client.actionDestroy(exampleApp.getName()));
} }
} }

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.hadoop.yarn.service.client; package org.apache.hadoop.yarn.service.client;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -35,9 +35,10 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.*; import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.*;
/** /**
@ -88,7 +89,7 @@ public class TestApiServiceClient {
} }
@BeforeClass @BeforeAll
public static void setup() throws Exception { public static void setup() throws Exception {
server = new Server(8088); server = new Server(8088);
((QueuedThreadPool)server.getThreadPool()).setMaxThreads(20); ((QueuedThreadPool)server.getThreadPool()).setMaxThreads(20);
@ -112,13 +113,13 @@ public class TestApiServiceClient {
badAsc.serviceInit(conf2); badAsc.serviceInit(conf2);
} }
@AfterClass @AfterAll
public static void tearDown() throws Exception { public static void tearDown() throws Exception {
server.stop(); server.stop();
} }
@Test @Test
public void testGetRMWebAddress() throws Exception { void testGetRMWebAddress() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
conf.set(YarnConfiguration.RM_HA_IDS, "rm1"); conf.set(YarnConfiguration.RM_HA_IDS, "rm1");
@ -129,17 +130,17 @@ public class TestApiServiceClient {
String diagnosticsMsg = null; String diagnosticsMsg = null;
try { try {
String rmWebAddress = asc1.getRMWebAddress(); String rmWebAddress = asc1.getRMWebAddress();
} catch (IOException e){ } catch (IOException e) {
exceptionCaught = true; exceptionCaught = true;
diagnosticsMsg = e.getMessage(); diagnosticsMsg = e.getMessage();
} }
assertTrue("ApiServiceClient failed to throw exception", exceptionCaught); assertTrue(exceptionCaught, "ApiServiceClient failed to throw exception");
assertTrue("Exception Message does not match", assertTrue(diagnosticsMsg.contains("Error connecting to localhost:0"),
diagnosticsMsg.contains("Error connecting to localhost:0")); "Exception Message does not match");
} }
@Test @Test
public void testLaunch() { void testLaunch() {
String fileName = "target/test-classes/example-app.json"; String fileName = "target/test-classes/example-app.json";
String appName = "example-app"; String appName = "example-app";
long lifetime = 3600L; long lifetime = 3600L;
@ -153,7 +154,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testBadLaunch() { void testBadLaunch() {
String fileName = "unknown_file"; String fileName = "unknown_file";
String appName = "unknown_app"; String appName = "unknown_app";
long lifetime = 3600L; long lifetime = 3600L;
@ -167,19 +168,18 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testStatus() { void testStatus() {
String appName = "nonexistent-app"; String appName = "nonexistent-app";
try { try {
String result = asc.getStatusString(appName); String result = asc.getStatusString(appName);
assertEquals("Status reponse don't match", assertEquals(" Service " + appName + " not found", result, "Status reponse don't match");
" Service " + appName + " not found", result);
} catch (IOException | YarnException e) { } catch (IOException | YarnException e) {
fail(); fail();
} }
} }
@Test @Test
public void testStop() { void testStop() {
String appName = "example-app"; String appName = "example-app";
try { try {
int result = asc.actionStop(appName); int result = asc.actionStop(appName);
@ -190,7 +190,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testBadStop() { void testBadStop() {
String appName = "unknown_app"; String appName = "unknown_app";
try { try {
int result = badAsc.actionStop(appName); int result = badAsc.actionStop(appName);
@ -201,7 +201,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testStart() { void testStart() {
String appName = "example-app"; String appName = "example-app";
try { try {
int result = asc.actionStart(appName); int result = asc.actionStart(appName);
@ -212,7 +212,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testBadStart() { void testBadStart() {
String appName = "unknown_app"; String appName = "unknown_app";
try { try {
int result = badAsc.actionStart(appName); int result = badAsc.actionStart(appName);
@ -223,7 +223,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testSave() { void testSave() {
String fileName = "target/test-classes/example-app.json"; String fileName = "target/test-classes/example-app.json";
String appName = "example-app"; String appName = "example-app";
long lifetime = 3600L; long lifetime = 3600L;
@ -237,7 +237,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testBadSave() { void testBadSave() {
String fileName = "unknown_file"; String fileName = "unknown_file";
String appName = "unknown_app"; String appName = "unknown_app";
long lifetime = 3600L; long lifetime = 3600L;
@ -251,7 +251,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testFlex() { void testFlex() {
String appName = "example-app"; String appName = "example-app";
HashMap<String, String> componentCounts = new HashMap<String, String>(); HashMap<String, String> componentCounts = new HashMap<String, String>();
try { try {
@ -263,7 +263,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testBadFlex() { void testBadFlex() {
String appName = "unknown_app"; String appName = "unknown_app";
HashMap<String, String> componentCounts = new HashMap<String, String>(); HashMap<String, String> componentCounts = new HashMap<String, String>();
try { try {
@ -275,7 +275,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testDestroy() { void testDestroy() {
String appName = "example-app"; String appName = "example-app";
try { try {
int result = asc.actionDestroy(appName); int result = asc.actionDestroy(appName);
@ -286,7 +286,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testBadDestroy() { void testBadDestroy() {
String appName = "unknown_app"; String appName = "unknown_app";
try { try {
int result = badAsc.actionDestroy(appName); int result = badAsc.actionDestroy(appName);
@ -297,7 +297,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testInitiateServiceUpgrade() { void testInitiateServiceUpgrade() {
String appName = "example-app"; String appName = "example-app";
String upgradeFileName = "target/test-classes/example-app.json"; String upgradeFileName = "target/test-classes/example-app.json";
try { try {
@ -309,7 +309,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testInstancesUpgrade() { void testInstancesUpgrade() {
String appName = "example-app"; String appName = "example-app";
try { try {
int result = asc.actionUpgradeInstances(appName, Lists.newArrayList( int result = asc.actionUpgradeInstances(appName, Lists.newArrayList(
@ -321,7 +321,7 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testComponentsUpgrade() { void testComponentsUpgrade() {
String appName = "example-app"; String appName = "example-app";
try { try {
int result = asc.actionUpgradeComponents(appName, Lists.newArrayList( int result = asc.actionUpgradeComponents(appName, Lists.newArrayList(
@ -333,12 +333,12 @@ public class TestApiServiceClient {
} }
@Test @Test
public void testNoneSecureApiClient() throws IOException { void testNoneSecureApiClient() throws IOException {
String url = asc.getServicePath("/foobar"); String url = asc.getServicePath("/foobar");
assertTrue("User.name flag is missing in service path.", assertTrue(url.contains("user.name"),
url.contains("user.name")); "User.name flag is missing in service path.");
assertTrue("User.name flag is not matching JVM user.", assertTrue(url.contains(System.getProperty("user.name")),
url.contains(System.getProperty("user.name"))); "User.name flag is not matching JVM user.");
} }
} }

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.yarn.service.client; package org.apache.hadoop.yarn.service.client;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -49,9 +49,9 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Test Spnego Client Login. * Test Spnego Client Login.
@ -129,8 +129,9 @@ public class TestSecureApiServiceClient extends KerberosSecurityTestcase {
} }
} }
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
startMiniKdc();
keytabFile = new File(getWorkDir(), "keytab"); keytabFile = new File(getWorkDir(), "keytab");
getKdc().createPrincipal(keytabFile, clientPrincipal, server1Principal, getKdc().createPrincipal(keytabFile, clientPrincipal, server1Principal,
server2Principal); server2Principal);
@ -163,13 +164,14 @@ public class TestSecureApiServiceClient extends KerberosSecurityTestcase {
asc.serviceInit(testConf); asc.serviceInit(testConf);
} }
@After @AfterEach
public void tearDown() throws Exception { public void tearDown() throws Exception {
server.stop(); server.stop();
stopMiniKdc();
} }
@Test @Test
public void testHttpSpnegoChallenge() throws Exception { void testHttpSpnegoChallenge() throws Exception {
UserGroupInformation.loginUserFromKeytab(clientPrincipal, keytabFile UserGroupInformation.loginUserFromKeytab(clientPrincipal, keytabFile
.getCanonicalPath()); .getCanonicalPath());
String challenge = YarnClientUtils.generateToken("localhost"); String challenge = YarnClientUtils.generateToken("localhost");
@ -177,7 +179,7 @@ public class TestSecureApiServiceClient extends KerberosSecurityTestcase {
} }
@Test @Test
public void testAuthorizationHeader() throws Exception { void testAuthorizationHeader() throws Exception {
UserGroupInformation.loginUserFromKeytab(clientPrincipal, keytabFile UserGroupInformation.loginUserFromKeytab(clientPrincipal, keytabFile
.getCanonicalPath()); .getCanonicalPath());
String rmAddress = asc.getRMWebAddress(); String rmAddress = asc.getRMWebAddress();

View File

@ -29,14 +29,16 @@ import org.apache.hadoop.yarn.service.api.records.Service;
import org.apache.hadoop.yarn.service.conf.SliderExitCodes; import org.apache.hadoop.yarn.service.conf.SliderExitCodes;
import org.apache.hadoop.yarn.service.conf.YarnServiceConf; import org.apache.hadoop.yarn.service.conf.YarnServiceConf;
import org.apache.hadoop.yarn.service.exceptions.SliderException; import org.apache.hadoop.yarn.service.exceptions.SliderException;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -44,8 +46,6 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.fail;
/** /**
* Test class for system service manager. * Test class for system service manager.
*/ */
@ -62,7 +62,7 @@ public class TestSystemServiceManagerImpl {
private static Map<String, Set<String>> savedServices = new HashMap<>(); private static Map<String, Set<String>> savedServices = new HashMap<>();
private static Map<String, Set<String>> submittedServices = new HashMap<>(); private static Map<String, Set<String>> submittedServices = new HashMap<>();
@Before @BeforeEach
public void setup() { public void setup() {
File file = new File( File file = new File(
getClass().getClassLoader().getResource(resourcePath).getFile()); getClass().getClassLoader().getResource(resourcePath).getFile());
@ -80,30 +80,30 @@ public class TestSystemServiceManagerImpl {
constructUserService(users[1], "example-app1", "example-app2"); constructUserService(users[1], "example-app1", "example-app2");
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
systemService.stop(); systemService.stop();
} }
@Test @Test
public void testSystemServiceSubmission() throws Exception { void testSystemServiceSubmission() throws Exception {
systemService.start(); systemService.start();
/* verify for ignored sevices count */ /* verify for ignored sevices count */
Map<String, Integer> ignoredUserServices = Map<String, Integer> ignoredUserServices =
systemService.getIgnoredUserServices(); systemService.getIgnoredUserServices();
Assert.assertEquals(1, ignoredUserServices.size()); assertEquals(1, ignoredUserServices.size());
Assert.assertTrue("User user1 doesn't exist.", assertTrue(ignoredUserServices.containsKey(users[0]),
ignoredUserServices.containsKey(users[0])); "User user1 doesn't exist.");
int count = ignoredUserServices.get(users[0]); int count = ignoredUserServices.get(users[0]);
Assert.assertEquals(1, count); assertEquals(1, count);
Assert.assertEquals(1, assertEquals(1,
systemService.getBadFileNameExtensionSkipCounter()); systemService.getBadFileNameExtensionSkipCounter());
Assert.assertEquals(1, systemService.getBadDirSkipCounter()); assertEquals(1, systemService.getBadDirSkipCounter());
Map<String, Set<Service>> userServices = Map<String, Set<Service>> userServices =
systemService.getSyncUserServices(); systemService.getSyncUserServices();
Assert.assertEquals(loadedServices.size(), userServices.size()); assertEquals(loadedServices.size(), userServices.size());
verifyForScannedUserServices(userServices); verifyForScannedUserServices(userServices);
verifyForLaunchedUserServices(); verifyForLaunchedUserServices();
@ -123,13 +123,12 @@ public class TestSystemServiceManagerImpl {
for (String user : users) { for (String user : users) {
Set<Service> services = userServices.get(user); Set<Service> services = userServices.get(user);
Set<String> serviceNames = loadedServices.get(user); Set<String> serviceNames = loadedServices.get(user);
Assert.assertEquals(serviceNames.size(), services.size()); assertEquals(serviceNames.size(), services.size());
Iterator<Service> iterator = services.iterator(); Iterator<Service> iterator = services.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Service next = iterator.next(); Service next = iterator.next();
Assert.assertTrue( assertTrue(serviceNames.contains(next.getName()),
"Service name doesn't exist in expected userService " "Service name doesn't exist in expected userService " + serviceNames);
+ serviceNames, serviceNames.contains(next.getName()));
} }
} }
} }
@ -203,19 +202,19 @@ public class TestSystemServiceManagerImpl {
} }
private void verifyForLaunchedUserServices() { private void verifyForLaunchedUserServices() {
Assert.assertEquals(loadedServices.size(), submittedServices.size()); assertEquals(loadedServices.size(), submittedServices.size());
for (Map.Entry<String, Set<String>> entry : submittedServices.entrySet()) { for (Map.Entry<String, Set<String>> entry : submittedServices.entrySet()) {
String user = entry.getKey(); String user = entry.getKey();
Set<String> serviceSet = entry.getValue(); Set<String> serviceSet = entry.getValue();
Assert.assertTrue(loadedServices.containsKey(user)); assertTrue(loadedServices.containsKey(user));
Set<String> services = loadedServices.get(user); Set<String> services = loadedServices.get(user);
Assert.assertEquals(services.size(), serviceSet.size()); assertEquals(services.size(), serviceSet.size());
Assert.assertTrue(services.containsAll(serviceSet)); assertTrue(services.containsAll(serviceSet));
} }
} }
@Test @Test
public void testFileSystemCloseWhenCleanUpService() throws Exception { void testFileSystemCloseWhenCleanUpService() throws Exception {
FileSystem fs = null; FileSystem fs = null;
Path path = new Path("/tmp/servicedir"); Path path = new Path("/tmp/servicedir");