8000 YARN-11260. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-timelineservice by ashutoshcipher · Pull Request #4775 · apache/hadoop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

YARN-11260. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-timelineservice #4775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
10000
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,23 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<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.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@

package org.apache.hadoop.yarn.server.timelineservice.collector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,6 +27,11 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

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.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
Expand All @@ -47,14 +41,22 @@
import org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextResponse;
import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl;
import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

public class TestNMTimelineCollectorManager {
private NodeTimelineCollectorManager collectorManager;

@Before
@BeforeEach
public void setup() throws Exception {
collectorManager = createCollectorManager();
Configuration conf = new YarnConfiguration();
Expand All @@ -66,20 +68,20 @@ public void setup() throws Exception {
collectorManager.start();
}

@After
@AfterEach
public void tearDown() throws Exception {
if (collectorManager != null) {
collectorManager.stop();
}
}

@Test
public void testStartingWriterFlusher() throws Exception {
void testStartingWriterFlusher() throws Exception {
assertTrue(collectorManager.writerFlusherRunning());
}

@Test
public void testStartWebApp() throws Exception {
void testStartWebApp() throws Exception {
assertNotNull(collectorManager.getRestServerBindAddress());
String address = collectorManager.getRestServerBindAddress();
String[] parts = address.split(":");
Expand All @@ -89,8 +91,9 @@ public void testStartWebApp() throws Exception {
Integer.valueOf(parts[1]) <= 30100);
}

@Test(timeout=60000)
public void testMultithreadedAdd() throws Exception {
@Test
@Timeout(60000)
void testMultithreadedAdd() throws Exception {
final int numApps = 5;
List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>();
for (int i = 0; i < numApps; i++) {
Expand All @@ -107,7 +110,7 @@ public Boolean call() {
ExecutorService executor = Executors.newFixedThreadPool(numApps);
try {
List<Future<Boolean>> futures = executor.invokeAll(tasks);
for (Future<Boolean> future: futures) {
for (Future<Boolean> future : futures) {
assertTrue(future.get());
}
} finally {
Expand All @@ -121,7 +124,7 @@ public Boolean call() {
}

@Test
public void testMultithreadedAddAndRemove() throws Exception {
void testMultithreadedAddAndRemove() throws Exception {
final int numApps = 5;
List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>();
for (int i = 0; i < numApps; i++) {
Expand All @@ -140,7 +143,7 @@ public Boolean call() {
ExecutorService executor = Executors.newFixedThreadPool(numApps);
try {
List<Future<Boolean>> futures = executor.invokeAll(tasks);
for (Future<Boolean> future: futures) {
for (Future<Boolean> future : futures) {
assertTrue(future.get());
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.apache.hadoop.yarn.server.timelineservice.collector;

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

import org.apache.hadoop.yarn.server.timelineservice.metrics.PerNodeAggTimelineCollectorMetrics;
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;

/**
* Test PerNodeAggTimelineCollectorMetrics.
Expand All @@ -32,24 +35,24 @@ public class TestPerNodeAggTimelineCollectorMetrics {
private PerNodeAggTimelineCollectorMetrics metrics;

@Test
public void testTimelineCollectorMetrics() {
Assert.assertNotNull(metrics);
Assert.assertEquals(10,
void testTimelineCollectorMetrics() {
assertNotNull(metrics);
assertEquals(10,
metrics.getPutEntitiesSuccessLatency().getInterval());
Assert.assertEquals(10,
assertEquals(10,
metrics.getPutEntitiesFailureLatency().getInterval());
Assert.assertEquals(10,
assertEquals(10,
metrics.getAsyncPutEntitiesSuccessLatency().getInterval());
Assert.assertEquals(10,
assertEquals(10,
metrics.getAsyncPutEntitiesFailureLatency().getInterval());
}

@Before
@BeforeEach
public void setup() {
metrics = PerNodeAggTimelineCollectorMetrics.getInstance();
}

@After
@AfterEach
public void tearDown() {
PerNodeAggTimelineCollectorMetrics.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@

package org.apache.hadoop.yarn.server.timelineservice.collector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.concurrent.Future;

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

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ExitUtil;
import org.apache.hadoop.util.Shell;
Expand All @@ -47,9 +41,16 @@
import org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextResponse;
import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl;
import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

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.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

public class TestPerNodeTimelineCollectorsAuxService {
private ApplicationAttemptId appAttemptId;
Expand All @@ -70,23 +71,23 @@ public TestPerNodeTimelineCollectorsAuxService() {
1000L);
}

@After
@AfterEach
public void tearDown() throws Shell.ExitCodeException {
if (auxService != null) {
auxService.stop();
}
}

@Test
public void testAddApplication() throws Exception {
void testAddApplication() throws Exception {
auxService = createCollectorAndAddApplication();
// auxService should have a single app
assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
auxService.close();
}

@Test
public void testAddApplicationNonAMContainer() throws Exception {
void testAddApplicationNonAMContainer() throws Exception {
auxService = createCollector();

ContainerId containerId = getContainerId(2L); // not an AM
Expand All @@ -99,7 +100,7 @@ public void testAddApplicationNonAMContainer() throws Exception {
}

@Test
public void testRemoveApplication() throws Exception {
void testRemoveApplication() throws Exception {
auxService = createCollectorAndAddApplication();
// auxService should have a single app
assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
Expand All @@ -118,7 +119,7 @@ public void testRemoveApplication() throws Exception {
}

@Test
public void testRemoveApplicationNonAMContainer() throws Exception {
void testRemoveApplicationNonAMContainer() throws Exception {
auxService = createCollectorAndAddApplication();
// auxService should have a single app
assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()));
Expand All @@ -133,8 +134,9 @@ public void testRemoveApplicationNonAMContainer() throws Exception {
auxService.close();
}

@Test(timeout = 60000)
public void testLaunch() throws Exception {
@Test
@Timeout(60000)
void testLaunch() throws Exception {
ExitUtil.disableSystemExit();
try {
auxService =
Expand Down Expand Up @@ -192,7 +194,7 @@ protected Future removeApplicationCollector(ContainerId containerId) {
try {
future.get();
} catch (Exception e) {
Assert.fail("Expeption thrown while removing collector");
fail("Expeption thrown while removing collector");
}
return future;
}
Expand Down Expand Up @@ -228,8 +230,9 @@ private ContainerId getContainerId(long id) {
return ContainerId.newContainerId(appAttemptId, id);
}

@Test(timeout = 60000)
public void testRemoveAppWhenSecondAttemptAMCotainerIsLaunchedSameNode()
@Test
@Timeout(60000)
void testRemoveAppWhenSecondAttemptAMCotainerIsLaunchedSameNode()
throws Exception {
// add first attempt collector
auxService = createCollectorAndAddApplication();
Expand All @@ -241,25 +244,25 @@ public void testRemoveAppWhenSecondAttemptAMCotainerIsLaunchedSameNode()
createContainerInitalizationContext(2);
auxService.initializeContainer(containerInitalizationContext);

assertTrue("Applicatin not found in collectors.",
auxService.hasApplication(appAttemptId.getApplicationId()));
assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()),
"Applicatin not found in collectors.");

// first attempt stop container
ContainerTerminationContext context = createContainerTerminationContext(1);
auxService.stopContainer(context);

// 2nd attempt container removed, still collector should hold application id
assertTrue("collector has removed application though 2nd attempt"
+ " is running this node",
auxService.hasApplication(appAttemptId.getApplicationId()));
assertTrue(auxService.hasApplication(appAttemptId.getApplicationId()),
"collector has removed application though 2nd attempt"
+ " is running this node");

// second attempt stop container
context = createContainerTerminationContext(2);
auxService.stopContainer(context);

// auxService should not have that app
assertFalse("Application is not removed from collector",
auxService.hasApplication(appAttemptId.getApplicationId()));
assertFalse(auxService.hasApplication(appAttemptId.getApplicationId()),
"Application is not removed from collector");
auxService.close();
}

Expand Down
Loading
0