Skip to content

Commit

Permalink
FINERACT-1971: Fixing long running COB related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reluxa authored and adamsaghy committed Mar 27, 2024
1 parent b64b4b7 commit d310d0d
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 349 deletions.
1 change: 1 addition & 0 deletions config/docker/env/fineract-manager.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ FINERACT_MODE_BATCH_MANAGER_ENABLED=true
FINERACT_MODE_BATCH_WORKER_ENABLED=false
LOAN_COB_CHUNK_SIZE=10
LOAN_COB_PARTITION_SIZE=10
LOAN_COB_POLL_INTERVAL=1000
OTEL_SERVICE_NAME=fineract-manager
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public static class PartitionedJobProperty {
private Integer threadPoolMaxPoolSize;
private Integer threadPoolQueueCapacity;
private Integer retryLimit;
private Integer pollInterval;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
*/
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;
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;
Expand All @@ -40,6 +44,8 @@
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;
Expand All @@ -51,9 +57,14 @@
@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")
Expand All @@ -80,4 +91,16 @@ public String getCobPartitions(@Context final UriInfo uriInfo, @PathParam("parti
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +87,8 @@ public LoanCOBPartitioner partitioner() {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface PropertyService {
Integer getThreadPoolMaxPoolSize(String jobName);

Integer getThreadPoolQueueCapacity(String jobName);

Integer getPollInterval(String jobName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public Integer getThreadPoolQueueCapacity(String jobName) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public abstract class BaseLoanIntegrationTest {
protected static final String DATETIME_PATTERN = "dd MMMM yyyy";

protected final ResponseSpecification responseSpec = createResponseSpecification(Matchers.is(200));
protected final ResponseSpecification responseSpec204 = createResponseSpecification(Matchers.is(204));

private final String fullAdminAuthKey = getFullAdminAuthKey();

Expand Down
Loading

0 comments on commit d310d0d

Please sign in to comment.