FINERACT-1678: Enable Scheduler API usage for batch manager only
This commit is contained in:
+1
@@ -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")),
|
||||
|
||||
+27
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user