Skip to content
Snippets Groups Projects

OZG-6223 OZG-7401 Timeout for async requests

Closed Krzysztof Witukiewicz requested to merge OZG-6223-zip-download-bug into main
9 unresolved threads

Default is 30 seconds, here set to 5 minutes (value in milliseconds)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Felix Reichenbach
  • Felix Reichenbach
  • Felix Reichenbach requested review from @felix

    requested review from @felix

  • Krzysztof Witukiewicz resolved all threads

    resolved all threads

  • added 2 commits

    • 7645c890 - OZG-6223 OZG-7381 Test for getFileSize
    • 625bd98b - OZG-6223 OZG-7381 Refactor ZipDownloadService

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 206 236
    207 237 @Nested
    208 238 class TestCreateZipFile {
  • 1 package de.ozgcloud.alfa.common.zipdownload;
  • 1 package de.ozgcloud.alfa.common.zipdownload;
  • 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);
      			}
    • Please register or sign in to reply
  • 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)) {
    • Static mock würde ich hier versuchen zu vermeiden

      		@Test
      		@SneakyThrows
      		void shouldDeleteFile() {
      			var file = TempFileUtils.createTmpFile().toFile();
      
      			new OzgZipFile(file).delete();
      
      			assertThat(file).doesNotExist();
      		}
    • Please register or sign in to reply
  • 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() {
    • Statt static mock, vielleicht sowas wie:

      		@Test
      		void shouldNotThrowException() {
      			var file = Path.of("path").toFile();
      
      			var zipFile = new OzgZipFile(file);
      
      			assertThatNoException().isThrownBy(ozgZipFile::delete);
      		}
    • Please register or sign in to reply
  • Please register or sign in to reply
    Loading