This is an automated email from the ASF dual-hosted git repository. chesnay pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit 329ee55e2e3ef5a6cf21009f6e321a99b1c91452 Author: Chesnay Schepler <[email protected]> AuthorDate: Thu Aug 17 11:11:34 2023 +0200 [FLINK-32888] Expose file comparison assertion --- .../runtime/rest/MultipartUploadExtension.java | 53 +++++++++++----------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadExtension.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadExtension.java index 672afe442ae..494eb212260 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadExtension.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadExtension.java @@ -138,36 +138,35 @@ public class MultipartUploadExtension implements CustomExtension { (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()); - - assertThat(uploadedFiles).hasSameSizeAs(expectedFiles); - - 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); - - assertThat(actual.getFileName()) - .hasToString(expected.getFileName().toString()); - - byte[] originalContent = Files.readAllBytes(expected); - byte[] receivedContent = Files.readAllBytes(actual); - assertThat(receivedContent).isEqualTo(originalContent); - } + 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()); + + assertThat(uploadedFiles).hasSameSizeAs(expectedFiles); + + 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); + + assertThat(actual.getFileName()).hasToString(expected.getFileName().toString()); + + byte[] originalContent = Files.readAllBytes(expected); + byte[] receivedContent = Files.readAllBytes(actual); + assertThat(receivedContent).isEqualTo(originalContent); + } + } + public void setFileUploadVerifier( BiConsumerWithException< HandlerRequest<? extends RequestBody>, RestfulGateway, Exception>
