[FINERACT-1724] making partition for big parameter lists
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
ca5c7d8747
commit
071cdae69b
+8
-1
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -42,7 +43,9 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
|
||||
ArgumentCaptor<LoanAccountLock> valueCaptor = ArgumentCaptor.forClass(LoanAccountLock.class);
|
||||
private LoanAccountLockRepository accountLockRepository = mock(LoanAccountLockRepository.class);
|
||||
private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(accountLockRepository);
|
||||
private FineractProperties fineractProperties = mock(FineractProperties.class);
|
||||
private FineractProperties.FineractQueryProperties fineractQueryProperties = mock(FineractProperties.FineractQueryProperties.class);
|
||||
private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(accountLockRepository, fineractProperties);
|
||||
private RepeatStatus resultItem;
|
||||
private StepContribution stepContribution;
|
||||
|
||||
@@ -56,12 +59,16 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
this.stepContribution = new StepContribution(stepExecution);
|
||||
|
||||
if ("error".equals(action)) {
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(this.accountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenThrow(new RuntimeException("fail"));
|
||||
} else {
|
||||
LoanAccountLock lock1 = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING);
|
||||
LoanAccountLock lock2 = new LoanAccountLock(2L, LockOwner.LOAN_COB_PARTITIONING);
|
||||
LoanAccountLock lock3 = new LoanAccountLock(3L, LockOwner.LOAN_INLINE_COB_PROCESSING);
|
||||
List<LoanAccountLock> accountLocks = List.of(lock1, lock2, lock3);
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(this.accountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenReturn(accountLocks);
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -35,6 +35,7 @@ import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.mockito.Mockito;
|
||||
@@ -48,6 +49,9 @@ public class FetchAndLockLoanStepDefinitions implements En {
|
||||
private final LoanAccountLockRepository loanAccountLockRepository = mock(LoanAccountLockRepository.class);
|
||||
|
||||
private final RetrieveLoanIdService retrieveLoanIdService = mock(RetrieveLoanIdService.class);
|
||||
private final FineractProperties fineractProperties = mock(FineractProperties.class);
|
||||
private final FineractProperties.FineractQueryProperties fineractQueryProperties = mock(
|
||||
FineractProperties.FineractQueryProperties.class);
|
||||
StepContribution contribution;
|
||||
private FetchAndLockLoanTasklet fetchAndLockLoanTasklet;
|
||||
private String action;
|
||||
@@ -65,17 +69,25 @@ public class FetchAndLockLoanStepDefinitions implements En {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(Collections.emptyList());
|
||||
} else if ("good".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenReturn(Collections.emptyList());
|
||||
} else if ("soft lock".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList()))
|
||||
.thenReturn(List.of(new LoanAccountLock(1L, LockOwner.LOAN_COB_PARTITIONING)));
|
||||
} else if ("inline cob".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList()))
|
||||
.thenReturn(List.of(new LoanAccountLock(2L, LockOwner.LOAN_INLINE_COB_PROCESSING)));
|
||||
} else if ("chunk processing".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList()))
|
||||
.thenReturn(List.of(new LoanAccountLock(3L, LockOwner.LOAN_COB_CHUNK_PROCESSING)));
|
||||
}
|
||||
@@ -85,7 +97,7 @@ public class FetchAndLockLoanStepDefinitions implements En {
|
||||
contribution = new StepContribution(stepExecution);
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.BUSINESS_DATE_PARAMETER_NAME,
|
||||
LocalDate.now(ZoneId.systemDefault()).toString());
|
||||
fetchAndLockLoanTasklet = new FetchAndLockLoanTasklet(loanAccountLockRepository, retrieveLoanIdService);
|
||||
fetchAndLockLoanTasklet = new FetchAndLockLoanTasklet(loanAccountLockRepository, retrieveLoanIdService, fineractProperties);
|
||||
});
|
||||
|
||||
When("FetchAndLockLoanTasklet.execute method executed", () -> {
|
||||
|
||||
+32
@@ -23,6 +23,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -35,6 +37,7 @@ import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
@@ -59,6 +62,10 @@ class InlineLoanCOBExecutorServiceImplTest {
|
||||
private InlineLoanCOBExecutionDataParser dataParser;
|
||||
@Mock
|
||||
private LoanRepository loanRepository;
|
||||
@Mock
|
||||
private FineractProperties fineractProperties;
|
||||
@Mock
|
||||
private FineractProperties.FineractQueryProperties fineractQueryProperties;
|
||||
|
||||
@Test
|
||||
void shouldExceptionThrownIfLoanIsAlreadyLocked() {
|
||||
@@ -72,10 +79,35 @@ class InlineLoanCOBExecutorServiceImplTest {
|
||||
ThreadLocalContextUtil.setBusinessDates(businessDates);
|
||||
|
||||
when(transactionTemplate.execute(any())).thenThrow(new LoanAccountLockCannotBeOverruledException(""));
|
||||
when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
when(dataParser.parseExecution(any())).thenReturn(List.of(1L));
|
||||
when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
when(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(any(), anyList())).thenReturn(List.of(loan));
|
||||
assertThrows(LoanAccountLockCannotBeOverruledException.class, () -> testObj.executeInlineJob(command, "INLINE_LOAN_COB"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldListBePartitioned() {
|
||||
JsonCommand command = mock(JsonCommand.class);
|
||||
LoanIdAndLastClosedBusinessDate loan1 = mock(LoanIdAndLastClosedBusinessDate.class);
|
||||
LoanIdAndLastClosedBusinessDate loan2 = mock(LoanIdAndLastClosedBusinessDate.class);
|
||||
LoanIdAndLastClosedBusinessDate loan3 = mock(LoanIdAndLastClosedBusinessDate.class);
|
||||
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
|
||||
HashMap<BusinessDateType, LocalDate> businessDates = new HashMap<>();
|
||||
LocalDate businessDate = LocalDate.now(ZoneId.systemDefault());
|
||||
businessDates.put(BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
businessDates.put(BusinessDateType.COB_DATE, businessDate.minusDays(1));
|
||||
ThreadLocalContextUtil.setBusinessDates(businessDates);
|
||||
|
||||
when(transactionTemplate.execute(any())).thenThrow(new LoanAccountLockCannotBeOverruledException(""));
|
||||
when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
when(dataParser.parseExecution(any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(2);
|
||||
when(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(any(), anyList())).thenReturn(List.of(loan1, loan2, loan3));
|
||||
assertThrows(LoanAccountLockCannotBeOverruledException.class, () -> testObj.executeInlineJob(command, "INLINE_LOAN_COB"));
|
||||
verify(loanRepository, times(2)).findAllNonClosedLoansBehindOrNullByLoanIds(any(), anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldOldestCloseBusinessDateReturnWithCorrectDate()
|
||||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
|
||||
+24
-7
@@ -42,6 +42,7 @@ import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
|
||||
import org.apache.fineract.cob.service.InlineLoanCOBExecutorServiceImpl;
|
||||
import org.apache.fineract.cob.service.LoanAccountLockService;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
@@ -80,6 +81,10 @@ class LoanCOBApiFilterTest {
|
||||
private InlineLoanCOBExecutorServiceImpl inlineLoanCOBExecutorService;
|
||||
@Mock
|
||||
private LoanRepository loanRepository;
|
||||
@Mock
|
||||
private FineractProperties fineractProperties;
|
||||
@Mock
|
||||
private FineractProperties.FineractQueryProperties fineractQueryProperties;
|
||||
|
||||
@Mock
|
||||
private LoanRescheduleRequestRepository loanRescheduleRequestRepository;
|
||||
@@ -145,7 +150,9 @@ class LoanCOBApiFilterTest {
|
||||
given(request.getPathInfo()).willReturn("/loans/invalid2LoanId/charges");
|
||||
given(request.getMethod()).willReturn(HTTPMethods.POST.value());
|
||||
given(context.authenticatedUser()).willReturn(appUser);
|
||||
given(loanRepository.findAllNonClosedLoansBehindByLoanIds(
|
||||
given(fineractProperties.getQuery()).willReturn(fineractQueryProperties);
|
||||
given(fineractQueryProperties.getInClauseParameterSizeLimit()).willReturn(65000);
|
||||
given(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(
|
||||
eq(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)), anyList()))
|
||||
.willReturn(Collections.emptyList());
|
||||
|
||||
@@ -187,7 +194,9 @@ class LoanCOBApiFilterTest {
|
||||
given(loanAccountLockService.isLoanHardLocked(2L)).willReturn(false);
|
||||
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(false);
|
||||
given(context.authenticatedUser()).willReturn(appUser);
|
||||
given(loanRepository.findAllNonClosedLoansBehindByLoanIds(
|
||||
given(fineractProperties.getQuery()).willReturn(fineractQueryProperties);
|
||||
given(fineractQueryProperties.getInClauseParameterSizeLimit()).willReturn(65000);
|
||||
given(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(
|
||||
eq(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)), anyList()))
|
||||
.willReturn(Collections.emptyList());
|
||||
|
||||
@@ -214,7 +223,9 @@ class LoanCOBApiFilterTest {
|
||||
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(false);
|
||||
given(context.authenticatedUser()).willReturn(appUser);
|
||||
given(loanRepository.findIdByExternalId(any())).willReturn(2L);
|
||||
given(loanRepository.findAllNonClosedLoansBehindByLoanIds(
|
||||
given(fineractProperties.getQuery()).willReturn(fineractQueryProperties);
|
||||
given(fineractQueryProperties.getInClauseParameterSizeLimit()).willReturn(65000);
|
||||
given(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(
|
||||
eq(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)), anyList()))
|
||||
.willReturn(Collections.emptyList());
|
||||
|
||||
@@ -239,11 +250,13 @@ class LoanCOBApiFilterTest {
|
||||
given(request.getMethod()).willReturn(HTTPMethods.POST.value());
|
||||
given(loanAccountLockService.isLoanHardLocked(2L)).willReturn(false);
|
||||
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(false);
|
||||
given(fineractProperties.getQuery()).willReturn(fineractQueryProperties);
|
||||
given(fineractQueryProperties.getInClauseParameterSizeLimit()).willReturn(65000);
|
||||
LoanRescheduleRequest rescheduleRequest = mock(LoanRescheduleRequest.class);
|
||||
given(loanRescheduleRequestRepository.getLoanIdByRescheduleRequestId(resourceId)).willReturn(Optional.of(2L));
|
||||
given(context.authenticatedUser()).willReturn(appUser);
|
||||
|
||||
given(loanRepository.findAllNonClosedLoansBehindByLoanIds(
|
||||
given(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(
|
||||
eq(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)), anyList()))
|
||||
.willReturn(Collections.emptyList());
|
||||
|
||||
@@ -288,8 +301,10 @@ class LoanCOBApiFilterTest {
|
||||
given(request.getPathInfo()).willReturn("/loans/2?command=approve");
|
||||
given(request.getMethod()).willReturn(HTTPMethods.POST.value());
|
||||
given(loanAccountLockService.isLoanHardLocked(2L)).willReturn(false);
|
||||
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(false);
|
||||
given(loanRepository.findAllNonClosedLoansBehindByLoanIds(
|
||||
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(true);
|
||||
given(fineractProperties.getQuery()).willReturn(fineractQueryProperties);
|
||||
given(fineractQueryProperties.getInClauseParameterSizeLimit()).willReturn(65000);
|
||||
given(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(
|
||||
eq(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)), anyList()))
|
||||
.willReturn(Collections.singletonList(result));
|
||||
|
||||
@@ -320,7 +335,9 @@ class LoanCOBApiFilterTest {
|
||||
given(request.getMethod()).willReturn(HTTPMethods.POST.value());
|
||||
given(loanAccountLockService.isLoanHardLocked(2L)).willReturn(false);
|
||||
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(false);
|
||||
given(loanRepository.findAllNonClosedLoansBehindByLoanIds(
|
||||
given(fineractProperties.getQuery()).willReturn(fineractQueryProperties);
|
||||
given(fineractQueryProperties.getInClauseParameterSizeLimit()).willReturn(65000);
|
||||
given(loanRepository.findAllNonClosedLoansBehindOrNullByLoanIds(
|
||||
eq(ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)), anyList()))
|
||||
.willReturn(Collections.emptyList());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user