FINERACT-1971: Fixing long running COB related tests

This commit is contained in:
Peter Bagrij
2024-03-27 12:55:35 +01:00
committed by Adam Saghy
parent b64b4b7105
commit d310d0dcbd
13 changed files with 180 additions and 369 deletions
@@ -18,9 +18,12 @@
*/
package org.apache.fineract.cob.api;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
@@ -28,6 +31,7 @@ import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -40,6 +44,8 @@ import org.apache.fineract.infrastructure.core.boot.FineractProfiles;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@@ -51,9 +57,14 @@ import org.springframework.stereotype.Component;
@Slf4j
public class InternalCOBApiResource implements InitializingBean {
private static final String DATETIME_PATTERN = "dd MMMM yyyy";
private final RetrieveLoanIdService retrieveLoanIdService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final ToApiJsonSerializer<List> toApiJsonSerializerForList;
private final LoanRepositoryWrapper loanRepositoryWrapper;
protected DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATETIME_PATTERN);
@Override
@SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
@@ -80,4 +91,16 @@ public class InternalCOBApiResource implements InitializingBean {
return toApiJsonSerializerForList.serialize(settings, loanCOBPartitions);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Path("fast-forward-cob-date-of-loan/{loanId}")
public void updateLoanCobLastDate(@Context final UriInfo uriInfo, @PathParam("loanId") long loanId, String jsonBody) {
JsonElement root = JsonParser.parseString(jsonBody);
String lastClosedBusinessDate = root.getAsJsonObject().get("lastClosedBusinessDate").getAsString();
Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId);
LocalDate localDate = LocalDate.parse(lastClosedBusinessDate, dateTimeFormatter);
loan.setLastClosedBusinessDate(localDate);
loanRepositoryWrapper.save(loan);
}
}
@@ -18,6 +18,8 @@
*/
package org.apache.fineract.cob.loan;
import static org.apache.fineract.cob.loan.LoanCOBConstant.LOAN_COB_JOB_NAME;
import org.apache.fineract.cob.COBBusinessStepService;
import org.apache.fineract.cob.common.CustomJobParameterResolver;
import org.apache.fineract.cob.conditions.BatchManagerCondition;
@@ -85,7 +87,8 @@ public class LoanCOBManagerConfiguration {
@Bean
public Step loanCOBStep() {
return stepBuilderFactory.get(LoanCOBConstant.LOAN_COB_PARTITIONER_STEP)
.partitioner(LoanCOBConstant.LOAN_COB_WORKER_STEP, partitioner()).outputChannel(outboundRequests).build();
.partitioner(LoanCOBConstant.LOAN_COB_WORKER_STEP, partitioner())
.pollInterval(propertyService.getPollInterval(LOAN_COB_JOB_NAME)).outputChannel(outboundRequests).build();
}
@Bean
@@ -31,4 +31,6 @@ public interface PropertyService {
Integer getThreadPoolMaxPoolSize(String jobName);
Integer getThreadPoolQueueCapacity(String jobName);
Integer getPollInterval(String jobName);
}
@@ -60,6 +60,11 @@ public class PropertyServiceImpl implements PropertyService {
return getProperty(jobName, FineractProperties.PartitionedJobProperty::getThreadPoolQueueCapacity);
}
@Override
public Integer getPollInterval(String jobName) {
return getProperty(jobName, FineractProperties.PartitionedJobProperty::getPollInterval);
}
private Integer getProperty(String jobName, Function<? super FineractProperties.PartitionedJobProperty, Integer> function) {
List<FineractProperties.PartitionedJobProperty> jobProperties = fineractProperties.getPartitionedJob()
.getPartitionedJobProperties();
@@ -69,6 +69,7 @@ fineract.partitioned-job.partitioned-job-properties[0].thread-pool-core-pool-siz
fineract.partitioned-job.partitioned-job-properties[0].thread-pool-max-pool-size=${LOAN_COB_THREAD_POOL_MAX_POOL_SIZE:5}
fineract.partitioned-job.partitioned-job-properties[0].thread-pool-queue-capacity=${LOAN_COB_THREAD_POOL_QUEUE_CAPACITY:20}
fineract.partitioned-job.partitioned-job-properties[0].retry-limit=${LOAN_COB_RETRY_LIMIT:5}
fineract.partitioned-job.partitioned-job-properties[0].poll-interval=${LOAN_COB_POLL_INTERVAL:10000}
fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_SPRING_EVENTS_ENABLED:true}
fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false}
@@ -46,6 +46,7 @@ fineract.partitioned-job.partitioned-job-properties[0].thread-pool-core-pool-siz
fineract.partitioned-job.partitioned-job-properties[0].thread-pool-max-pool-size=1
fineract.partitioned-job.partitioned-job-properties[0].thread-pool-queue-capacity=1
fineract.partitioned-job.partitioned-job-properties[0].retry-limit=5
fineract.partitioned-job.partitioned-job-properties[0].poll-interval=10000
fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_SPRING_EVENTS_ENABLED:true}
fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false}