Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
fixed cleanup endlessly retrying to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin-Isenring-Bit committed Jul 3, 2023
1 parent 1a93b05 commit a724f3b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>ch.admin.bag.covidcertificate</groupId>
<artifactId>cc-management-service</artifactId>
<version>4.12.2</version>
<version>4.12.3</version>
<name>cc-management-service</name>
<description>Service for generating Covid Certificates</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void processCleanup() {
log.error("CLEANUP | {} - cleaning failed, retry #{}/{}; throwed '{}'", effort.getName(), ++retry, MAX_RETRIES, e);
if (retry < MAX_RETRIES) {
deleted = -1;
} else {
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;

import java.io.EOFException;
import java.time.LocalDate;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -59,12 +62,34 @@ void processCleanup_oneSpotConfigured() {

when(cleanupService.create(eq("name2"), any(Cleanup.class))).thenReturn(effort2);
when(cleanupService.getCount(eq(effort2), any(LocalDate.class))).thenReturn(5L);
when(cleanupService.delete(eq(effort2), any(LocalDate.class), eq(false))).thenReturn(0L);
when(cleanupService.delete(eq(effort2), any(LocalDate.class), eq(true))).thenReturn(0L);
when(cleanupService.delete(eq(effort2), any(LocalDate.class), eq(false))).thenReturn(0L);
doNothing().when(cleanupService).destroy(eq(effort2));

cleanupScheduler.processCleanup();

verify(cleanupConfig).getSpots();
}

@Test
void processCleanup_deleteThrowsException() {
Map<String, Cleanup> map = new TreeMap<>();
map.put("name1", new Cleanup());
map.put("name2", new Cleanup());
when(cleanupConfig.getSpots()).thenReturn(map);

CleanupService.CleaningEffort effort1 = new CleanupService.CleaningEffort("name1",
"countQuery", "deleteUntilQuery", "deleteUntilBatchQuery", 5,
null, null);

when(cleanupService.create(eq("name1"), any(Cleanup.class))).thenReturn(effort1);
when(cleanupService.getCount(eq(effort1), any(LocalDate.class))).thenReturn(5L);
when(cleanupService.delete(eq(effort1), any(LocalDate.class), eq(true)))
.thenAnswer(invocation -> { throw new EOFException(null); });
doNothing().when(cleanupService).destroy(eq(effort1));

cleanupScheduler.processCleanup();

verify(cleanupConfig).getSpots();
}
}

0 comments on commit a724f3b

Please sign in to comment.