more clean up in SchedulerJobsTest (re. FINERACT-922)
This does NOT, yet, fix FINERACT-922, but it splits the old test into new smaller test methods, which (hopefully) should always pass, except for the last one.
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
404f055b65
commit
c4797ab96b
+36
-31
@@ -42,71 +42,76 @@ public class SchedulerJobsTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Utils.initializeRESTAssured();
|
Utils.initializeRESTAssured();
|
||||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||||
this.requestSpec.header("Fineract-Platform-TenantId", "default");
|
requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec);
|
schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlippingSchedulerStatus() throws InterruptedException {
|
public void testFlippingSchedulerStatus() throws InterruptedException {
|
||||||
// Retrieving Status of Scheduler
|
// Retrieving Status of Scheduler
|
||||||
Boolean schedulerStatus = this.schedulerJobHelper.getSchedulerStatus();
|
Boolean schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||||
if (schedulerStatus == true) {
|
if (schedulerStatus == true) {
|
||||||
this.schedulerJobHelper.updateSchedulerStatus("stop");
|
schedulerJobHelper.updateSchedulerStatus("stop");
|
||||||
schedulerStatus = this.schedulerJobHelper.getSchedulerStatus();
|
schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||||
// Verifying Status of the Scheduler after stopping
|
// Verifying Status of the Scheduler after stopping
|
||||||
assertEquals("Verifying Scheduler Job Status", false, schedulerStatus);
|
assertEquals("Verifying Scheduler Job Status", false, schedulerStatus);
|
||||||
} else {
|
} else {
|
||||||
this.schedulerJobHelper.updateSchedulerStatus("start");
|
schedulerJobHelper.updateSchedulerStatus("start");
|
||||||
schedulerStatus = this.schedulerJobHelper.getSchedulerStatus();
|
schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||||
// Verifying Status of the Scheduler after starting
|
// Verifying Status of the Scheduler after starting
|
||||||
assertEquals("Verifying Scheduler Job Status", true, schedulerStatus);
|
assertEquals("Verifying Scheduler Job Status", true, schedulerStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // TODO FINERACT-852
|
public void testFlippingJobsActiveStatus() throws InterruptedException {
|
||||||
public void testSchedulerJobs() throws InterruptedException {
|
// Stop the Scheduler while we test flapping jobs' active on/off, to avoid side effects
|
||||||
// Retrieving All Scheduler Jobs
|
schedulerJobHelper.updateSchedulerStatus("stop");
|
||||||
List<Map> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs();
|
|
||||||
assertNotNull(allSchedulerJobsData);
|
|
||||||
|
|
||||||
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
|
||||||
Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
|
|
||||||
|
|
||||||
|
// For each retrieved scheduled job (by ID)...
|
||||||
|
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||||
// Retrieving Scheduler Job by ID
|
// Retrieving Scheduler Job by ID
|
||||||
Map schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
Map<String, Object> schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
assertNotNull(schedulerJob);
|
|
||||||
|
|
||||||
Boolean active = (Boolean) schedulerJob.get("active");
|
Boolean active = (Boolean) schedulerJob.get("active");
|
||||||
|
active = !active;
|
||||||
if (active == true) {
|
|
||||||
active = false;
|
|
||||||
} else {
|
|
||||||
active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updating Scheduler Job
|
// Updating Scheduler Job
|
||||||
Map changes = this.schedulerJobHelper.updateSchedulerJob(jobId.toString(), active.toString());
|
Map<String, Object> changes = schedulerJobHelper.updateSchedulerJob(jobId, active.toString());
|
||||||
|
|
||||||
// Verifying Scheduler Job updates
|
// Verifying Scheduler Job updates
|
||||||
assertEquals("Verifying Scheduler Job Updates", active, changes.get("active"));
|
assertEquals("Verifying Scheduler Job Updates", active, changes.get("active"));
|
||||||
|
|
||||||
|
schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
|
assertEquals("Verifying Get Scheduler Job", active, schedulerJob.get("active"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore // TODO FINERACT-852 & FINERACT-922
|
||||||
|
public void testSchedulerJobs() throws InterruptedException {
|
||||||
|
// For each retrieved scheduled job (by ID)...
|
||||||
|
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||||
|
// Retrieving Scheduler Job by ID
|
||||||
|
Map<String, Object> schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
|
|
||||||
// Executing Scheduler Job
|
// Executing Scheduler Job
|
||||||
this.schedulerJobHelper.runSchedulerJob(this.requestSpec, jobId.toString());
|
schedulerJobHelper.runSchedulerJob(requestSpec, jobId.toString());
|
||||||
|
|
||||||
// Retrieving Scheduler Job by ID
|
// Retrieving Scheduler Job by ID
|
||||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
assertNotNull(schedulerJob);
|
assertNotNull(schedulerJob);
|
||||||
|
|
||||||
// Waiting for Job to complete
|
// Waiting for Job to complete
|
||||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
assertNotNull(schedulerJob);
|
assertNotNull(schedulerJob);
|
||||||
System.out.println("Job " +jobId.toString() +" is Still Running");
|
System.out.println("Job " + jobId +" is Still Running");
|
||||||
}
|
}
|
||||||
List<Map> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(jobId.toString());
|
List<Map> jobHistoryData = schedulerJobHelper.getSchedulerJobHistory(jobId);
|
||||||
|
|
||||||
// Verifying the Status of the Recently executed Scheduler Job
|
// Verifying the Status of the Recently executed Scheduler Job
|
||||||
assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
||||||
|
|||||||
+3
-2
@@ -36,6 +36,7 @@ import java.util.Calendar;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||||
import org.apache.fineract.integrationtests.common.HolidayHelper;
|
import org.apache.fineract.integrationtests.common.HolidayHelper;
|
||||||
@@ -772,12 +773,12 @@ public class SchedulerJobsTestResults {
|
|||||||
|
|
||||||
this.schedulerJobHelper.executeJob(JobName);
|
this.schedulerJobHelper.executeJob(JobName);
|
||||||
|
|
||||||
HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
Map<String, Object> schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
|
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||||
Thread.sleep(15000);
|
Thread.sleep(15000);
|
||||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-9
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.integrationtests.common;
|
package org.apache.fineract.integrationtests.common;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import io.restassured.builder.ResponseSpecBuilder;
|
import io.restassured.builder.ResponseSpecBuilder;
|
||||||
import io.restassured.specification.RequestSpecification;
|
import io.restassured.specification.RequestSpecification;
|
||||||
@@ -26,6 +28,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.ToIntFunction;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@@ -47,17 +51,23 @@ public class SchedulerJobHelper {
|
|||||||
this.response202Spec = responseSpec;
|
this.response202Spec = responseSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getAllSchedulerJobs() {
|
private List getAllSchedulerJobs() {
|
||||||
final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
|
final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
||||||
final ArrayList response = Utils.performServerGet(requestSpec, response200Spec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
final ArrayList response = Utils.performServerGet(requestSpec, response200Spec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap getSchedulerJobById(final String jobId) {
|
public List<Integer> getAllSchedulerJobIds() {
|
||||||
|
ToIntFunction<Map> mapper = map -> (Integer) map.get("jobId");
|
||||||
|
return getAllSchedulerJobs().stream().mapToInt(mapper).boxed().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getSchedulerJobById(int jobId) {
|
||||||
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
||||||
final HashMap response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
final Map<String, Object> response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
||||||
|
assertNotNull(response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,10 +84,10 @@ public class SchedulerJobHelper {
|
|||||||
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map updateSchedulerJob(final String jobId, final String active) {
|
public Map<String, Object> updateSchedulerJob(int jobId, final String active) {
|
||||||
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
||||||
final Map response = Utils.performServerPut(requestSpec, response200Spec, UPDATE_SCHEDULER_JOB_URL,
|
final Map<String, Object> response = Utils.performServerPut(requestSpec, response200Spec, UPDATE_SCHEDULER_JOB_URL,
|
||||||
updateSchedulerJobAsJSON(active), "changes");
|
updateSchedulerJobAsJSON(active), "changes");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -89,7 +99,7 @@ public class SchedulerJobHelper {
|
|||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getSchedulerJobHistory(final String jobId) {
|
public List getSchedulerJobHistory(int jobId) {
|
||||||
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER;
|
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------");
|
System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------");
|
||||||
final Map response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_STATUS_URL, "");
|
final Map response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_STATUS_URL, "");
|
||||||
@@ -122,18 +132,18 @@ public class SchedulerJobHelper {
|
|||||||
runSchedulerJob(this.requestSpec, jobId.toString());
|
runSchedulerJob(this.requestSpec, jobId.toString());
|
||||||
|
|
||||||
// Retrieving Scheduler Job by ID
|
// Retrieving Scheduler Job by ID
|
||||||
Map schedulerJob = getSchedulerJobById(jobId.toString());
|
Map schedulerJob = getSchedulerJobById(jobId);
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
|
|
||||||
// Waiting for Job to complete
|
// Waiting for Job to complete
|
||||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||||
Thread.sleep(15000);
|
Thread.sleep(15000);
|
||||||
schedulerJob = getSchedulerJobById(jobId.toString());
|
schedulerJob = getSchedulerJobById(jobId);
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
System.out.println("Job is Still Running");
|
System.out.println("Job is Still Running");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map> jobHistoryData = getSchedulerJobHistory(jobId.toString());
|
List<Map> jobHistoryData = getSchedulerJobHistory(jobId);
|
||||||
|
|
||||||
Assert.assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
Assert.assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user