Skip to content

Commit

Permalink
YARN-10793. Upgrade Junit from 4 to 5 in hadoop-yarn-server-applicati…
Browse files Browse the repository at this point in the history
…onhistoryservice (apache#4603)

Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com>
Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
  • Loading branch information
2 people authored and HarshitGupta11 committed Nov 28, 2022
1 parent 5979843 commit 6523b63
Show file tree
Hide file tree
Showing 21 changed files with 1,391 additions and 1,356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<yarn.basedir>${project.parent.parent.basedir}</yarn.basedir>
</properties>



<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down Expand Up @@ -194,6 +196,21 @@
<artifactId>bcprov-jdk15on</artifactId>
<scope>test</scope>
</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>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.io.IOException;
import java.util.List;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse;
Expand Down Expand Up @@ -49,17 +52,19 @@
import org.apache.hadoop.yarn.server.timeline.TimelineDataManager;
import org.apache.hadoop.yarn.server.timeline.TimelineStore;
import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

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;

public class TestApplicationHistoryClientService {

private static ApplicationHistoryClientService clientService;
private static TimelineDataManager dataManager;
private final static int MAX_APPS = 2;

@BeforeClass
@BeforeAll
public static void setup() throws Exception {
Configuration conf = new YarnConfiguration();
TimelineStore store =
Expand All @@ -78,7 +83,7 @@ public static void setup() throws Exception {
}

@Test
public void testApplicationNotFound() throws IOException, YarnException {
void testApplicationNotFound() throws IOException, YarnException {
ApplicationId appId = null;
appId = ApplicationId.newInstance(0, MAX_APPS + 1);
GetApplicationReportRequest request =
Expand All @@ -87,18 +92,18 @@ public void testApplicationNotFound() throws IOException, YarnException {
@SuppressWarnings("unused")
GetApplicationReportResponse response =
clientService.getApplicationReport(request);
Assert.fail("Exception should have been thrown before we reach here.");
fail("Exception should have been thrown before we reach here.");
} catch (ApplicationNotFoundException e) {
//This exception is expected.
Assert.assertTrue(e.getMessage().contains(
assertTrue(e.getMessage().contains(
"doesn't exist in the timeline store"));
} catch (Exception e) {
Assert.fail("Undesired exception caught");
fail("Undesired exception caught");
}
}

@Test
public void testApplicationAttemptNotFound() throws IOException, YarnException {
void testApplicationAttemptNotFound() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, MAX_APPS + 1);
Expand All @@ -108,95 +113,95 @@ public void testApplicationAttemptNotFound() throws IOException, YarnException {
@SuppressWarnings("unused")
GetApplicationAttemptReportResponse response =
clientService.getApplicationAttemptReport(request);
Assert.fail("Exception should have been thrown before we reach here.");
fail("Exception should have been thrown before we reach here.");
} catch (ApplicationAttemptNotFoundException e) {
//This Exception is expected
System.out.println(e.getMessage());
Assert.assertTrue(e.getMessage().contains(
assertTrue(e.getMessage().contains(
"doesn't exist in the timeline store"));
} catch (Exception e) {
Assert.fail("Undesired exception caught");
fail("Undesired exception caught");
}
}

@Test
public void testContainerNotFound() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1);
ContainerId containerId = ContainerId.newContainerId(appAttemptId,
MAX_APPS + 1);
GetContainerReportRequest request =
GetContainerReportRequest.newInstance(containerId);
try {
@SuppressWarnings("unused")
GetContainerReportResponse response =
clientService.getContainerReport(request);
} catch (ContainerNotFoundException e) {
//This exception is expected
Assert.assertTrue(e.getMessage().contains(
"doesn't exist in the timeline store"));
} catch (Exception e) {
Assert.fail("Undesired exception caught");
}
}
void testContainerNotFound() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1);
ContainerId containerId = ContainerId.newContainerId(appAttemptId,
MAX_APPS + 1);
GetContainerReportRequest request =
GetContainerReportRequest.newInstance(containerId);
try {
@SuppressWarnings("unused")
GetContainerReportResponse response =
clientService.getContainerReport(request);
} catch (ContainerNotFoundException e) {
//This exception is expected
assertTrue(e.getMessage().contains(
"doesn't exist in the timeline store"));
} catch (Exception e) {
fail("Undesired exception caught");
}
}

@Test
public void testApplicationReport() throws IOException, YarnException {
void testApplicationReport() throws IOException, YarnException {
ApplicationId appId = null;
appId = ApplicationId.newInstance(0, 1);
GetApplicationReportRequest request =
GetApplicationReportRequest.newInstance(appId);
GetApplicationReportResponse response =
clientService.getApplicationReport(request);
ApplicationReport appReport = response.getApplicationReport();
Assert.assertNotNull(appReport);
Assert.assertEquals(123, appReport.getApplicationResourceUsageReport()
assertNotNull(appReport);
assertEquals(123, appReport.getApplicationResourceUsageReport()
.getMemorySeconds());
Assert.assertEquals(345, appReport.getApplicationResourceUsageReport()
assertEquals(345, appReport.getApplicationResourceUsageReport()
.getVcoreSeconds());
Assert.assertEquals("application_0_0001", appReport.getApplicationId()
.toString());
Assert.assertEquals("test app type",
assertEquals("application_0_0001", appReport.getApplicationId()
.toString());
assertEquals("test app type",
appReport.getApplicationType().toString());
Assert.assertEquals("test queue", appReport.getQueue().toString());
assertEquals("test queue", appReport.getQueue().toString());
}

@Test
public void testApplications() throws IOException, YarnException {
void testApplications() throws IOException, YarnException {
ApplicationId appId = null;
appId = ApplicationId.newInstance(0, 1);
ApplicationId appId1 = ApplicationId.newInstance(0, 2);
GetApplicationsRequest request = GetApplicationsRequest.newInstance();
GetApplicationsResponse response =
clientService.getApplications(request);
List<ApplicationReport> appReport = response.getApplicationList();
Assert.assertNotNull(appReport);
Assert.assertEquals(appId, appReport.get(1).getApplicationId());
Assert.assertEquals(appId1, appReport.get(0).getApplicationId());
assertNotNull(appReport);
assertEquals(appId, appReport.get(1).getApplicationId());
assertEquals(appId1, appReport.get(0).getApplicationId());

// Create a historyManager, and set the max_apps can be loaded
// as 1.
Configuration conf = new YarnConfiguration();
conf.setLong(YarnConfiguration.APPLICATION_HISTORY_MAX_APPS, 1);
ApplicationHistoryManagerOnTimelineStore historyManager2 =
new ApplicationHistoryManagerOnTimelineStore(dataManager,
new ApplicationACLsManager(conf));
new ApplicationACLsManager(conf));
historyManager2.init(conf);
historyManager2.start();
@SuppressWarnings("resource")
ApplicationHistoryClientService clientService2 =
new ApplicationHistoryClientService(historyManager2);
response = clientService2.getApplications(request);
appReport = response.getApplicationList();
Assert.assertNotNull(appReport);
Assert.assertTrue(appReport.size() == 1);
assertNotNull(appReport);
assertTrue(appReport.size() == 1);
// Expected to get the appReport for application with appId1
Assert.assertEquals(appId1, appReport.get(0).getApplicationId());
assertEquals(appId1, appReport.get(0).getApplicationId());
}

@Test
public void testApplicationAttemptReport() throws IOException, YarnException {
void testApplicationAttemptReport() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1);
Expand All @@ -206,13 +211,13 @@ public void testApplicationAttemptReport() throws IOException, YarnException {
clientService.getApplicationAttemptReport(request);
ApplicationAttemptReport attemptReport =
response.getApplicationAttemptReport();
Assert.assertNotNull(attemptReport);
Assert.assertEquals("appattempt_0_0001_000001", attemptReport
.getApplicationAttemptId().toString());
assertNotNull(attemptReport);
assertEquals("appattempt_0_0001_000001", attemptReport
.getApplicationAttemptId().toString());
}

@Test
public void testApplicationAttempts() throws IOException, YarnException {
void testApplicationAttempts() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1);
Expand All @@ -224,15 +229,15 @@ public void testApplicationAttempts() throws IOException, YarnException {
clientService.getApplicationAttempts(request);
List<ApplicationAttemptReport> attemptReports =
response.getApplicationAttemptList();
Assert.assertNotNull(attemptReports);
Assert.assertEquals(appAttemptId, attemptReports.get(0)
.getApplicationAttemptId());
Assert.assertEquals(appAttemptId1, attemptReports.get(1)
.getApplicationAttemptId());
assertNotNull(attemptReports);
assertEquals(appAttemptId, attemptReports.get(0)
.getApplicationAttemptId());
assertEquals(appAttemptId1, attemptReports.get(1)
.getApplicationAttemptId());
}

@Test
public void testContainerReport() throws IOException, YarnException {
void testContainerReport() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1);
Expand All @@ -242,15 +247,15 @@ public void testContainerReport() throws IOException, YarnException {
GetContainerReportResponse response =
clientService.getContainerReport(request);
ContainerReport container = response.getContainerReport();
Assert.assertNotNull(container);
Assert.assertEquals(containerId, container.getContainerId());
Assert.assertEquals("http://0.0.0.0:8188/applicationhistory/logs/" +
assertNotNull(container);
assertEquals(containerId, container.getContainerId());
assertEquals("http://0.0.0.0:8188/applicationhistory/logs/" +
"test host:100/container_0_0001_01_000001/" +
"container_0_0001_01_000001/user1", container.getLogUrl());
}

@Test
public void testContainers() throws IOException, YarnException {
void testContainers() throws IOException, YarnException {
ApplicationId appId = ApplicationId.newInstance(0, 1);
ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1);
Expand All @@ -261,8 +266,8 @@ public void testContainers() throws IOException, YarnException {
GetContainersResponse response =
clientService.getContainers(request);
List<ContainerReport> containers = response.getContainerList();
Assert.assertNotNull(containers);
Assert.assertEquals(containerId, containers.get(0).getContainerId());
Assert.assertEquals(containerId1, containers.get(1).getContainerId());
assertNotNull(containers);
assertEquals(containerId, containers.get(0).getContainerId());
assertEquals(containerId1, containers.get(1).getContainerId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,43 @@
import java.io.IOException;
import java.util.Map;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.ApplicationReport;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

public class TestApplicationHistoryManagerImpl extends
ApplicationHistoryStoreTestUtils {
ApplicationHistoryManagerImpl applicationHistoryManagerImpl = null;
private ApplicationHistoryManagerImpl applicationHistoryManagerImpl = null;

@Before
@BeforeEach
public void setup() throws Exception {
Configuration config = new Configuration();
config.setClass(YarnConfiguration.APPLICATION_HISTORY_STORE,
MemoryApplicationHistoryStore.class, ApplicationHistoryStore.class);
MemoryApplicationHistoryStore.class, ApplicationHistoryStore.class);
applicationHistoryManagerImpl = new ApplicationHistoryManagerImpl();
applicationHistoryManagerImpl.init(config);
applicationHistoryManagerImpl.start();
store = applicationHistoryManagerImpl.getHistoryStore();
}

@After
@AfterEach
public void tearDown() throws Exception {
applicationHistoryManagerImpl.stop();
}

@Test
public void testApplicationReport() throws IOException, YarnException {
void testApplicationReport() throws IOException, YarnException {
ApplicationId appId = null;
appId = ApplicationId.newInstance(0, 1);
writeApplicationStartData(appId);
Expand All @@ -64,17 +68,17 @@ public void testApplicationReport() throws IOException, YarnException {
writeApplicationAttemptFinishData(appAttemptId);
ApplicationReport appReport =
applicationHistoryManagerImpl.getApplication(appId);
Assert.assertNotNull(appReport);
Assert.assertEquals(appId, appReport.getApplicationId());
Assert.assertEquals(appAttemptId,
appReport.getCurrentApplicationAttemptId());
Assert.assertEquals(appAttemptId.toString(), appReport.getHost());
Assert.assertEquals("test type", appReport.getApplicationType().toString());
Assert.assertEquals("test queue", appReport.getQueue().toString());
assertNotNull(appReport);
assertEquals(appId, appReport.getApplicationId());
assertEquals(appAttemptId,
appReport.getCurrentApplicationAttemptId());
assertEquals(appAttemptId.toString(), appReport.getHost());
assertEquals("test type", appReport.getApplicationType().toString());
assertEquals("test queue", appReport.getQueue().toString());
}

@Test
public void testApplications() throws IOException {
void testApplications() throws IOException {
ApplicationId appId1 = ApplicationId.newInstance(0, 1);
ApplicationId appId2 = ApplicationId.newInstance(0, 2);
ApplicationId appId3 = ApplicationId.newInstance(0, 3);
Expand All @@ -86,10 +90,10 @@ public void testApplications() throws IOException {
writeApplicationFinishData(appId3);
Map<ApplicationId, ApplicationReport> reports =
applicationHistoryManagerImpl.getApplications(2, 2000L, 5000L);
Assert.assertNotNull(reports);
Assert.assertEquals(2, reports.size());
Assert.assertNull(reports.get("1"));
Assert.assertNull(reports.get("2"));
Assert.assertNull(reports.get("3"));
assertNotNull(reports);
assertEquals(2, reports.size());
assertNull(reports.get("1"));
assertNull(reports.get("2"));
assertNull(reports.get("3"));
}
}
Loading

0 comments on commit 6523b63

Please sign in to comment.