TSK-1973: Check CREATED events to avoid NullPointerException in HistoryCleanupJob (#2045)
* TSK-1973: Check CREATED events to avoid null pointer * TSK-1973: - extend log message - fix test name Co-authored-by: Artem Leitner <artem.leitner@novatec-gmbh.de>
This commit is contained in:
parent
b9ef00ef7c
commit
7daa1a0262
|
@ -161,17 +161,23 @@ public class HistoryCleanupJob extends AbstractTaskanaJob {
|
|||
mapping(TaskHistoryEvent::getTaskId, toList()))));
|
||||
|
||||
List<String> taskIdsToDeleteHistoryEventsFor = new ArrayList<>();
|
||||
String createdKey = TaskHistoryEventType.CREATED.getName();
|
||||
|
||||
taskHistoryIdsByEventTypeByParentBusinessProcessId.forEach(
|
||||
(parentBusinessProcessId, taskHistoryIdsByEventType) -> {
|
||||
if (taskHistoryIdsByEventType.get(TaskHistoryEventType.CREATED.getName()).size()
|
||||
if (!taskHistoryIdsByEventType.containsKey(createdKey)) {
|
||||
LOGGER.error(
|
||||
"Issue during history cleanup tasks with enabled parent business process. "
|
||||
+ "No events for parent business process {} with type {} found."
|
||||
+ "Please clean up those history events manually",
|
||||
parentBusinessProcessId,
|
||||
createdKey);
|
||||
} else if (taskHistoryIdsByEventType.get(createdKey).size()
|
||||
== taskHistoryIdsByEventType.entrySet().stream()
|
||||
.filter(
|
||||
not(entry -> entry.getKey().equals(TaskHistoryEventType.CREATED.getName())))
|
||||
.filter(not(entry -> entry.getKey().equals(createdKey)))
|
||||
.mapToInt(stringListEntry -> stringListEntry.getValue().size())
|
||||
.sum()) {
|
||||
taskIdsToDeleteHistoryEventsFor.addAll(
|
||||
taskHistoryIdsByEventType.get(TaskHistoryEventType.CREATED.getName()));
|
||||
taskIdsToDeleteHistoryEventsFor.addAll(taskHistoryIdsByEventType.get(createdKey));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -374,6 +374,59 @@ class HistoryCleanupJobAccTest extends AbstractAccTest {
|
|||
assertThat(getHistoryService().createTaskHistoryQuery().count()).isEqualTo(16);
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithAccessId(user = "admin")
|
||||
void should_NotCleanEvents_When_NoCreatedEventsForParentBusinessProcessIdExist()
|
||||
throws Exception {
|
||||
assertThat(getHistoryService().createTaskHistoryQuery().count()).isEqualTo(14);
|
||||
|
||||
TaskHistoryEvent toBeIgnored1 =
|
||||
createTaskHistoryEvent(
|
||||
"wbKey1",
|
||||
"taskId1",
|
||||
TaskHistoryEventType.CANCELLED.getName(),
|
||||
"wbKey2",
|
||||
"someUserId",
|
||||
"someDetails");
|
||||
toBeIgnored1.setCreated(Instant.now().minus(20, ChronoUnit.DAYS));
|
||||
toBeIgnored1.setParentBusinessProcessId("toBeIgnored1");
|
||||
|
||||
TaskHistoryEvent toBeIgnored2 =
|
||||
createTaskHistoryEvent(
|
||||
"wbKey1",
|
||||
"taskId2",
|
||||
TaskHistoryEventType.COMPLETED.getName(),
|
||||
"wbKey2",
|
||||
"someUserId",
|
||||
"someDetails");
|
||||
toBeIgnored2.setCreated(Instant.now().minus(20, ChronoUnit.DAYS));
|
||||
toBeIgnored2.setParentBusinessProcessId("toBeIgnored2");
|
||||
|
||||
TaskHistoryEvent toBeIgnored3 =
|
||||
createTaskHistoryEvent(
|
||||
"wbKey1",
|
||||
"taskId3",
|
||||
TaskHistoryEventType.TERMINATED.getName(),
|
||||
"wbKey2",
|
||||
"someUserId",
|
||||
"someDetails");
|
||||
toBeIgnored3.setCreated(Instant.now().minus(20, ChronoUnit.DAYS));
|
||||
toBeIgnored3.setParentBusinessProcessId("toBeIgnored3");
|
||||
|
||||
getHistoryService().create(toBeIgnored1);
|
||||
getHistoryService().create(toBeIgnored2);
|
||||
getHistoryService().create(toBeIgnored3);
|
||||
|
||||
assertThat(getHistoryService().createTaskHistoryQuery().count()).isEqualTo(17);
|
||||
|
||||
taskanaEngine.getConfiguration().setTaskCleanupJobAllCompletedSameParentBusiness(true);
|
||||
|
||||
HistoryCleanupJob job = new HistoryCleanupJob(taskanaEngine, null, null);
|
||||
job.run();
|
||||
|
||||
assertThat(getHistoryService().createTaskHistoryQuery().count()).isEqualTo(17);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_DeleteOldHistoryCleanupJobs_When_InitializingSchedule() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue