Skip to content

Commit

Permalink
MAPREDUCE-7416. Upgrade Junit 4 to 5 in hadoop-mapreduce-client-shuffle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 authored and fanshilun committed Feb 5, 2025
1 parent f900339 commit ce0bb52
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package org.apache.hadoop.mapred;

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

import java.io.File;
import java.io.RandomAccessFile;

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;

/**
* Unit test for FadvisedChunkedFile.
Expand All @@ -42,11 +42,11 @@ public void testDoubleClose() throws Exception {
f, 0, 5, 2, true,
10, null, "foo");

assertTrue("fd not valid", f.getFD().valid());
assertTrue(f.getFD().valid(), "fd not valid");
af.close();
assertFalse("fd still valid", f.getFD().valid());
assertFalse(f.getFD().valid(), "fd still valid");
af.close();
assertFalse("fd still valid", f.getFD().valid());
assertFalse(f.getFD().valid(), "fd still valid");
}
} finally {
absoluteFile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.StringUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,7 +39,8 @@ public class TestFadvisedFileRegion {
private static final Logger LOG =
LoggerFactory.getLogger(TestFadvisedFileRegion.class);

@Test(timeout = 100000)
@Test
@Timeout(value = 100)
public void testCustomShuffleTransfer() throws IOException {
File absLogDir = new File("target",
TestFadvisedFileRegion.class.getSimpleName() +
Expand Down Expand Up @@ -84,7 +86,7 @@ public void testCustomShuffleTransfer() throws IOException {
targetFile = new RandomAccessFile(outFile.getAbsolutePath(), "rw");
target = targetFile.getChannel();

Assert.assertEquals(FILE_SIZE, inputFile.length());
Assertions.assertEquals(FILE_SIZE, inputFile.length());

//create FadvisedFileRegion
fileRegion = new FadvisedFileRegion(
Expand All @@ -100,8 +102,8 @@ public void testCustomShuffleTransfer() throws IOException {
}

//assert size
Assert.assertEquals(count, (int)pos);
Assert.assertEquals(count, targetFile.length());
Assertions.assertEquals(count, (int)pos);
Assertions.assertEquals(count, targetFile.length());
} finally {
if (fileRegion != null) {
fileRegion.deallocate();
Expand All @@ -117,10 +119,10 @@ public void testCustomShuffleTransfer() throws IOException {
try {
int total = in.read(buff, 0, count);

Assert.assertEquals(count, total);
Assertions.assertEquals(count, total);

for(int i = 0; i < count; i++) {
Assert.assertEquals(initBuff[position+i], buff[i]);
Assertions.assertEquals(initBuff[position+i], buff[i]);
}
} finally {
IOUtils.cleanupWithLogger(LOG, in);
Expand All @@ -137,21 +139,21 @@ private static void customShuffleTransferCornerCases(
FadvisedFileRegion fileRegion, WritableByteChannel target, int count) {
try {
fileRegion.customShuffleTransfer(target, -1);
Assert.fail("Expected a IllegalArgumentException");
Assertions.fail("Expected a IllegalArgumentException");
} catch (IllegalArgumentException ie) {
LOG.info("Expected - illegal argument is passed.");
} catch (Exception e) {
Assert.fail("Expected a IllegalArgumentException");
Assertions.fail("Expected a IllegalArgumentException");
}

//test corner cases
try {
fileRegion.customShuffleTransfer(target, count + 1);
Assert.fail("Expected a IllegalArgumentException");
Assertions.fail("Expected a IllegalArgumentException");
} catch (IllegalArgumentException ie) {
LOG.info("Expected - illegal argument is passed.");
} catch (Exception e) {
Assert.fail("Expected a IllegalArgumentException");
Assertions.fail("Expected a IllegalArgumentException");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
import org.apache.hadoop.security.token.SecretManager;
import org.apache.hadoop.security.token.Token;
import org.eclipse.jetty.http.HttpHeader;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
Expand All @@ -93,10 +93,10 @@
import static org.apache.hadoop.mapred.ShuffleHandler.SHUFFLE_CONNECTION_KEEP_ALIVE_TIME_OUT;
import static org.apache.hadoop.mapred.ShuffleHandler.TIMEOUT_HANDLER;
import static org.apache.hadoop.mapreduce.security.SecureShuffleUtils.HTTP_HEADER_URL_HASH;
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.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;

public class TestShuffleChannelHandler extends TestShuffleHandlerBase {
private static final org.slf4j.Logger LOG =
Expand Down Expand Up @@ -163,12 +163,12 @@ public void tetKeepAliveTimeout() throws InterruptedException, IOException {
t.getExpectedHttpResponse(req, true, 46),
t.getAttemptData(new Attempt(TEST_ATTEMPT_1, TEST_DATA_A))
);
assertTrue("keep-alive", shuffle.isActive());
assertTrue(shuffle.isActive(), "keep-alive");

TimeUnit.SECONDS.sleep(3);
shuffle.runScheduledPendingTasks();

assertFalse("closed", shuffle.isActive());
assertFalse(shuffle.isActive(), "closed");
}

@Test
Expand All @@ -193,7 +193,7 @@ public void testIncompatibleShuffleVersion() {
assertEquals(getExpectedHttpResponse(HttpResponseStatus.BAD_REQUEST).toString(),
actual.toString());

assertFalse("closed", shuffle.isActive()); // known-issue
assertFalse(shuffle.isActive(), "closed"); // known-issue
}

@Test
Expand All @@ -216,7 +216,7 @@ public void testInvalidMapNoIndexFile() {
assertEquals(getExpectedHttpResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR).toString(),
actual.toString());

assertFalse("closed", shuffle.isActive());
assertFalse(shuffle.isActive(), "closed");
}

@Test
Expand All @@ -225,7 +225,7 @@ public void testInvalidMapNoDataFile() {
final EmbeddedChannel shuffle = t.createShuffleHandlerChannelFileRegion();

String dataFile = getDataFile(TEST_USER, tempDir.toAbsolutePath().toString(), TEST_ATTEMPT_2);
assertTrue("should delete", new File(dataFile).delete());
assertTrue(new File(dataFile).delete(), "should delete");

FullHttpRequest req = t.createRequest(getUri(TEST_JOB_ID, 0,
Arrays.asList(TEST_ATTEMPT_1, TEST_ATTEMPT_2), false));
Expand All @@ -243,7 +243,7 @@ public void testInvalidMapNoDataFile() {
assertEquals(getExpectedHttpResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR).toString(),
actual.toString());

assertFalse("closed", shuffle.isActive());
assertFalse(shuffle.isActive(), "closed");
}

private DefaultHttpResponse getExpectedHttpResponse(HttpResponseStatus status) {
Expand Down Expand Up @@ -362,7 +362,7 @@ private void testGetAllAttemptsForReduce0NoKeepAlive(
getExpectedHttpResponse(request, false, 138),
getAllAttemptsForReduce0()
);
assertFalse("no keep-alive", shuffle.isActive());
assertFalse(shuffle.isActive(), "no keep-alive");
}

private void testKeepAlive(java.util.Queue<Object> messages,
Expand All @@ -374,7 +374,7 @@ private void testKeepAlive(java.util.Queue<Object> messages,
getExpectedHttpResponse(req1, true, 46),
getAttemptData(new Attempt(TEST_ATTEMPT_1, TEST_DATA_A))
);
assertTrue("keep-alive", shuffle.isActive());
assertTrue(shuffle.isActive(), "keep-alive");
messages.clear();

final FullHttpRequest req2 = createRequest(
Expand All @@ -384,7 +384,7 @@ private void testKeepAlive(java.util.Queue<Object> messages,
getExpectedHttpResponse(req2, true, 46),
getAttemptData(new Attempt(TEST_ATTEMPT_2, TEST_DATA_B))
);
assertTrue("keep-alive", shuffle.isActive());
assertTrue(shuffle.isActive(), "keep-alive");
messages.clear();

final FullHttpRequest req3 = createRequest(
Expand All @@ -394,7 +394,7 @@ private void testKeepAlive(java.util.Queue<Object> messages,
getExpectedHttpResponse(req3, false, 46),
getAttemptData(new Attempt(TEST_ATTEMPT_3, TEST_DATA_C))
);
assertFalse("no keep-alive", shuffle.isActive());
assertFalse(shuffle.isActive(), "no keep-alive");
}

private ArrayList<ByteBuf> getAllAttemptsForReduce0() throws IOException {
Expand Down Expand Up @@ -437,15 +437,15 @@ private void assertResponse(java.util.Queue<Object> outboundMessages,
assertEquals(response.toString(), resp.toString());
}
if (i > 0 && i <= content.size()) {
assertEquals("data should match",
ByteBufUtil.prettyHexDump(content.get(i - 1)), actualHexdump);
assertEquals(
ByteBufUtil.prettyHexDump(content.get(i - 1)), actualHexdump, "data should match");
}

i++;
}

// This check is done after to have better debug logs on failure.
assertEquals("all data should match", content.size() + 1, outboundMessages.size());
assertEquals(content.size() + 1, outboundMessages.size(), "all data should match");
}

public EmbeddedChannel createShuffleHandlerChannelFileRegion() {
Expand Down
Loading

0 comments on commit ce0bb52

Please sign in to comment.