FINERACT-1724
- fixes the JPA exception which is raised when a message was redelivered and earlier all the loans got closed for that given partition.
This commit is contained in:
committed by
Arnold Gálovics
parent
f12430752f
commit
a45ff9a3e0
@@ -23,6 +23,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.cob.common.CustomJobParameterResolver;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.annotation.BeforeStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
@Slf4j
|
||||
public class LoanItemReader extends AbstractLoanItemReader {
|
||||
|
||||
private final RetrieveLoanIdService retrieveLoanIdService;
|
||||
@@ -61,9 +63,10 @@ public class LoanItemReader extends AbstractLoanItemReader {
|
||||
loanIds = retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter,
|
||||
customJobParameterResolver.getCustomJobParameterById(stepExecution, LoanCOBConstant.IS_CATCH_UP_PARAMETER_NAME)
|
||||
.map(Boolean::parseBoolean).orElse(false));
|
||||
|
||||
List<Long> lockedByCOBChunkProcessingAccountIds = getLoanIdsLockedWithChunkProcessingLock(loanIds);
|
||||
loanIds.retainAll(lockedByCOBChunkProcessingAccountIds);
|
||||
if (loanIds.size() > 0) {
|
||||
List<Long> lockedByCOBChunkProcessingAccountIds = getLoanIdsLockedWithChunkProcessingLock(loanIds);
|
||||
loanIds.retainAll(lockedByCOBChunkProcessingAccountIds);
|
||||
}
|
||||
}
|
||||
setRemainingData(new LinkedBlockingQueue<>(loanIds));
|
||||
}
|
||||
|
||||
@@ -101,6 +101,27 @@ class LoanItemReaderTest {
|
||||
Mockito.verifyNoMoreInteractions(loanRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanItemReadNoOpenLoansFound() throws Exception {
|
||||
// given
|
||||
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "test", "test", "UTC", null));
|
||||
LoanItemReader loanItemReader = new LoanItemReader(loanRepository, retrieveLoanIdService, customJobParameterResolver,
|
||||
loanLockingService);
|
||||
when(stepExecution.getExecutionContext()).thenReturn(executionContext);
|
||||
LoanCOBParameter loanCOBParameter = new LoanCOBParameter(1L, 5L);
|
||||
when(executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER)).thenReturn(loanCOBParameter);
|
||||
when(retrieveLoanIdService.retrieveAllNonClosedLoansByLastClosedBusinessDateAndMinAndMaxLoanId(loanCOBParameter, false))
|
||||
.thenReturn(new ArrayList<>(List.of()));
|
||||
|
||||
// when + then
|
||||
loanItemReader.beforeStep(stepExecution);
|
||||
Loan myLoan = loanItemReader.read();
|
||||
Assertions.assertNull(myLoan);
|
||||
|
||||
Mockito.verifyNoMoreInteractions(loanRepository);
|
||||
Mockito.verifyNoInteractions(loanLockingService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanItemReaderMultiThreadRead() throws Exception {
|
||||
// given
|
||||
|
||||
Reference in New Issue
Block a user