OZG-6223 OZG-7401 Timeout for async requests
9 unresolved threads
9 unresolved threads
Default is 30 seconds, here set to 5 minutes (value in milliseconds)
Merge request reports
Activity
- Resolved by Krzysztof Witukiewicz
- Resolved by Krzysztof Witukiewicz
- Resolved by Krzysztof Witukiewicz
- Resolved by Krzysztof Witukiewicz
- Resolved by Krzysztof Witukiewicz
requested review from @felix
27 import lombok.SneakyThrows; 28 import lombok.extern.log4j.Log4j2; 29 30 @Log4j2 31 class OzgZipFileTest { 32 33 private final File file = Path.of("/some/dummy/path/dummy-archive.zip").toFile(); 34 @Spy 35 private final OzgZipFile ozgZipFile = new OzgZipFile(file); 36 37 @Nested 38 class TestGetSize { 39 40 @Test 41 void shouldCallFilesSize() { 42 try (MockedStatic<Files> mockedFiles = mockStatic(Files.class)) { Ich finde es besser statische mocks von fremden Klassen zu vermeiden. Ich hätte Tests in der Art erwartet:
private static final byte[] BYTES = LoremIpsum.getInstance().getParagraphs(1, 2).getBytes(); @Test @SneakyThrows void shouldReturnFileSize() { var file = TempFileUtils.createTmpFile().toFile(); try (var outputStream = new FileOutputStream(file)) { outputStream.write(BYTES); } var size = new OzgZipFile(file).getSize(); assertThat(size).isEqualTo(BYTES.length); } @Test void shouldThrowTechnicalException() { var file = new OzgZipFile(Path.of("path").toFile()); assertThrows(TechnicalException.class, file::getSize); }
6 import java.io.OutputStream; 7 import java.nio.file.Files; 8 9 import de.ozgcloud.common.errorhandling.TechnicalException; 10 import lombok.AccessLevel; 11 import lombok.RequiredArgsConstructor; 12 import lombok.extern.log4j.Log4j2; 13 14 @RequiredArgsConstructor(access = AccessLevel.PACKAGE) 15 @Log4j2 16 public class OzgZipFile { 17 18 private final File zipFile; 19 20 public long getSize() { 21 try { 124 void shouldCallDeleteAfterSuccessfulTransfer() { 125 mockFileInputStream = mockConstruction(FileInputStream.class); 126 127 ozgZipFile.streamTo(fileOutputStream); 128 129 verify(ozgZipFile).delete(); 130 } 131 132 @Test 133 void shouldCallDeleteAfterException() { 134 mockFileInputStream = mockConstruction(FileInputStream.class, 135 (mock, context) -> { 136 when(mock.transferTo(fileOutputStream)).thenThrow(IOException.class); 137 }); 138 139 assertThatThrownBy(() -> ozgZipFile.streamTo(fileOutputStream)); 125 mockFileInputStream = mockConstruction(FileInputStream.class); 126 127 ozgZipFile.streamTo(fileOutputStream); 128 129 verify(ozgZipFile).delete(); 130 } 131 132 @Test 133 void shouldCallDeleteAfterException() { 134 mockFileInputStream = mockConstruction(FileInputStream.class, 135 (mock, context) -> { 136 when(mock.transferTo(fileOutputStream)).thenThrow(IOException.class); 137 }); 138 139 assertThatThrownBy(() -> ozgZipFile.streamTo(fileOutputStream)); 140 verify(ozgZipFile).delete(); 134 mockFileInputStream = mockConstruction(FileInputStream.class, 135 (mock, context) -> { 136 when(mock.transferTo(fileOutputStream)).thenThrow(IOException.class); 137 }); 138 139 assertThatThrownBy(() -> ozgZipFile.streamTo(fileOutputStream)); 140 verify(ozgZipFile).delete(); 141 } 142 } 143 144 @Nested 145 class TestDelete { 146 147 @Test 148 void shouldDeleteFile() { 149 try (MockedStatic<Files> mockedFiles = mockStatic(Files.class)) { 142 } 143 144 @Nested 145 class TestDelete { 146 147 @Test 148 void shouldDeleteFile() { 149 try (MockedStatic<Files> mockedFiles = mockStatic(Files.class)) { 150 ozgZipFile.delete(); 151 152 mockedFiles.verify(() -> Files.delete(file.toPath())); 153 } 154 } 155 156 @Test 157 void shouldNotThrowException() {
Please register or sign in to reply