From 7c58563a234f7bbf74a6655c4812f6b8c2c9fa93 Mon Sep 17 00:00:00 2001 From: Danylo Date: Fri, 17 Jan 2025 14:09:30 +0100 Subject: [PATCH] Fix RemoteFileSupplier --- .../server/execution/file/supplier/RemoteFileSupplier.java | 4 ++-- .../execution/file/supplier/RemoteFileSupplierTest.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java b/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java index e8b8f313c54..855ee4e8f9d 100644 --- a/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java +++ b/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java @@ -96,8 +96,8 @@ private Future isSizeChanged() { private Future downloadFile() { return fileSystem.open(tmpPath, new OpenOptions()) .compose(tmpFile -> sendHttpRequest(getRequestOptions) - .compose(response -> response.pipeTo(tmpFile)) - .onComplete(result -> tmpFile.close())); + .onFailure(ignored -> tmpFile.close()) + .compose(response -> response.pipeTo(tmpFile))); } private Future sendHttpRequest(RequestOptions requestOptions) { diff --git a/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java b/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java index d60ff696ba7..076e03e0f03 100644 --- a/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java +++ b/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java @@ -125,6 +125,7 @@ public void getShouldReturnFailureOnNotOkStatusCode() { final Future result = target.get(); // then + verify(tmpFile).close(); FutureAssertion.assertThat(result).isFailed() .hasMessage("Got unexpected response from server with status code 204 and message null"); } @@ -147,7 +148,6 @@ public void getShouldReturnExpectedResult() { final Future result = target.get(); // then - verify(tmpFile).close(); assertThat(result.result()).isEqualTo(SAVE_PATH); } @@ -178,7 +178,6 @@ public void getShouldReturnExpectedResultWhenCheckRemoteFileSizeIsTrue() { final Future result = target.get(); // then - verify(tmpFile).close(); assertThat(result.result()).isEqualTo(SAVE_PATH); }