Skip to content

HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part11. #7671

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

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/
package org.apache.hadoop.io.compress;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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 java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -37,13 +38,11 @@
import org.apache.hadoop.io.compress.zlib.ZlibFactory;
import org.apache.hadoop.util.NativeCodeLoader;
import org.apache.log4j.Logger;
import org.junit.Assert;

import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
import static org.junit.Assert.*;

public class CompressDecompressTester<T extends Compressor, E extends Decompressor> {

Expand Down Expand Up @@ -274,12 +273,10 @@ public void assertCompression(String name, Compressor compressor,
int maxCompressedLength = 32 + rawData.length + rawData.length/6;
byte[] compressedResult = new byte[maxCompressedLength];
byte[] decompressedBytes = new byte[rawData.length];
assertTrue(
joiner.join(name, "compressor.needsInput before error !!!"),
compressor.needsInput());
assertEquals(
joiner.join(name, "compressor.getBytesWritten before error !!!"),
0, compressor.getBytesWritten());
assertTrue(compressor.needsInput(),
joiner.join(name, "compressor.needsInput before error !!!"));
assertEquals(0, compressor.getBytesWritten(),
joiner.join(name, "compressor.getBytesWritten before error !!!"));
compressor.setInput(rawData, 0, rawData.length);
compressor.finish();
while (!compressor.finished()) {
Expand All @@ -288,23 +285,20 @@ public void assertCompression(String name, Compressor compressor,
}
compressor.reset();

assertTrue(
joiner.join(name, "decompressor.needsInput() before error !!!"),
decompressor.needsInput());
assertTrue(decompressor.needsInput(),
joiner.join(name, "decompressor.needsInput() before error !!!"));
decompressor.setInput(compressedResult, 0, cSize);
assertFalse(
joiner.join(name, "decompressor.needsInput() after error !!!"),
decompressor.needsInput());
assertFalse(decompressor.needsInput(),
joiner.join(name, "decompressor.needsInput() after error !!!"));
while (!decompressor.finished()) {
decompressedSize = decompressor.decompress(decompressedBytes, 0,
decompressedBytes.length);
}
decompressor.reset();
assertEquals(joiner.join(name, " byte size not equals error !!!"),
rawData.length, decompressedSize);
assertArrayEquals(
joiner.join(name, " byte arrays not equals error !!!"), rawData,
decompressedBytes);
assertEquals(rawData.length, decompressedSize,
joiner.join(name, " byte size not equals error !!!"));
assertArrayEquals(rawData, decompressedBytes,
joiner.join(name, " byte arrays not equals error !!!"));
}
}),

Expand All @@ -331,17 +325,16 @@ void assertCompression(String name, Compressor compressor,
// check compressed output
buf = bytesOut.toByteArray();
int emSize = emptySize.get(compressor.getClass());
Assert.assertEquals(
joiner.join(name, "empty stream compressed output size != "
+ emSize), emSize, buf.length);
assertEquals(emSize, buf.length,
joiner.join(name, "empty stream compressed output size != " + emSize));
// use compressed output as input for decompression
bytesIn = new ByteArrayInputStream(buf);
// create decompression stream
blockDecompressorStream = new BlockDecompressorStream(bytesIn,
decompressor, 1024);
// no byte is available because stream was closed
assertEquals(joiner.join(name, " return value is not -1"), -1,
blockDecompressorStream.read());
assertEquals(-1,
blockDecompressorStream.read(), joiner.join(name, " return value is not -1"));
} catch (IOException e) {
fail(joiner.join(name, e.getMessage()));
} finally {
Expand Down Expand Up @@ -407,9 +400,8 @@ public void assertCompression(String name, Compressor compressor,
decompressor.reset();
off = off + step;
}
assertArrayEquals(
joiner.join(name, "byte arrays not equals error !!!"),
originalRawData, decompressOut.toByteArray());
assertArrayEquals(originalRawData, decompressOut.toByteArray(),
joiner.join(name, "byte arrays not equals error !!!"));
} catch (Exception ex) {
throw new AssertionError(name + ex, ex);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.util.List;

import org.apache.hadoop.thirdparty.com.google.common.primitives.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -41,8 +41,8 @@
import static org.apache.hadoop.util.Preconditions.checkArgument;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public final class TestBZip2Codec {

Expand All @@ -54,7 +54,7 @@ public final class TestBZip2Codec {
private Decompressor decompressor;
private Path tempFile;

@Before
@BeforeEach
public void setUp() throws Exception {
conf = new Configuration();

Expand All @@ -71,7 +71,7 @@ public void setUp() throws Exception {
decompressor = CodecPool.getDecompressor(codec);
}

@After
@AfterEach
public void tearDown() throws Exception {
CodecPool.returnDecompressor(decompressor);
fs.delete(tempFile, /* recursive */ false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package org.apache.hadoop.io.compress;

import static org.junit.Assert.assertEquals;
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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -29,7 +29,7 @@
import java.io.InputStream;
import java.nio.ByteBuffer;

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

public class TestBlockDecompressorStream {

Expand Down Expand Up @@ -63,17 +63,17 @@ private void testRead(int bufLen) throws IOException {

// check compressed output
buf = bytesOut.toByteArray();
assertEquals("empty file compressed output size is not " + (bufLen + 4),
bufLen + 4, buf.length);
assertEquals(bufLen + 4, buf.length,
"empty file compressed output size is not " + (bufLen + 4));

// use compressed output as input for decompression
bytesIn = new ByteArrayInputStream(buf);

// get decompression stream
try (BlockDecompressorStream blockDecompressorStream =
new BlockDecompressorStream(bytesIn, new FakeDecompressor(), 1024)) {
assertEquals("return value is not -1",
-1 , blockDecompressorStream.read());
assertEquals(-1, blockDecompressorStream.read(),
"return value is not -1");
} catch (IOException e) {
fail("unexpected IOException : " + e);
}
Expand Down
Loading