From 419f2873cd678fa48b588687628c99175de2eb70 Mon Sep 17 00:00:00 2001 From: Evgeny Bardin <evgeny.bardin@external.mgm-cp.com> Date: Thu, 16 Jan 2025 16:05:35 +0100 Subject: [PATCH] OZG-7426 refactor grpc uploader --- .../binaryfile/GrpcFileUploadUtils.java | 23 ++++++++++--------- .../binaryfile/GrpcFileUploadUtilsTest.java | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtils.java b/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtils.java index e7aae2e..bd2e1af 100644 --- a/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtils.java +++ b/ozgcloud-common-lib/src/main/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtils.java @@ -103,25 +103,26 @@ public class GrpcFileUploadUtils { } public void cancelOnError(Throwable t) { - LOG.error("File tranfer canceled on error.", t); + LOG.error("File transfer canceled on error.", t); resultFuture.cancel(true); requestObserver.onError(t); closeStreams(); } void sendNext() { - if (!done.get()) { - waitForOberver(); - sendMetaData(); - do { - LOG.debug("Sending next chunk."); - sendNextChunk(); - } while (!done.get() && isReady()); - LOG.debug("Finished or waiting to become ready."); + if (done.get()) { + return; } + waitForOberver(); + sendMetaData(); + while (!done.get() && isReady()) { + LOG.debug("Sending next chunk"); + sendNextChunk(); + } + LOG.debug("Finished or waiting to become ready."); } - private boolean isReady() { + boolean isReady() { return requestObserver.isReady(); } @@ -166,7 +167,7 @@ public class GrpcFileUploadUtils { } void sendChunk(byte[] content, int length) { - LOG.debug("Sending {} byte Data.", length); + LOG.debug("Sending {} bytes.", length); var chunk = chunkBuilder.apply(content, length); requestObserver.onNext(chunk); } diff --git a/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtilsTest.java b/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtilsTest.java index 83e18f8..43afc19 100644 --- a/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtilsTest.java +++ b/ozgcloud-common-lib/src/test/java/de/ozgcloud/common/binaryfile/GrpcFileUploadUtilsTest.java @@ -115,6 +115,8 @@ class GrpcFileUploadUtilsTest { @Test void shouldSendNextChunk() { + doReturn(true).when(fileSender).isReady(); + fileSender.sendNext(); verify(fileSender).sendNextChunk(); -- GitLab