[FINERACT-1678] all Loan COB steps are completed if there is no loan to be processed
This commit is contained in:
committed by
Arnold Gálovics
parent
3b337c96ee
commit
4e52bd3a02
+2
@@ -21,6 +21,7 @@ package org.apache.fineract.cob.loan;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -54,6 +55,7 @@ public class FetchAndLockLoanTasklet implements Tasklet {
|
||||
LocalDate businessDate = LocalDate.parse(Objects.requireNonNull(businessDateParameter));
|
||||
List<Long> allNonClosedLoanIds = retrieveLoanIdService.retrieveLoanIdsNDaysBehind(NUMBER_OF_DAYS_BEHIND, businessDate);
|
||||
if (allNonClosedLoanIds.isEmpty()) {
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_IDS, Collections.emptyList());
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
List<Long> remainingIds = new ArrayList<>(allNonClosedLoanIds);
|
||||
|
||||
+1
-7
@@ -37,7 +37,6 @@ import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.launch.NoSuchJobExecutionException;
|
||||
import org.springframework.batch.core.partition.support.Partitioner;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@@ -58,17 +57,12 @@ public class LoanCOBPartitioner implements Partitioner {
|
||||
int partitionSize = propertyService.getPartitionSize(LoanCOBConstant.JOB_NAME);
|
||||
Set<BusinessStepNameAndOrder> cobBusinessSteps = cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class,
|
||||
LoanCOBConstant.LOAN_COB_JOB_NAME);
|
||||
if (cobBusinessSteps.isEmpty()) {
|
||||
stopJobExecution();
|
||||
return Map.of();
|
||||
}
|
||||
return getPartitions(partitionSize, cobBusinessSteps);
|
||||
}
|
||||
|
||||
private Map<String, ExecutionContext> getPartitions(int partitionSize, Set<BusinessStepNameAndOrder> cobBusinessSteps) {
|
||||
Map<String, ExecutionContext> partitions = new HashMap<>();
|
||||
|
||||
if (CollectionUtils.isEmpty(loanIds)) {
|
||||
if (cobBusinessSteps.isEmpty()) {
|
||||
stopJobExecution();
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public class LoanItemReader extends AbstractLoanItemReader {
|
||||
@BeforeStep
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void beforeStep(@NotNull StepExecution stepExecution) {
|
||||
|
||||
ExecutionContext executionContext = stepExecution.getExecutionContext();
|
||||
ExecutionContext jobExecutionContext = stepExecution.getJobExecution().getExecutionContext();
|
||||
List<Long> loanIds = (List<Long>) executionContext.get(LoanCOBConstant.LOAN_IDS);
|
||||
|
||||
+13
-10
@@ -19,7 +19,6 @@
|
||||
package org.apache.fineract.cob.loan;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -27,7 +26,6 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.cucumber.java8.En;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -70,12 +68,12 @@ public class LoanCOBPartitionerStepDefinitions implements En {
|
||||
.thenReturn(Collections.emptySet());
|
||||
lenient().when(jobExplorer.findRunningJobExecutions(JobName.LOAN_COB.name())).thenReturn(Set.of(new JobExecution(3L)));
|
||||
lenient().when(jobOperator.stop(3L)).thenReturn(Boolean.TRUE);
|
||||
loanIds = Collections.emptyList();
|
||||
} else if ("empty loanIds".equals(action)) {
|
||||
cobBusinessSteps.add(new BusinessStepNameAndOrder("Business step", 1L));
|
||||
lenient().when(cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
|
||||
.thenReturn(cobBusinessSteps);
|
||||
loanIds = new ArrayList<>();
|
||||
lenient().when(jobExplorer.findRunningJobExecutions(JobName.LOAN_COB.name())).thenThrow(new RuntimeException("fail"));
|
||||
loanIds = Collections.emptyList();
|
||||
} else if ("good".equals(action)) {
|
||||
cobBusinessSteps.add(new BusinessStepNameAndOrder("Business step", 1L));
|
||||
lenient().when(cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
|
||||
@@ -113,13 +111,18 @@ public class LoanCOBPartitionerStepDefinitions implements En {
|
||||
businessSteps.stream().findFirst().get().getStepName());
|
||||
assertEquals(1, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "2").get(LoanCOBConstant.LOAN_IDS)).size());
|
||||
assertEquals(3L, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "2").get(LoanCOBConstant.LOAN_IDS)).get(0));
|
||||
} else if ("empty loanIds".equals(action)) {
|
||||
verify(jobOperator, Mockito.times(0)).stop(Mockito.anyLong());
|
||||
assertEquals(1, resultItem.size());
|
||||
assertTrue(resultItem.containsKey(LoanCOBPartitioner.PARTITION_PREFIX + "1"));
|
||||
Set<BusinessStepNameAndOrder> businessSteps = (Set<BusinessStepNameAndOrder>) resultItem
|
||||
.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.BUSINESS_STEPS);
|
||||
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepOrder(),
|
||||
businessSteps.stream().findFirst().get().getStepOrder());
|
||||
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepName(),
|
||||
businessSteps.stream().findFirst().get().getStepName());
|
||||
assertEquals(0, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.LOAN_IDS)).size());
|
||||
}
|
||||
});
|
||||
|
||||
Then("throw exception LoanCOBPartitioner.partition method", () -> {
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
resultItem = this.loanCOBPartitioner.partition(2);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,4 @@ Feature: COB Loan partitioner Step
|
||||
|action|
|
||||
|empty steps|
|
||||
|good|
|
||||
|
||||
@cob
|
||||
Scenario Outline: LoanCOBPartitioner - run test: exception
|
||||
Given The LoanCOBPartitioner.partition method with action <action>
|
||||
Then throw exception LoanCOBPartitioner.partition method
|
||||
|
||||
Examples:
|
||||
|action|
|
||||
|empty loanIds|
|
||||
|empty loanIds|
|
||||
|
||||
Reference in New Issue
Block a user