Skip to content

Commit

Permalink
MAPREDUCE-7420. [JDK17] Upgrade Junit 4 to 5 in hadoop-mapreduce-clie…
Browse files Browse the repository at this point in the history
…nt-core Part1. (apache#7363)

Co-authored-by: Chris Nauroth <[email protected]>
Reviewed-by: Chris Nauroth <[email protected]>
Signed-off-by: Shilun Fan <[email protected]>
  • Loading branch information
slfan1989 and cnauroth authored Feb 10, 2025
1 parent c5fdc3b commit 8424c15
Show file tree
Hide file tree
Showing 65 changed files with 1,274 additions and 1,136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
*/
package org.apache.hadoop.mapred;

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

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

import static org.junit.Assert.*;
/**
* test Clock class
*
* test Clock class
*/
public class TestClock {

@Test (timeout=10000)
@Test
@Timeout(value = 10)
public void testClock(){
Clock clock= new Clock();
long templateTime=System.currentTimeMillis();
long time=clock.getTime();
assertEquals(templateTime, time,30);

Clock clock = new Clock();
long templateTime = System.currentTimeMillis();
long time = clock.getTime();
assertEquals(templateTime, time, 30);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@
*/
package org.apache.hadoop.mapred;

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

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestClusterStatus {

private ClusterStatus clusterStatus = new ClusterStatus();

@SuppressWarnings("deprecation")
@Test (timeout = 10000)
public void testGraylistedTrackers() {
Assert.assertEquals(0, clusterStatus.getGraylistedTrackers());
Assert.assertTrue(clusterStatus.getGraylistedTrackerNames().isEmpty());
@Test
@Timeout(value = 10)
public void testGrayListedTrackers() {
assertEquals(0, clusterStatus.getGraylistedTrackers());
assertTrue(clusterStatus.getGraylistedTrackerNames().isEmpty());
}

@SuppressWarnings("deprecation")
@Test (timeout = 10000)
@Test
@Timeout(value = 10)
public void testJobTrackerState() {
Assert.assertEquals(JobTracker.State.RUNNING,
assertEquals(JobTracker.State.RUNNING,
clusterStatus.getJobTrackerState());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
*/
package org.apache.hadoop.mapred;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.text.ParseException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;

import org.junit.Assert;

import org.apache.hadoop.mapred.Counters.Counter;
import org.apache.hadoop.mapred.Counters.CountersExceededException;
import org.apache.hadoop.mapred.Counters.Group;
Expand All @@ -38,7 +39,7 @@
import org.apache.hadoop.mapreduce.TaskCounter;
import org.apache.hadoop.mapreduce.counters.FrameworkCounterGroup;
import org.apache.hadoop.mapreduce.counters.CounterGroupFactory.FrameworkGroupFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -85,14 +86,14 @@ private Counters getEnumCounters(String[] gNames, String[] cNames) {
*/
private void testCounter(Counters counter) throws ParseException {
String compactEscapedString = counter.makeEscapedCompactString();
assertFalse("compactEscapedString should not contain null",
compactEscapedString.contains("null"));
assertFalse(compactEscapedString.contains("null"),
"compactEscapedString should not contain null");

Counters recoveredCounter =
Counters.fromEscapedCompactString(compactEscapedString);
// Check for recovery from string
assertEquals("Recovered counter does not match on content",
counter, recoveredCounter);
assertEquals(counter, recoveredCounter,
"Recovered counter does not match on content");
}

@Test
Expand Down Expand Up @@ -134,19 +135,19 @@ public void testCounterValue() {
long expectedValue = initValue;
Counter counter = counters.findCounter("foo", "bar");
counter.setValue(initValue);
assertEquals("Counter value is not initialized correctly",
expectedValue, counter.getValue());
assertEquals(expectedValue, counter.getValue(),
"Counter value is not initialized correctly");
for (int j = 0; j < NUMBER_INC; j++) {
int incValue = rand.nextInt();
counter.increment(incValue);
expectedValue += incValue;
assertEquals("Counter value is not incremented correctly",
expectedValue, counter.getValue());
assertEquals(expectedValue, counter.getValue(),
"Counter value is not incremented correctly");
}
expectedValue = rand.nextInt();
counter.setValue(expectedValue);
assertEquals("Counter value is not set correctly",
expectedValue, counter.getValue());
assertEquals(expectedValue, counter.getValue(),
"Counter value is not set correctly");
}
}

Expand Down Expand Up @@ -174,29 +175,28 @@ public void testWriteWithLegacyNames() {

@SuppressWarnings("deprecation")
private void checkLegacyNames(Counters counters) {
assertEquals("New name", 1, counters.findCounter(
TaskCounter.class.getName(), "MAP_INPUT_RECORDS").getValue());
assertEquals("Legacy name", 1, counters.findCounter(
assertEquals(1, counters.findCounter(
TaskCounter.class.getName(), "MAP_INPUT_RECORDS").getValue(), "New name");
assertEquals(1, counters.findCounter(
"org.apache.hadoop.mapred.Task$Counter",
"MAP_INPUT_RECORDS").getValue());
assertEquals("Legacy enum", 1,
counters.findCounter(Task.Counter.MAP_INPUT_RECORDS).getValue());
"MAP_INPUT_RECORDS").getValue(), "Legacy name");
assertEquals(1, counters.findCounter(Task.Counter.MAP_INPUT_RECORDS).getValue(), "Legacy enum");

assertEquals("New name", 1, counters.findCounter(
JobCounter.class.getName(), "DATA_LOCAL_MAPS").getValue());
assertEquals("Legacy name", 1, counters.findCounter(
assertEquals(1, counters.findCounter(
JobCounter.class.getName(), "DATA_LOCAL_MAPS").getValue(), "New name");
assertEquals(1, counters.findCounter(
"org.apache.hadoop.mapred.JobInProgress$Counter",
"DATA_LOCAL_MAPS").getValue());
assertEquals("Legacy enum", 1,
counters.findCounter(JobInProgress.Counter.DATA_LOCAL_MAPS).getValue());
"DATA_LOCAL_MAPS").getValue(), "Legacy name");
assertEquals(1,
counters.findCounter(JobInProgress.Counter.DATA_LOCAL_MAPS).getValue(), "Legacy enum");

assertEquals("New name", 1, counters.findCounter(
FileSystemCounter.class.getName(), "FILE_BYTES_READ").getValue());
assertEquals("New name and method", 1, counters.findCounter("file",
FileSystemCounter.BYTES_READ).getValue());
assertEquals("Legacy name", 1, counters.findCounter(
assertEquals(1, counters.findCounter(
FileSystemCounter.class.getName(), "FILE_BYTES_READ").getValue(), "New name");
assertEquals(1, counters.findCounter("file",
FileSystemCounter.BYTES_READ).getValue(), "New name and method");
assertEquals(1, counters.findCounter(
"FileSystemCounters",
"FILE_BYTES_READ").getValue());
"FILE_BYTES_READ").getValue(), "Legacy name");
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -266,8 +266,8 @@ public void testMakeCompactString() {
assertEquals("group1.counter1:1", counters.makeCompactString());
counters.incrCounter("group2", "counter2", 3);
String cs = counters.makeCompactString();
assertTrue("Bad compact string",
cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1));
assertTrue(cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1),
"Bad compact string");
}

@Test
Expand Down Expand Up @@ -321,7 +321,7 @@ private void shouldThrow(Class<? extends Exception> ecls, Runnable runnable) {
} catch (CountersExceededException e) {
return;
}
Assert.fail("Should've thrown " + ecls.getSimpleName());
fail("Should've thrown " + ecls.getSimpleName());
}

public static void main(String[] args) throws IOException {
Expand All @@ -341,12 +341,12 @@ public void testFrameworkCounter() {

org.apache.hadoop.mapreduce.Counter count1 =
counterGroup.findCounter(JobCounter.NUM_FAILED_MAPS.toString());
Assert.assertNotNull(count1);
assertNotNull(count1);

// Verify no exception get thrown when finding an unknown counter
org.apache.hadoop.mapreduce.Counter count2 =
counterGroup.findCounter("Unknown");
Assert.assertNull(count2);
assertNull(count2);
}

@SuppressWarnings("rawtypes")
Expand All @@ -363,19 +363,19 @@ public void testTaskCounter() {
org.apache.hadoop.mapreduce.Counter count1 =
counterGroup.findCounter(
TaskCounter.PHYSICAL_MEMORY_BYTES.toString());
Assert.assertNotNull(count1);
assertNotNull(count1);
count1.increment(10);
count1.increment(10);
Assert.assertEquals(20, count1.getValue());
assertEquals(20, count1.getValue());

// Verify no exception get thrown when finding an unknown counter
org.apache.hadoop.mapreduce.Counter count2 =
counterGroup.findCounter(
TaskCounter.MAP_PHYSICAL_MEMORY_BYTES_MAX.toString());
Assert.assertNotNull(count2);
assertNotNull(count2);
count2.increment(5);
count2.increment(10);
Assert.assertEquals(10, count2.getValue());
assertEquals(10, count2.getValue());
}

@Test
Expand All @@ -385,12 +385,12 @@ public void testFilesystemCounter() {

org.apache.hadoop.mapreduce.Counter count1 =
fsGroup.findCounter("ANY_BYTES_READ");
Assert.assertNotNull(count1);
assertNotNull(count1);

// Verify no exception get thrown when finding an unknown counter
org.apache.hadoop.mapreduce.Counter count2 =
fsGroup.findCounter("Unknown");
Assert.assertNull(count2);
assertNull(count2);
}

}
Expand Down
Loading

0 comments on commit 8424c15

Please sign in to comment.