Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6178#discussion_r197058127
  
    --- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/FileUploadHandlerTest.java
 ---
    @@ -259,6 +271,29 @@ public void testFileMultipart() throws Exception {
                }
        }
     
    +   @Test
    +   public void testUploadCleanupOnFailure() throws IOException {
    +           OkHttpClient client = new OkHttpClient();
    +
    +           Request request = 
buildMixedRequestWithUnknownAttribute(mixedHandler.getMessageHeaders().getTargetRestEndpointURL());
    +           try (Response response = client.newCall(request).execute()) {
    +                   assertEquals(HttpResponseStatus.BAD_REQUEST.code(), 
response.code());
    +           }
    +           assertUploadDirectoryIsEmpty();
    +   }
    +
    +   private static void assertUploadDirectoryIsEmpty() throws IOException {
    +           Preconditions.checkArgument(
    +                   1 == Files.list(configuredUploadDir).count(),
    +                   "Directory structure in rest upload directory has 
changed. Test must be adjusted");
    +           Optional<Path> actualUploadDir = 
Files.list(configuredUploadDir).findAny();
    +           Preconditions.checkArgument(
    +                   actualUploadDir.isPresent(),
    +                   "Expected upload directory does not exist.");
    +           
System.out.println(Files.list(actualUploadDir.get()).collect(Collectors.toList()));
    +           assertEquals("Not all files were cleaned up.", 0, 
Files.list(actualUploadDir.get()).count());
    --- End diff --
    
    Alright, but then the order how methods are called in the catch block is 
incorrect. Maybe that should be factored out into a method to avoid code 
duplication.


---

Reply via email to