Skip to content
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
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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})));
}

Expand All @@ -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})));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +57,6 @@ public void testGetContentSummaryIncorrectPath() throws Throwable {

fs.mkdirs(parent);

intercept(FileNotFoundException.class, () -> fs.getContentSummary(nested));
assertThrows(FileNotFoundException.class, () -> fs.getContentSummary(nested));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -608,18 +612,18 @@ 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);

// 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);
Expand All @@ -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));
}

Expand Down Expand Up @@ -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()));
}

Expand All @@ -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);
}
Expand All @@ -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));
}
Expand All @@ -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));
}

Expand All @@ -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
Expand Down Expand Up @@ -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),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max wait time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistencyDelay

CONSISTENCY_INTERVAL, consistencyDelay);
}

verifyContents(file, digest2, size2);
Expand Down
Loading