diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractConcatTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractConcatTest.java index 2a7c48acd8f5..cdd98ed40fec 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractConcatTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractConcatTest.java @@ -23,7 +23,7 @@ import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile; import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset; import static org.apache.hadoop.fs.contract.ContractTestUtils.touch; -import static org.apache.hadoop.test.LambdaTestUtils.intercept; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.apache.hadoop.fs.Path; import org.junit.jupiter.api.BeforeEach; @@ -58,14 +58,14 @@ public void setup() throws Exception { @Test public void testConcatEmptyFiles() throws Throwable { touch(getFileSystem(), target); - handleExpectedException(intercept(Exception.class, + handleExpectedException(assertThrows(Exception.class, () -> getFileSystem().concat(target, new Path[0]))); } @Test public void testConcatMissingTarget() throws Throwable { handleExpectedException( - intercept(Exception.class, + assertThrows(Exception.class, () -> getFileSystem().concat(target, new Path[]{zeroByteFile}))); } @@ -85,7 +85,7 @@ public void testConcatFileOnFile() throws Throwable { public void testConcatOnSelf() throws Throwable { byte[] block = dataset(TEST_FILE_LEN, 0, 255); createFile(getFileSystem(), target, false, block); - handleExpectedException(intercept(Exception.class, + handleExpectedException(assertThrows(Exception.class, () -> getFileSystem().concat(target, new Path[]{target}))); } diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractContentSummaryTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractContentSummaryTest.java index 5611b4d7c86b..2ea7b7070b9c 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractContentSummaryTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractContentSummaryTest.java @@ -18,7 +18,7 @@ package org.apache.hadoop.fs.contract; import static org.apache.hadoop.fs.contract.ContractTestUtils.touch; -import static org.apache.hadoop.test.LambdaTestUtils.intercept; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.FileNotFoundException; import org.apache.hadoop.fs.ContentSummary; @@ -57,6 +57,6 @@ public void testGetContentSummaryIncorrectPath() throws Throwable { fs.mkdirs(parent); - intercept(FileNotFoundException.class, () -> fs.getContentSummary(nested)); + assertThrows(FileNotFoundException.class, () -> fs.getContentSummary(nested)); } } diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractCopyFromLocalTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractCopyFromLocalTest.java index c27319d0ec12..61a59727a19d 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractCopyFromLocalTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractCopyFromLocalTest.java @@ -17,7 +17,7 @@ package org.apache.hadoop.fs.contract; -import static org.apache.hadoop.test.LambdaTestUtils.intercept; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.FileNotFoundException; @@ -79,7 +79,7 @@ public void testCopyFile() throws Throwable { public void testCopyFileNoOverwrite() throws Throwable { file = createTempFile("hello"); copyFromLocal(file, true); - intercept(PathExistsException.class, + assertThrows(PathExistsException.class, () -> copyFromLocal(file, false)); } @@ -99,7 +99,7 @@ public void testCopyMissingFile() throws Throwable { file = createTempFile("test"); FileUtils.deleteQuietly(file); // first upload to create - intercept(FileNotFoundException.class, "", + assertThrows(FileNotFoundException.class, () -> copyFromLocal(file, true)); } @@ -194,7 +194,7 @@ public void testSrcIsDirWithOverwriteOptions() throws Throwable { Path dest = path(source.getName()).getParent(); fs.copyFromLocalFile(sourcePath, dest); - intercept(PathExistsException.class, + assertThrows(PathExistsException.class, () -> fs.copyFromLocalFile(false, false, sourcePath, dest)); @@ -279,7 +279,7 @@ public void testSourceIsDirectoryAndDestinationIsFile() throws Throwable { Path destination = copyFromLocal(f, false); Path sourcePath = new Path(source.toURI()); - intercept(FileAlreadyExistsException.class, + assertThrows(FileAlreadyExistsException.class, () -> getFileSystem().copyFromLocalFile(false, true, sourcePath, destination)); } diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java index 6d09248a0911..d37f783ec642 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetFileStatusTest.java @@ -25,8 +25,8 @@ import static org.apache.hadoop.fs.contract.ContractTestUtils.toListThroughNextCallsAlone; import static org.apache.hadoop.fs.contract.ContractTestUtils.touch; import static org.apache.hadoop.fs.contract.ContractTestUtils.treeWalk; -import static org.apache.hadoop.test.LambdaTestUtils.intercept; import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.FileNotFoundException; import java.io.IOException; @@ -321,28 +321,28 @@ public void testListFilesNoDir() throws Throwable { public void testListStatusIteratorNoDir() throws Throwable { describe("test the listStatusIterator call on a path which is not " + "present"); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> getFileSystem().listStatusIterator(path("missing"))); } @Test public void testLocatedStatusNoDir() throws Throwable { describe("test the LocatedStatus call on a path which is not present"); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> getFileSystem().listLocatedStatus(path("missing"))); } @Test public void testListStatusNoDir() throws Throwable { describe("test the listStatus(path) call on a path which is not present"); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> getFileSystem().listStatus(path("missing"))); } @Test public void testListStatusFilteredNoDir() throws Throwable { describe("test the listStatus(path, filter) call on a missing path"); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> getFileSystem().listStatus(path("missing"), ALL_PATHS)); } diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java index 55a5e88aa8da..9c9a5ac2fafe 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java @@ -18,13 +18,13 @@ package org.apache.hadoop.fs.contract; import static org.apache.hadoop.fs.CommonPathCapabilities.LEASE_RECOVERABLE; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.LeaseRecoverable; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.test.LambdaTestUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -56,11 +56,13 @@ public void testLeaseRecoveryFileNotExist() throws Throwable { final FileSystem fs = getFileSystem(); LeaseRecoverable leaseRecoverableFs = verifyAndGetLeaseRecoverableInstance(fs, path); - LambdaTestUtils.intercept(FileNotFoundException.class, "File does not exist", + Exception e = assertThrows(FileNotFoundException.class, () -> leaseRecoverableFs.recoverLease(path)); + Assertions.assertThat(e).hasMessageContaining("File does not exist"); - LambdaTestUtils.intercept(FileNotFoundException.class, "File does not exist", + e = assertThrows(FileNotFoundException.class, () -> leaseRecoverableFs.isFileClosed(path)); + Assertions.assertThat(e).hasMessageContaining("File does not exist"); } @Test @@ -70,11 +72,13 @@ public void testLeaseRecoveryFileOnDirectory() throws Throwable { LeaseRecoverable leaseRecoverableFs = verifyAndGetLeaseRecoverableInstance(fs, path); final Path parentDirectory = path.getParent(); - LambdaTestUtils.intercept(FileNotFoundException.class, "Path is not a file", + Exception e = assertThrows(FileNotFoundException.class, () -> leaseRecoverableFs.recoverLease(parentDirectory)); + Assertions.assertThat(e).hasMessageContaining("Path is not a file"); - LambdaTestUtils.intercept(FileNotFoundException.class, "Path is not a file", + e = assertThrows(FileNotFoundException.class, () -> leaseRecoverableFs.isFileClosed(parentDirectory)); + Assertions.assertThat(e).hasMessageContaining("Path is not a file"); } private LeaseRecoverable verifyAndGetLeaseRecoverableInstance(FileSystem fs, Path path) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractMultipartUploaderTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractMultipartUploaderTest.java index ba902986eee8..c6fa82b06024 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractMultipartUploaderTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractMultipartUploaderTest.java @@ -20,16 +20,16 @@ import static org.apache.hadoop.fs.contract.ContractTestUtils.verifyPathExists; import static org.apache.hadoop.fs.statistics.IOStatisticsLogging.ioStatisticsSourceToString; import static org.apache.hadoop.io.IOUtils.cleanupWithLogger; -import static org.apache.hadoop.test.LambdaTestUtils.eventually; -import static org.apache.hadoop.test.LambdaTestUtils.intercept; import static org.apache.hadoop.util.functional.FutureIO.awaitFuture; import static org.assertj.core.api.Assumptions.assumeThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.base.Charsets; import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.util.HashMap; @@ -47,8 +47,8 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.PathHandle; import org.apache.hadoop.fs.UploadHandle; -import org.apache.hadoop.test.LambdaTestUtils; import org.apache.hadoop.util.DurationInfo; +import org.apache.ozone.test.GenericTestUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -262,7 +262,7 @@ public void testSingleUpload() throws Exception { // verify that if the implementation processes data immediately // then a second attempt at the upload will fail. if (finalizeConsumesUploadIdImmediately()) { - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> complete(completer, uploadHandle, file, partHandles)); } else { // otherwise, the same or other uploader can try again. @@ -429,14 +429,18 @@ protected void verifyContents(final Path file, * @param expectedLength expected length * @throws IOException IO failure */ - private void verifyFileLength(final Path file, final long expectedLength) - throws IOException { - FileStatus st = getFileSystem().getFileStatus(file); - Assertions.assertThat(st) - .describedAs("Uploaded file %s", st) - .matches(FileStatus::isFile) - .extracting(FileStatus::getLen) - .isEqualTo(expectedLength); + private boolean verifyFileLength(final Path file, final long expectedLength) { + try { + FileStatus st = getFileSystem().getFileStatus(file); + Assertions.assertThat(st) + .describedAs("Uploaded file %s", st) + .matches(FileStatus::isFile) + .extracting(FileStatus::getLen) + .isEqualTo(expectedLength); + return true; + } catch (IOException e) { + throw new UncheckedIOException(e); + } } /** @@ -608,10 +612,10 @@ public void testMultipartUploadAbort() throws Exception { int len = contents.getBytes(Charsets.UTF_8).length; InputStream is = IOUtils.toInputStream(contents, "UTF-8"); - intercept(IOException.class, + assertThrows(IOException.class, () -> awaitFuture( uploader0.putPart(uploadHandle, 49, true, file, is, len))); - intercept(IOException.class, + assertThrows(IOException.class, () -> complete(uploader0, uploadHandle, file, partHandles)); assertPathDoesNotExist("Uploaded file should not exist", file); @@ -619,7 +623,7 @@ public void testMultipartUploadAbort() throws Exception { // A second abort should be an FileNotFoundException if the UploadHandle is // consumed by finalization operations (complete, abort). if (finalizeConsumesUploadIdImmediately()) { - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> abortUpload(uploadHandle, file)); } else { abortUpload(uploadHandle, file); @@ -634,7 +638,7 @@ public void testAbortUnknownUpload() throws Exception { Path file = methodPath(); ByteBuffer byteBuffer = ByteBuffer.wrap( "invalid-handle".getBytes(Charsets.UTF_8)); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> abortUpload(BBUploadHandle.from(byteBuffer), file)); } @@ -681,7 +685,7 @@ public void testAbortAllPendingUploads() throws Exception { @Test public void testAbortEmptyUploadHandle() throws Exception { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[0]); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> abortUpload(BBUploadHandle.from(byteBuffer), methodPath())); } @@ -693,7 +697,7 @@ public void testCompleteEmptyUpload() throws Exception { describe("Expect an empty MPU to fail, but still be abortable"); Path dest = methodPath(); UploadHandle handle = startUpload(dest); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> complete(uploader0, handle, dest, new HashMap<>())); abortUpload(handle, dest); } @@ -709,7 +713,7 @@ public void testPutPartEmptyUploadID() throws Exception { BBUploadHandle.from(ByteBuffer.wrap(new byte[0])); byte[] payload = generatePayload(1); InputStream is = new ByteArrayInputStream(payload); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> uploader0.putPart(emptyHandle, 1, true, dest, is, payload.length)); } @@ -729,14 +733,14 @@ public void testCompleteEmptyUploadID() throws Exception { generatePayload(1, SMALL_FILE)); partHandles.put(1, partHandle); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> complete(uploader0, emptyHandle, dest, partHandles)); // and, while things are setup, attempt to complete with // a part index of 0 partHandles.clear(); partHandles.put(0, partHandle); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> complete(uploader0, realHandle, dest, partHandles)); } @@ -758,7 +762,7 @@ public void testDirectoryInTheWay() throws Exception { partHandles.put(1, partHandle); fs.mkdirs(file); - intercept(IOException.class, + assertThrows(IOException.class, () -> completeUpload(file, uploadHandle, partHandles, null, size)); // abort should still work @@ -830,11 +834,8 @@ public void testConcurrentUploads() throws Throwable { // consistent. final int consistencyDelay = timeToBecomeConsistentMillis(); if (consistencyDelay > 0) { - eventually(consistencyDelay, - () -> verifyFileLength(file, size2), - new LambdaTestUtils.ProportionalRetryInterval( - CONSISTENCY_INTERVAL, - consistencyDelay)); + GenericTestUtils.waitFor(() -> verifyFileLength(file, size2), + CONSISTENCY_INTERVAL, consistencyDelay); } verifyContents(file, digest2, size2); diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractOpenTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractOpenTest.java index e696654059dc..400035c23640 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractOpenTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractOpenTest.java @@ -24,14 +24,16 @@ import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile; import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset; import static org.apache.hadoop.fs.contract.ContractTestUtils.touch; -import static org.apache.hadoop.test.LambdaTestUtils.intercept; -import static org.apache.hadoop.test.LambdaTestUtils.interceptFuture; import static org.apache.hadoop.util.functional.FutureIO.awaitFuture; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.FileNotFoundException; import java.io.IOException; +import java.time.Duration; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.hadoop.conf.Configuration; @@ -42,7 +44,6 @@ import org.apache.hadoop.fs.FutureDataInputStreamBuilder; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -75,7 +76,7 @@ public void testOpenReadZeroByteFile() throws Throwable { Path path = path("zero.txt"); touch(getFileSystem(), path); instream = getFileSystem().open(path); - Assertions.assertThat(instream.getPos()) + assertThat(instream.getPos()) .isEqualTo(0); //expect initial read to fail assertMinusOne("initial byte read", instream.read()); @@ -87,7 +88,7 @@ public void testFsIsEncrypted() throws Exception { final Path path = path("file"); createFile(getFileSystem(), path, false, new byte[0]); final FileStatus stat = getFileSystem().getFileStatus(path); - Assertions.assertThat(stat.isEncrypted()) + assertThat(stat.isEncrypted()) .withFailMessage("Result wrong for for isEncrypted() in " + stat) .isEqualTo(areZeroByteFilesEncrypted()); } @@ -152,16 +153,16 @@ public void testOpenFileTwice() throws Throwable { FSDataInputStream instream2 = null; try { int c = instream1.read(); - Assertions.assertThat(c).isEqualTo(0); + assertThat(c).isEqualTo(0); instream2 = getFileSystem().open(path); - Assertions.assertThat(instream2.read()) + assertThat(instream2.read()) .withFailMessage("first read of instream 2") .isEqualTo(0); - Assertions.assertThat(instream1.read()) + assertThat(instream1.read()) .withFailMessage("second read of instream 1") .isEqualTo(1); instream1.close(); - Assertions.assertThat(instream2.read()) + assertThat(instream2.read()) .withFailMessage("second read of instream 2") .isEqualTo(1); //close instream1 again @@ -183,18 +184,18 @@ public void testSequentialRead() throws Throwable { createFile(getFileSystem(), path, true, block); //open first instream = getFileSystem().open(path); - Assertions.assertThat(instream.read()) + assertThat(instream.read()) .isEqualTo(base); - Assertions.assertThat(instream.read()) + assertThat(instream.read()) .isEqualTo(base + 1); - Assertions.assertThat(instream.read()) + assertThat(instream.read()) .isEqualTo(base + 2); - Assertions.assertThat(instream.read()) + assertThat(instream.read()) .isEqualTo(base + 3); // and now, failures - Assertions.assertThat(instream.read()) + assertThat(instream.read()) .isEqualTo(-1); - Assertions.assertThat(instream.read()) + assertThat(instream.read()) .isEqualTo(-1); instream.close(); } @@ -222,7 +223,7 @@ public void testOpenFileUnknownOption() throws Throwable { getFileSystem().openFile(path("testOpenFileUnknownOption")) .opt("fs.test.something", true) .must("fs.test.something", true); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> builder.build()); } @@ -233,7 +234,7 @@ public void testOpenFileUnknownOptionLong() throws Throwable { getFileSystem().openFile(path("testOpenFileUnknownOption")) .optLong("fs.test.something", 1L) .mustLong("fs.test.something2", 1L); - intercept(IllegalArgumentException.class, + assertThrows(IllegalArgumentException.class, () -> builder.build()); } @@ -243,7 +244,10 @@ public void testOpenFileLazyFail() throws Throwable { FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testOpenFileLazyFail")) .opt("fs.test.something", true); - interceptFuture(FileNotFoundException.class, "", builder.build()); + assertThat(builder.build()) + .failsWithin(Duration.ofSeconds(1)) + .withThrowableOfType(ExecutionException.class) + .withCauseInstanceOf(FileNotFoundException.class); } @Test @@ -252,7 +256,7 @@ public void testOpenFileFailExceptionally() throws Throwable { FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testOpenFileFailExceptionally")) .opt("fs.test.something", true); - Assertions.assertThat(builder.build().exceptionally(ex -> null).get()) + assertThat(builder.build().exceptionally(ex -> null).get()) .withFailMessage("exceptional uprating") .isNull(); } @@ -263,7 +267,7 @@ public void testAwaitFutureFailToFNFE() throws Throwable { FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testAwaitFutureFailToFNFE")) .opt("fs.test.something", true); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> awaitFuture(builder.build())); } @@ -273,7 +277,7 @@ public void testAwaitFutureTimeoutFailToFNFE() throws Throwable { FutureDataInputStreamBuilder builder = getFileSystem().openFile(path("testAwaitFutureFailToFNFE")) .opt("fs.test.something", true); - intercept(FileNotFoundException.class, + assertThrows(FileNotFoundException.class, () -> awaitFuture(builder.build(), 10, TimeUnit.DAYS)); } @@ -282,12 +286,16 @@ public void testAwaitFutureTimeoutFailToFNFE() throws Throwable { public void testOpenFileExceptionallyTranslating() throws Throwable { describe("openFile missing file chains into exceptionally()"); CompletableFuture f = getFileSystem() - .openFile(path("testOpenFileExceptionallyTranslating")).build(); - interceptFuture(RuntimeException.class, - "exceptionally", - f.exceptionally(ex -> { + .openFile(path("testOpenFileExceptionallyTranslating")).build() + .exceptionally(ex -> { throw new RuntimeException("exceptionally", ex); - })); + }); + assertThat(f) + .failsWithin(Duration.ofSeconds(1)) + .withThrowableOfType(ExecutionException.class) + .havingCause() + .isInstanceOf(RuntimeException.class) + .withMessage("exceptionally"); } @Test @@ -297,12 +305,12 @@ public void testChainedFailureAwaitFuture() throws Throwable { .openFile(path("testChainedFailureAwaitFuture")) .withFileStatus(null) .build(); - intercept(RuntimeException.class, - "exceptionally", + Exception e = assertThrows(RuntimeException.class, () -> awaitFuture( f.exceptionally(ex -> { throw new RuntimeException("exceptionally", ex); }))); + assertThat(e).hasMessageContaining("exceptionally"); } @Test @@ -318,7 +326,7 @@ public void testOpenFileApplyRead() throws Throwable { .withFileStatus(st) .build() .thenApply(ContractTestUtils::readStream); - Assertions.assertThat((long) readAllBytes.get()) + assertThat((long) readAllBytes.get()) .withFailMessage("Wrong number of bytes read value") .isEqualTo(len); // now reattempt with a new FileStatus and a different path @@ -334,7 +342,7 @@ public void testOpenFileApplyRead() throws Throwable { st.getOwner(), st.getGroup(), new Path("gopher:///localhost:/" + path.getName())); - Assertions.assertThat((long) fs.openFile(path) + assertThat((long) fs.openFile(path) .withFileStatus(st2) .build() .thenApply(ContractTestUtils::readStream) @@ -359,10 +367,10 @@ public void testOpenFileApplyAsyncRead() throws Throwable { accepted.set(true); return ContractTestUtils.readStream(stream); }).get(); - Assertions.assertThat(accepted.get()) + assertThat(accepted.get()) .withFailMessage("async accept operation not invoked") .isTrue(); - Assertions.assertThat(bytes) + assertThat(bytes) .describedAs("bytes read from stream") .isEqualTo(len); } @@ -419,7 +427,7 @@ public void testFloatingPointLength() throws Throwable { .build() .thenApply(ContractTestUtils::readStream) .get(); - Assertions.assertThat(l) + assertThat(l) .describedAs("bytes read from file %s", path) .isEqualTo(len); } diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java index e16340af2b6c..b86e914937ed 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java @@ -31,7 +31,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.apache.hadoop.fs.FileStatus; @@ -39,7 +38,7 @@ import org.apache.hadoop.fs.LocatedFileStatus; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.RemoteIterator; -import org.apache.hadoop.test.LambdaTestUtils; +import org.apache.ozone.test.GenericTestUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -98,11 +97,9 @@ public void testRmEmptyRootDirNonRecursive() throws Throwable { final FileSystem fs = getFileSystem(); final AtomicInteger iterations = new AtomicInteger(0); final FileStatus[] originalChildren = listChildren(fs, root); - LambdaTestUtils.eventually( - OBJECTSTORE_RETRY_TIMEOUT, - new Callable() { - @Override - public Void call() throws Exception { + GenericTestUtils.waitFor( + () -> { + try { FileStatus[] deleted = deleteChildren(fs, root, true); FileStatus[] children = listChildren(fs, root); if (children.length > 0) { @@ -114,10 +111,11 @@ public Void call() throws Exception { dumpStats("deleted", deleted), dumpStats("original", originalChildren))); } - return null; + return true; + } catch (IOException e) { + return false; } - }, - new LambdaTestUtils.ProportionalRetryInterval(50, 1000)); + }, 50, OBJECTSTORE_RETRY_TIMEOUT); // then try to delete the empty one boolean deleted = fs.delete(root, false); LOG.info("rm / of empty dir result is {}", deleted); diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/tools/contract/AbstractContractDistCpTest.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/tools/contract/AbstractContractDistCpTest.java index e6cfc6e46743..35360004c9dd 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/tools/contract/AbstractContractDistCpTest.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/tools/contract/AbstractContractDistCpTest.java @@ -18,6 +18,7 @@ package org.apache.hadoop.tools.contract; import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile; +import static org.apache.hadoop.fs.contract.ContractTestUtils.createSubdirs; import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset; import static org.apache.hadoop.fs.contract.ContractTestUtils.skip; import static org.apache.hadoop.fs.contract.ContractTestUtils.verifyFileContents; @@ -26,6 +27,7 @@ import static org.apache.hadoop.tools.DistCpConstants.CONF_LABEL_DISTCP_JOB_ID; import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -44,7 +46,6 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Counter; import org.apache.hadoop.mapreduce.Job; -import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.tools.CopyListingFileStatus; import org.apache.hadoop.tools.DistCp; import org.apache.hadoop.tools.DistCpConstants; @@ -53,10 +54,12 @@ import org.apache.hadoop.tools.mapred.CopyMapper; import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.functional.RemoteIterators; +import org.apache.ozone.test.GenericTestUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -137,6 +140,9 @@ public abstract class AbstractContractDistCpTest private Path inputDirUnderOutputDir; + @TempDir + private File testDir; + /** * The timeout value is extended over the default so that large updates * are allowed to take time, especially to remote stores. @@ -168,8 +174,7 @@ public void setup() throws Exception { String className = getClass().getSimpleName(); String testSubDir = className + "/" + getMethodName(); localDir = - localFS.makeQualified(new Path(new Path( - GenericTestUtils.getTestDir().toURI()), testSubDir + "/local")); + localFS.makeQualified(new Path(new Path(testDir.toURI()), testSubDir + "/local")); localFS.delete(localDir, true); mkdirs(localFS, localDir); Path testSubPath = path(testSubDir); @@ -703,8 +708,7 @@ public void testDistCpWithIterator() throws Exception { Path dest = new Path(localDir, "dest"); dest = localFS.makeQualified(dest); - GenericTestUtils - .createFiles(remoteFS, source, getDepth(), getWidth(), getWidth()); + createSubdirs(remoteFS, source, getDepth(), getWidth(), getWidth(), 0); GenericTestUtils.LogCapturer log = GenericTestUtils.LogCapturer.captureLogs(SimpleCopyListing.LOG); diff --git a/pom.xml b/pom.xml index 85e37d461da2..a727919d65bf 100644 --- a/pom.xml +++ b/pom.xml @@ -1952,10 +1952,6 @@ ${project.build.directory}/generated-sources/java ${project.build.directory}/generated-sources/protobuf/java - - org.apache.hadoop.fs.contract.* - org.apache.hadoop.tools.contract.* - true