Skip to content
Snippets Groups Projects
Commit 419f2873 authored by Evgeny Bardin's avatar Evgeny Bardin
Browse files

OZG-7426 refactor grpc uploader

parent 2622c313
No related branches found
No related tags found
No related merge requests found
......@@ -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()) {
if (done.get()) {
return;
}
waitForOberver();
sendMetaData();
do {
LOG.debug("Sending next chunk.");
while (!done.get() && isReady()) {
LOG.debug("Sending next chunk");
sendNextChunk();
} while (!done.get() && isReady());
LOG.debug("Finished or waiting to become ready.");
}
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);
}
......
......@@ -115,6 +115,8 @@ class GrpcFileUploadUtilsTest {
@Test
void shouldSendNextChunk() {
doReturn(true).when(fileSender).isReady();
fileSender.sendNext();
verify(fileSender).sendNextChunk();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment