This is an automated email from the ASF dual-hosted git repository. chesnay pushed a commit to branch release-1.16 in repository https://gitbox.apache.org/repos/asf/flink.git
commit 333a6e67b4bbe78b8c5695f8cd52ea2ea7dc0b20 Author: Chesnay Schepler <ches...@apache.org> AuthorDate: Thu Aug 17 11:11:34 2023 +0200 [FLINK-32888] Expose file comparison assertion --- .../runtime/rest/MultipartUploadResource.java | 53 +++++++++++----------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java index 19939b2dce9..9109424b177 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java @@ -134,36 +134,35 @@ public class MultipartUploadResource extends ExternalResource { (request, restfulGateway) -> { // the default verifier checks for identiy (i.e. same name and content) of all // uploaded files - List<Path> expectedFiles = - getFilesToUpload().stream() - .map(File::toPath) - .collect(Collectors.toList()); - List<Path> uploadedFiles = - request.getUploadedFiles().stream() - .map(File::toPath) - .collect(Collectors.toList()); - - assertEquals(expectedFiles.size(), uploadedFiles.size()); - - List<Path> expectedList = new ArrayList<>(expectedFiles); - List<Path> actualList = new ArrayList<>(uploadedFiles); - expectedList.sort(Comparator.comparing(Path::toString)); - actualList.sort(Comparator.comparing(Path::toString)); - - for (int x = 0; x < expectedList.size(); x++) { - Path expected = expectedList.get(x); - Path actual = actualList.get(x); - - assertEquals( - expected.getFileName().toString(), actual.getFileName().toString()); - - byte[] originalContent = Files.readAllBytes(expected); - byte[] receivedContent = Files.readAllBytes(actual); - assertArrayEquals(originalContent, receivedContent); - } + assertUploadedFilesEqual(request, getFilesToUpload()); }); } + public static void assertUploadedFilesEqual(HandlerRequest<?> request, Collection<File> files) + throws IOException { + List<Path> expectedFiles = files.stream().map(File::toPath).collect(Collectors.toList()); + List<Path> uploadedFiles = + request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList()); + + assertEquals(expectedFiles.size(), uploadedFiles.size()); + + List<Path> expectedList = new ArrayList<>(expectedFiles); + List<Path> actualList = new ArrayList<>(uploadedFiles); + expectedList.sort(Comparator.comparing(Path::toString)); + actualList.sort(Comparator.comparing(Path::toString)); + + for (int x = 0; x < expectedList.size(); x++) { + Path expected = expectedList.get(x); + Path actual = actualList.get(x); + + assertEquals(expected.getFileName().toString(), actual.getFileName().toString()); + + byte[] originalContent = Files.readAllBytes(expected); + byte[] receivedContent = Files.readAllBytes(actual); + assertArrayEquals(originalContent, receivedContent); + } + } + public void setFileUploadVerifier( BiConsumerWithException< HandlerRequest<? extends RequestBody>, RestfulGateway, Exception>