Skip to content
Snippets Groups Projects

Ozg 7262 fix unfinished downloads

Merged Krzysztof Witukiewicz requested to merge OZG-7262-fix-unfinished-downloads into main
All threads resolved!
1 file
+ 1
69
Compare changes
  • Side-by-side
  • Inline
@@ -27,7 +27,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -40,7 +39,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@@ -486,7 +484,7 @@ class GrpcBinaryFileServerDownloaderTest {
@ParameterizedTest
@MethodSource("provideArguments")
void shouldReturnValue(boolean requestFinished, boolean ready, boolean expected) {
ReflectionTestUtils.setField(downloader, "requestFinished", new AtomicBoolean(requestFinished));
setRequestFinishedField(requestFinished);
lenient().when(callObserver.isReady()).thenReturn(ready);
var canSendChunks = downloader.canSendChunks();
@@ -635,72 +633,6 @@ class GrpcBinaryFileServerDownloaderTest {
return (TechnicalException) ReflectionTestUtils.getField(downloader, "downloadError", AtomicReference.class).get();
}
private void setDownloadFinishedField(boolean downloadFinished) {
ReflectionTestUtils.setField(downloader, "downloadFinished", new AtomicBoolean(downloadFinished));
}
private boolean getDownloadFinished() {
return ReflectionTestUtils.getField(downloader, "downloadFinished", AtomicBoolean.class).get();
}
private static class GrpcResponseDummy {
}
@Nested
class TestStreams {
private static final int CHUNK_SIZE = 255 * 1024;
private PipedInputStream inputStream;
private PipedOutputStream outputStream;
@SneakyThrows
@BeforeEach
void init() {
outputStream = new PipedOutputStream();
inputStream = new PipedInputStream(CHUNK_SIZE);
outputStream.connect(inputStream);
}
@SneakyThrows
@Test
void shouldReadIncompleteFile() {
var fileBuffer = new byte[CHUNK_SIZE];
var readBuffer = new byte[CHUNK_SIZE];
try (FileInputStream fileInputStream = new FileInputStream("/Users/kwitukiewicz/Documents/books/__Debt__The_First_5_000_Years.pdf")) {
fileInputStream.read(fileBuffer, 0, 255);
outputStream.write(fileBuffer, 0, 1);
var read = inputStream.read(readBuffer, 0, CHUNK_SIZE);
assertThat(read).isEqualTo(1);
}
}
@SneakyThrows
@Test
void shouldReadAfterOutputStreamWasClosed() {
var fileBuffer = new byte[CHUNK_SIZE];
var readBuffer = new byte[CHUNK_SIZE * 2];
try (FileInputStream fileInputStream = new FileInputStream("/Users/kwitukiewicz/Documents/books/__Debt__The_First_5_000_Years.pdf")) {
fileInputStream.read(fileBuffer, 0, fileBuffer.length);
outputStream.write(fileBuffer);
outputStream.close();
var read = inputStream.read(readBuffer);
assertThat(read).isEqualTo(CHUNK_SIZE);
read = inputStream.read(readBuffer);
assertThat(read).isEqualTo(-1);
}
}
@SneakyThrows
@AfterEach
void cleanup() {
outputStream.close();
inputStream.close();
}
}
}
\ No newline at end of file
Loading