Skip to content
Snippets Groups Projects
Commit 5093746c authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7573 only read content if EOF is false

parent f7cfe07f
No related branches found
No related tags found
1 merge request!9Ozg 7573 forward vorgang
......@@ -156,13 +156,14 @@ public class EingangStubReceiverStreamObserver implements StreamObserver<GrpcRou
if (Objects.isNull(currentFile)) {
throw new IllegalStateException("File content received before metadata.");
}
try {
pipedOutput.write(content.getContent().toByteArray());
if (content.getIsEndOfFile()) {
handleEndOfFile();
if (content.getIsEndOfFile()) {
handleEndOfFile();
} else {
try {
pipedOutput.write(content.getContent().toByteArray());
} catch (IOException e) {
throw new TechnicalException("Error when writing file content.", e);
}
} catch (IOException e) {
throw new TechnicalException("Error when writing file content.", e);
}
}
......
......@@ -502,42 +502,61 @@ class EingangStubReceiverStreamObserverTest {
setCurrentFile(incomingFile);
}
@Test
@SneakyThrows
void shouldWriteContentToOutputStream() {
observer.storeFileContent(GrpcFileContentTestFactory.create());
@Nested
class TestOnEndOfFile {
verify(pipedOutput).write(GrpcFileContentTestFactory.CONTENT);
}
private GrpcFileContent fileContent = GrpcFileContentTestFactory.createBuilder().setIsEndOfFile(true).build();
@Test
void shouldCallHandleEndOfFile() {
doNothing().when(observer).handleEndOfFile();
var fileContent = GrpcFileContentTestFactory.createBuilder().setIsEndOfFile(true).build();
@BeforeEach
void setUp() {
doNothing().when(observer).handleEndOfFile();
}
@Test
void shouldCallHandleEndOfFile() {
observer.storeFileContent(fileContent);
verify(observer).handleEndOfFile();
}
observer.storeFileContent(fileContent);
@Test
@SneakyThrows
void shouldNotWriteContentToOutputStream() {
observer.storeFileContent(fileContent);
verify(observer).handleEndOfFile();
verify(pipedOutput, never()).write(any());
}
}
@Test
void shouldNotCallHandleEndOfFile() {
var fileContent = GrpcFileContentTestFactory.createBuilder().setIsEndOfFile(false).build();
@Nested
class TestOnNotEndOfFile {
observer.storeFileContent(fileContent);
private GrpcFileContent fileContent = GrpcFileContentTestFactory.createBuilder().setIsEndOfFile(false).build();
verify(observer, never()).handleEndOfFile();
}
@Test
@SneakyThrows
void shouldWriteContentToOutputStream() {
observer.storeFileContent(fileContent);
@Test
@SneakyThrows
void shouldThrowTechnicalExceptionOnIOException() {
doThrow(new IOException()).when(pipedOutput).write(any());
var fileContent = GrpcFileContentTestFactory.create();
verify(pipedOutput).write(GrpcFileContentTestFactory.CONTENT);
}
assertThrows(TechnicalException.class, () -> {
@Test
void shouldNotCallHandleEndOfFile() {
observer.storeFileContent(fileContent);
});
verify(observer, never()).handleEndOfFile();
}
@Test
@SneakyThrows
void shouldThrowTechnicalExceptionOnIOException() {
doThrow(new IOException()).when(pipedOutput).write(any());
assertThrows(TechnicalException.class, () -> {
observer.storeFileContent(fileContent);
});
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment