Github user zentol commented on a diff in the pull request:
https://github.com/apache/flink/pull/6178#discussion_r197054770
--- 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 --
This test wasn't covering the case of exceptions but the rejection of
unknown attributes. Will try to find a way to crash the handler.
---