This is an automated email from the ASF dual-hosted git repository.
adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new f1c89ac91 FINERACT-1678: Enable Scheduler API usage for batch manager
only
f1c89ac91 is described below
commit f1c89ac9144793dbdb4158b4429d594592959c77
Author: Adam Saghy <[email protected]>
AuthorDate: Wed Mar 1 16:20:17 2023 +0100
FINERACT-1678: Enable Scheduler API usage for batch manager only
---
.../filter/FineractInstanceModeApiFilter.java | 1 +
.../filter/FineractInstanceModeApiFilterTest.java | 27 ++++++++++++++++++++++
.../LoanCOBCatchUpInstanceModeIntegrationTest.java | 20 ++++++++++++++++
.../common/SchedulerJobHelper.java | 4 +---
4 files changed, 49 insertions(+), 3 deletions(-)
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilter.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilter.java
index 3ff84bafa..dea80f259 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilter.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilter.java
@@ -43,6 +43,7 @@ public class FineractInstanceModeApiFilter extends
OncePerRequestFilter {
private static final List<ExceptionListItem> EXCEPTION_LIST = List
.of(item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi
-> pi.startsWith("/jobs")),
+
item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi ->
pi.startsWith("/scheduler")),
item(FineractProperties.FineractModeProperties::isBatchManagerEnabled, pi ->
pi.startsWith("/loans/catch-up")),
item(FineractProperties.FineractModeProperties::isBatchManagerEnabled,
pi -> pi.startsWith("/loans/is-catch-up-running")),
diff --git
a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilterTest.java
b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilterTest.java
index bc395d2ed..ad20c1693 100644
---
a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilterTest.java
+++
b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/instancemode/filter/FineractInstanceModeApiFilterTest.java
@@ -368,4 +368,31 @@ class FineractInstanceModeApiFilterTest {
// then
verify(filterChain).doFilter(request, response);
}
+
+ @Test
+ void
testDoFilterInternal_ShouldLetSchedulerApiThrough_WhenFineractIsInBatchManagerMode()
throws ServletException, IOException {
+ // given
+ FineractProperties.FineractModeProperties modeProperties =
InstanceModeMock.createModeProps(false, false, false, true);
+ given(fineractProperties.getMode()).willReturn(modeProperties);
+ given(request.getMethod()).willReturn(HttpMethod.POST.name());
+ given(request.getPathInfo()).willReturn("/scheduler?command=start");
+ // when
+ underTest.doFilterInternal(request, response, filterChain);
+ // then
+ verify(filterChain).doFilter(request, response);
+ }
+
+ @Test
+ void
testDoFilterInternal_ShouldNotLetSchedulerApiThrough_WhenFineractIsNotInBatchManagerMode()
throws ServletException, IOException {
+ // given
+ FineractProperties.FineractModeProperties modeProperties =
InstanceModeMock.createModeProps(true, true, true, false);
+ given(fineractProperties.getMode()).willReturn(modeProperties);
+ given(request.getMethod()).willReturn(HttpMethod.POST.name());
+ given(request.getPathInfo()).willReturn("/scheduler?command=start");
+ // when
+ underTest.doFilterInternal(request, response, filterChain);
+ // then
+ verifyNoInteractions(filterChain);
+ verify(response).setStatus(HttpStatus.SC_METHOD_NOT_ALLOWED);
+ }
}
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBCatchUpInstanceModeIntegrationTest.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBCatchUpInstanceModeIntegrationTest.java
index eeff29972..fee1c902d 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBCatchUpInstanceModeIntegrationTest.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBCatchUpInstanceModeIntegrationTest.java
@@ -31,6 +31,7 @@ import
org.apache.fineract.client.util.CallFailedRuntimeException;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
+import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanCOBCatchUpHelper;
import
org.apache.fineract.integrationtests.support.instancemode.ConfigureInstanceMode;
@@ -46,6 +47,8 @@ public class LoanCOBCatchUpInstanceModeIntegrationTest {
private LoanCOBCatchUpHelper loanCOBCatchUpHelper;
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
+ private SchedulerJobHelper schedulerJobHelper;
+ private Boolean originalSchedulerStatus;
@BeforeEach
public void setup() throws InterruptedException {
@@ -54,6 +57,8 @@ public class LoanCOBCatchUpInstanceModeIntegrationTest {
this.responseSpec = new
ResponseSpecBuilder().expectStatusCode(200).build();
this.requestSpec = new
RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " +
Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ schedulerJobHelper = new SchedulerJobHelper(requestSpec);
+ originalSchedulerStatus = schedulerJobHelper.getSchedulerStatus();
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec,
responseSpec, Boolean.TRUE);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec,
BusinessDateType.BUSINESS_DATE, todaysDate);
@@ -99,9 +104,24 @@ public class LoanCOBCatchUpInstanceModeIntegrationTest {
loanCOBCatchUpHelper.executeRetrieveOldestCOBProcessedLoan();
}
+ @ConfigureInstanceMode(readEnabled = false, writeEnabled = false,
batchWorkerEnabled = false, batchManagerEnabled = true)
+ @Test
+ public void testSchedulerWorksWhenInBatchManagerMode() {
+ schedulerJobHelper.updateSchedulerStatus(false);
+ }
+
+ @ConfigureInstanceMode(readEnabled = true, writeEnabled = true,
batchWorkerEnabled = true, batchManagerEnabled = false)
+ @Test
+ public void testSchedulerDoesNotWorksWhenNotInBatchManagerMode() {
+ CallFailedRuntimeException exception =
assertThrows(CallFailedRuntimeException.class,
+ () -> schedulerJobHelper.updateSchedulerStatus(false));
+ assertEquals(405, exception.getResponse().code());
+ }
+
@AfterEach
public void tearDown() throws InterruptedException {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec,
responseSpec, Boolean.FALSE);
+ schedulerJobHelper.updateSchedulerStatus(originalSchedulerStatus);
}
}
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
index ba554031f..3636f4f2a 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
@@ -97,9 +97,7 @@ public class SchedulerJobHelper extends IntegrationTest {
public void updateSchedulerStatus(final boolean on) {
String command = on ? "start" : "stop";
- final String UPDATE_SCHEDULER_STATUS_URL =
"/fineract-provider/api/v1/scheduler?command=" + command + "&" +
Utils.TENANT_IDENTIFIER;
- LOG.info("------------------------ UPDATING SCHEDULER STATUS
-------------------------");
- Utils.performServerPost(requestSpec, response202Spec,
UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
+ ok(fineract().jobsScheduler.changeSchedulerStatus(command));
}
public Map<String, Object> updateSchedulerJob(int jobId, final boolean
active) {