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; 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.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
@@ -30,6 +30,6 @@ public interface CommandSourceRepository extends JpaRepository<CommandSource, Lo
@Modifying(flushAutomatically = true) @Modifying(flushAutomatically = true)
@Query("delete from CommandSource c where c.status = :status and c.madeOnDate is not null and c.madeOnDate <= :dateForPurgeCriteria") @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; package org.apache.fineract.commands.jobs;
import java.time.LocalDate; import java.time.OffsetDateTime;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.commands.domain.CommandProcessingResultType; import org.apache.fineract.commands.domain.CommandProcessingResultType;
@@ -43,8 +43,8 @@ public class PurgeProcessedCommandsTasklet implements Tasklet {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
try { try {
Long numberOfDaysForPurgeCriteria = configurationDomainService.retrieveProcessedCommandsPurgeDaysCriteria(); Long numberOfDaysForPurgeCriteria = configurationDomainService.retrieveProcessedCommandsPurgeDaysCriteria();
LocalDate dateForPurgeCriteria = DateUtils.getBusinessLocalDate().minusDays(numberOfDaysForPurgeCriteria); OffsetDateTime dateForPurgeCriteria = DateUtils.getOffsetDateTimeOfTenant().minusDays(numberOfDaysForPurgeCriteria);
repository.deleteOlderEventsWithStatus(CommandProcessingResultType.PROCESSED, dateForPurgeCriteria); repository.deleteOlderEventsWithStatus(CommandProcessingResultType.PROCESSED.getValue(), dateForPurgeCriteria);
} catch (Exception e) { } catch (Exception e) {
log.error("Error occurred while purging processed commands: ", 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 static org.mockito.Mockito.when;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -70,15 +71,15 @@ public class PurgeProcessedCommandsTaskletTest {
@Test @Test
public void givenEventsForPurgeWhenTaskExecutionThenEventsPurgeForDaysCriteria() { public void givenEventsForPurgeWhenTaskExecutionThenEventsPurgeForDaysCriteria() {
// given // given
ArgumentCaptor<LocalDate> dateCriteriaCaptor = ArgumentCaptor.forClass(LocalDate.class); ArgumentCaptor<OffsetDateTime> dateCriteriaCaptor = ArgumentCaptor.forClass(OffsetDateTime.class);
when(configurationDomainService.retrieveProcessedCommandsPurgeDaysCriteria()).thenReturn(2L); when(configurationDomainService.retrieveProcessedCommandsPurgeDaysCriteria()).thenReturn(2L);
// when // when
resultStatus = underTest.execute(stepContribution, chunkContext); resultStatus = underTest.execute(stepContribution, chunkContext);
// then // then
verify(repository, times(1)).deleteOlderEventsWithStatus(Mockito.any(), Mockito.any()); verify(repository, times(1)).deleteOlderEventsWithStatus(Mockito.any(), Mockito.any());
verify(repository).deleteOlderEventsWithStatus(Mockito.any(), dateCriteriaCaptor.capture()); verify(repository).deleteOlderEventsWithStatus(Mockito.any(), dateCriteriaCaptor.capture());
LocalDate expectedDateForPurgeCriteriaTest = DateUtils.getBusinessLocalDate().minusDays(2); OffsetDateTime expectedDateForPurgeCriteriaTest = DateUtils.getOffsetDateTimeOfTenant().minusDays(2);
LocalDate actualDateForPurgeCriteria = dateCriteriaCaptor.getValue(); OffsetDateTime actualDateForPurgeCriteria = dateCriteriaCaptor.getValue();
assertEquals(expectedDateForPurgeCriteriaTest, actualDateForPurgeCriteria); assertEquals(expectedDateForPurgeCriteriaTest, actualDateForPurgeCriteria);
assertEquals(RepeatStatus.FINISHED, resultStatus); assertEquals(RepeatStatus.FINISHED, resultStatus);
} }
+1 -1
View File
@@ -57,7 +57,7 @@ cargo {
downloadDir = file("$buildDir/download") downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/tomcat-integration-tests") extractDir = file("$buildDir/tomcat-integration-tests")
} }
startStopTimeout = 240000 startStopTimeout = 300000
sharedClasspath = configurations.driver sharedClasspath = configurations.driver
containerProperties { 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 ' 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 '