Fixed purge external events job

This commit is contained in:
Arnold Galovics
2022-12-29 12:38:16 +01:00
committed by Arnold Gálovics
parent 7a9e696ac8
commit 77ee43acb8
4 changed files with 10 additions and 9 deletions
@@ -18,7 +18,7 @@
*/
package org.apache.fineract.commands.domain;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
@@ -30,6 +30,6 @@ public interface CommandSourceRepository extends JpaRepository<CommandSource, Lo
@Modifying(flushAutomatically = true)
@Query("delete from CommandSource c where c.status = :status and c.madeOnDate is not null and c.madeOnDate <= :dateForPurgeCriteria")
void deleteOlderEventsWithStatus(CommandProcessingResultType status, LocalDate dateForPurgeCriteria);
void deleteOlderEventsWithStatus(Integer status, OffsetDateTime dateForPurgeCriteria);
}
@@ -18,7 +18,7 @@
*/
package org.apache.fineract.commands.jobs;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.commands.domain.CommandProcessingResultType;
@@ -43,8 +43,8 @@ public class PurgeProcessedCommandsTasklet implements Tasklet {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
try {
Long numberOfDaysForPurgeCriteria = configurationDomainService.retrieveProcessedCommandsPurgeDaysCriteria();
LocalDate dateForPurgeCriteria = DateUtils.getBusinessLocalDate().minusDays(numberOfDaysForPurgeCriteria);
repository.deleteOlderEventsWithStatus(CommandProcessingResultType.PROCESSED, dateForPurgeCriteria);
OffsetDateTime dateForPurgeCriteria = DateUtils.getOffsetDateTimeOfTenant().minusDays(numberOfDaysForPurgeCriteria);
repository.deleteOlderEventsWithStatus(CommandProcessingResultType.PROCESSED.getValue(), dateForPurgeCriteria);
} catch (Exception e) {
log.error("Error occurred while purging processed commands: ", e);
}
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.Map;
@@ -70,15 +71,15 @@ public class PurgeProcessedCommandsTaskletTest {
@Test
public void givenEventsForPurgeWhenTaskExecutionThenEventsPurgeForDaysCriteria() {
// given
ArgumentCaptor<LocalDate> dateCriteriaCaptor = ArgumentCaptor.forClass(LocalDate.class);
ArgumentCaptor<OffsetDateTime> dateCriteriaCaptor = ArgumentCaptor.forClass(OffsetDateTime.class);
when(configurationDomainService.retrieveProcessedCommandsPurgeDaysCriteria()).thenReturn(2L);
// when
resultStatus = underTest.execute(stepContribution, chunkContext);
// then
verify(repository, times(1)).deleteOlderEventsWithStatus(Mockito.any(), Mockito.any());
verify(repository).deleteOlderEventsWithStatus(Mockito.any(), dateCriteriaCaptor.capture());
LocalDate expectedDateForPurgeCriteriaTest = DateUtils.getBusinessLocalDate().minusDays(2);
LocalDate actualDateForPurgeCriteria = dateCriteriaCaptor.getValue();
OffsetDateTime expectedDateForPurgeCriteriaTest = DateUtils.getOffsetDateTimeOfTenant().minusDays(2);
OffsetDateTime actualDateForPurgeCriteria = dateCriteriaCaptor.getValue();
assertEquals(expectedDateForPurgeCriteriaTest, actualDateForPurgeCriteria);
assertEquals(RepeatStatus.FINISHED, resultStatus);
}
+1 -1
View File
@@ -57,7 +57,7 @@ cargo {
downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/tomcat-integration-tests")
}
startStopTimeout = 240000
startStopTimeout = 300000
sharedClasspath = configurations.driver
containerProperties {
def jvmArgs = '--add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.management/javax.management=ALL-UNNAMED --add-opens=java.naming/javax.naming=ALL-UNNAMED '