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 e7aae2efb9b16f1150e897a6a5b2414f22e81b41..bd2e1af28ab65d530f37fcf10e6be9b35282aad3 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 83e18f8a06855426be7aeb13e6ecdf3282bb7553..43afc1952c4ca845386c6ac722e3bb6c6259ff2a 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();