FINERACT-1724-COB-hardlocked-loans-and-inline-cob-issue

This commit is contained in:
Ruchi Dhamankar
2023-06-22 10:21:43 +02:00
committed by Adam Saghy
parent 03fd2ac7ce
commit d704d3d027
13 changed files with 231 additions and 15 deletions
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import io.cucumber.java8.En;
@@ -35,6 +36,7 @@ import org.apache.fineract.cob.common.CustomJobParameterResolver;
import org.apache.fineract.cob.data.LoanCOBParameter;
import org.apache.fineract.cob.domain.LoanAccountLock;
import org.apache.fineract.cob.domain.LockOwner;
import org.apache.fineract.cob.exceptions.LoanLockCannotBeAppliedException;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
@@ -45,6 +47,8 @@ import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
public class ApplyLoanLockTaskletStepDefinitions implements En {
@@ -54,10 +58,11 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
private FineractProperties fineractProperties = mock(FineractProperties.class);
private FineractProperties.FineractQueryProperties fineractQueryProperties = mock(FineractProperties.FineractQueryProperties.class);
private RetrieveLoanIdService retrieveLoanIdService = mock(RetrieveLoanIdService.class);
private TransactionTemplate transactionTemplate = spy(TransactionTemplate.class);
private CustomJobParameterResolver customJobParameterResolver = mock(CustomJobParameterResolver.class);
private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(fineractProperties, loanLockingService,
retrieveLoanIdService, customJobParameterResolver);
retrieveLoanIdService, customJobParameterResolver, transactionTemplate);
private RepeatStatus resultItem;
private StepContribution stepContribution;
@@ -81,6 +86,25 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
lenient().when(loanLockingService.findAllByLoanIdIn(Mockito.anyList())).thenThrow(new RuntimeException("fail"));
} else if ("db-error-first-try".equals(action)) {
LoanAccountLock lock1 = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault()));
LoanAccountLock lock3 = new LoanAccountLock(3L, LockOwner.LOAN_INLINE_COB_PROCESSING,
LocalDate.now(ZoneId.systemDefault()));
List<LoanAccountLock> accountLocks = List.of(lock1, lock3);
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
lenient().when(loanLockingService.findAllByLoanIdIn(Mockito.anyList())).thenReturn(accountLocks);
Mockito.doThrow(new RuntimeException("db error")).when(loanLockingService).applyLock(Mockito.anyList(), any());
} else if ("db-error-not-recoverable".equals(action)) {
LoanAccountLock lock1 = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault()));
LoanAccountLock lock3 = new LoanAccountLock(3L, LockOwner.LOAN_INLINE_COB_PROCESSING,
LocalDate.now(ZoneId.systemDefault()));
List<LoanAccountLock> accountLocks = List.of(lock1, lock3);
stepContribution.getStepExecution().setCommitCount(4);
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
lenient().when(loanLockingService.findAllByLoanIdIn(Mockito.anyList())).thenReturn(accountLocks);
Mockito.doThrow(new RuntimeException("db error")).when(loanLockingService).applyLock(Mockito.anyList(), any());
} else {
LoanAccountLock lock1 = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault()));
LoanAccountLock lock3 = new LoanAccountLock(3L, LockOwner.LOAN_INLINE_COB_PROCESSING,
@@ -90,6 +114,7 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
lenient().when(loanLockingService.findAllByLoanIdIn(Mockito.anyList())).thenReturn(accountLocks);
}
transactionTemplate.setTransactionManager(mock(PlatformTransactionManager.class));
lenient().when(customJobParameterResolver.getCustomJobParameterSet(any())).thenReturn(Optional.empty());
});
@@ -111,5 +136,15 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
resultItem = applyLoanLockTasklet.execute(stepContribution, null);
});
});
Then("throw LoanLockCannotBeAppliedException exception ApplyLoanLockTasklet.execute method", () -> {
assertThrows(LoanLockCannotBeAppliedException.class, () -> {
resultItem = applyLoanLockTasklet.execute(stepContribution, null);
});
});
Then("ApplyLoanLockTasklet.execute result should be retry", () -> {
assertEquals(RepeatStatus.CONTINUABLE, resultItem);
});
}
}
@@ -33,8 +33,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.fineract.cob.common.CustomJobParameterResolver;
import org.apache.fineract.cob.data.LoanCOBParameter;
import org.apache.fineract.cob.domain.LoanAccountLock;
import org.apache.fineract.cob.domain.LockOwner;
import org.apache.fineract.cob.exceptions.LoanReadException;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
@@ -52,7 +55,10 @@ public class LoanItemReaderStepDefinitions implements En {
private CustomJobParameterResolver customJobParameterResolver = mock(CustomJobParameterResolver.class);
private LoanItemReader loanItemReader = new LoanItemReader(loanRepository, retrieveLoanIdService, customJobParameterResolver);
private LoanLockingService lockingService = mock(LoanLockingService.class);
private LoanItemReader loanItemReader = new LoanItemReader(loanRepository, retrieveLoanIdService, customJobParameterResolver,
lockingService);
private Loan loan = mock(Loan.class);
@@ -70,7 +76,7 @@ public class LoanItemReaderStepDefinitions implements En {
List<Long> splitAccounts = new ArrayList<>();
if (!loanIds.isEmpty()) {
List<String> splitStr = Splitter.on(',').splitToList(loanIds);
splitAccounts = splitStr.stream().map(Long::parseLong).toList();
splitAccounts = splitStr.stream().map(Long::parseLong).collect(Collectors.toList());
minLoanId = splitAccounts.get(0);
maxLoanId = splitAccounts.get(splitAccounts.size() - 1);
}
@@ -87,7 +93,16 @@ public class LoanItemReaderStepDefinitions implements En {
businessDates.put(BusinessDateType.BUSINESS_DATE, businessDate);
businessDates.put(BusinessDateType.COB_DATE, businessDate.minusDays(1));
ThreadLocalContextUtil.setBusinessDates(businessDates);
LoanAccountLock loanAccountLock = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING, businessDate.minusDays(1));
LoanAccountLock loanAccountLockNegativeNumberTest = new LoanAccountLock(-1L, LockOwner.LOAN_COB_CHUNK_PROCESSING,
businessDate.minusDays(1));
lenient().when(customJobParameterResolver.getCustomJobParameterSet(any())).thenReturn(Optional.empty());
lenient().when(lockingService.findAllByLoanIdInAndLockOwner(List.of(1L), LockOwner.LOAN_COB_CHUNK_PROCESSING))
.thenReturn(List.of(loanAccountLock));
lenient().when(lockingService.findAllByLoanIdInAndLockOwner(List.of(1L, 2L), LockOwner.LOAN_COB_CHUNK_PROCESSING))
.thenReturn(List.of(loanAccountLock));
lenient().when(lockingService.findAllByLoanIdInAndLockOwner(List.of(-1L), LockOwner.LOAN_COB_CHUNK_PROCESSING))
.thenReturn(List.of(loanAccountLockNegativeNumberTest));
loanItemReader.beforeStep(stepExecution);
@@ -36,4 +36,23 @@ Feature: COB Apply Loan Lock Step
Examples:
|action|
|error|
|error|
@cob
Scenario Outline: ApplyLoanLockTasklet - run test: database exception not recoverable after retries
Given The ApplyLoanLockTasklet.execute method with action <action>
Then throw LoanLockCannotBeAppliedException exception ApplyLoanLockTasklet.execute method
Examples:
|action|
|db-error-not-recoverable|
@cob
Scenario Outline: ApplyLoanLockTasklet - run test: database exception first try
Given The ApplyLoanLockTasklet.execute method with action <action>
When ApplyLoanLockTasklet.execute method executed
Then ApplyLoanLockTasklet.execute result should be retry
Examples:
|action|
|db-error-first-try|