From 4960695d1fc0d231a5ccbfcfe722e2b6929a10fb Mon Sep 17 00:00:00 2001 From: Krzysztof Witukiewicz <krzysztof.witukiewicz@mgm-tp.com> Date: Thu, 23 Jan 2025 10:56:25 +0100 Subject: [PATCH] OZG-7262 OZG-7566 Notify callObserver about error --- .../GrpcBinaryFileServerDownloader.java | 2 +- .../GrpcBinaryFileServerDownloaderTest.java | 31 ++++++------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloader.java b/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloader.java index b992f42..cb4a208 100644 --- a/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloader.java +++ b/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloader.java @@ -143,7 +143,7 @@ public class GrpcBinaryFileServerDownloader<T> { } catch (Exception e) { closeOutputStream(); closeInputStream(); - throw new TechnicalException("Error occurred during downloading file content download.", e); + callObserver.onError(new TechnicalException("Error occurred during downloading file content download.", e)); } } diff --git a/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloaderTest.java b/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloaderTest.java index 6050e6b..483e38d 100644 --- a/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloaderTest.java +++ b/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcBinaryFileServerDownloaderTest.java @@ -26,7 +26,6 @@ package de.ozgcloud.common.binaryfile; import com.google.protobuf.ByteString; import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.test.ReflectionTestUtils; -import io.grpc.Context; import io.grpc.stub.CallStreamObserver; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; @@ -407,11 +406,6 @@ class GrpcBinaryFileServerDownloaderTest { verify(callObserver).onCompleted(); } - - @SneakyThrows - private boolean getRequestFinished() { - return ReflectionTestUtils.getField(downloader, "requestFinished", AtomicBoolean.class).get(); - } } @DisplayName("Handle safety") @@ -436,20 +430,10 @@ class GrpcBinaryFileServerDownloaderTest { setOutputStreamField(outputStream); } - @SneakyThrows - @Test - void shouldThrowTechnicalException() { - assertThatThrownBy(this::handleSafety).isInstanceOf(TechnicalException.class).extracting(Throwable::getCause).isEqualTo(exception); - } - @SneakyThrows @Test void shouldCloseOutputStream() { - try { - handleSafety(); - } catch (Exception e) { - // do nothing - } + handleSafety(); verify(outputStream).close(); } @@ -457,15 +441,18 @@ class GrpcBinaryFileServerDownloaderTest { @SneakyThrows @Test void shouldCloseInputStream() { - try { - handleSafety(); - } catch (Exception e) { - // do nothing - } + handleSafety(); verify(inputStream).close(); } + @Test + void shouldNotifyCallObserver() { + handleSafety(); + + verify(callObserver).onError(argThat(TechnicalException.class::isInstance)); + } + private void handleSafety() { downloader.handleSafety(this::dummyMethodThrowingException); } -- GitLab