Skip to content

Commit

Permalink
chore(merge): release-10.2.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Sep 14, 2024
2 parents e6323f1 + 7945e69 commit 6566c2a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Durations.ONE_MINUTE;
import static org.awaitility.Durations.ONE_SECOND;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;

import java.util.List;
Expand Down Expand Up @@ -131,13 +133,17 @@ public void retryAJob_should_update_job_log_when_execution_fails_again() throws
getCommandAPI().register("except", "Throws Exception when scheduling a job", AddJobCommand.class.getName());
try {
getCommandAPI().execute("except", Map.of());
FailedJob failedJob = await().until(() -> getProcessAPI().getFailedJobs(0, 100), hasSize(1)).get(0);
// Job can trigger in up to 'org.quartz.scheduler.idleWaitTime' milliseconds, so better wait long enough:
FailedJob failedJob = await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(
() -> getProcessAPI().getFailedJobs(0, 100), hasSize(1)).get(0);

//when
getProcessAPI().replayFailedJob(failedJob.getJobDescriptorId());

//then
failedJob = await().until(() -> getProcessAPI().getFailedJobs(0, 100), hasSize(1)).get(0);
// Job can trigger in up to 'org.quartz.scheduler.idleWaitTime' milliseconds, so better wait long enough:
failedJob = await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND)
.until(() -> getProcessAPI().getFailedJobs(0, 100), hasSize(1)).get(0);
assertThat(failedJob.getJobName()).isEqualTo(THROWS_EXCEPTION_JOB);
assertThat(failedJob.getDescription()).isEqualTo("Throw an exception when 'throwException'=true");
assertThat(failedJob.getLastMessage()).contains(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ public void setAttributes(Map<String, Serializable> attributes) {

@Override
public void execute() throws SJobExecutionException {
System.err.println(
"Executing job:"
+ failOnce + ", "
+ failOnceWithRetryable + ", "
+ throwsError + ", "
+ throwsJobExecutionException);
if (failOnce) {
if (variableStorage.getVariableValue("nbJobException", 0) == 0) {
variableStorage.setVariable("nbJobException", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Durations.FIVE_HUNDRED_MILLISECONDS;
import static org.awaitility.Durations.*;
import static org.bonitasoft.engine.scheduler.impl.JobThatMayThrowErrorOrJobException.*;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.*;
Expand All @@ -29,7 +29,6 @@
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

import org.awaitility.core.ConditionTimeoutException;
import org.bonitasoft.engine.bpm.CommonBPMServicesTest;
import org.bonitasoft.engine.persistence.QueryOptions;
import org.bonitasoft.engine.scheduler.JobService;
Expand Down Expand Up @@ -118,7 +117,6 @@ public void doNotThrowAnExceptionWhenDeletingAnUnknownJob() throws Exception {
* * pause jobs
* * trigger new job are not executed
* * resume the jobs resume it really
* *
*/
@Test
public void pause_and_resume_jobs_of_a_tenant() throws Exception {
Expand Down Expand Up @@ -153,7 +151,8 @@ public void should_be_able_to_list_job_that_failed_because_of_an_Error() throws
singletonMap(TYPE, ERROR));

//we have failed job
List<SFailedJob> failedJobs = await().until(() -> inTx(() -> jobService.getFailedJobs(0, 100)), hasSize(1));
List<SFailedJob> failedJobs = await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND)
.until(() -> inTx(() -> jobService.getFailedJobs(0, 100)), hasSize(1));
assertThat(failedJobs).hasOnlyOneElementSatisfying(f -> assertThat(f.getLastMessage()).contains("an Error"));
}

Expand All @@ -165,35 +164,25 @@ public void should_be_able_to_restart_a_job_that_failed_because_of_a_SJobExecuti
singletonMap(TYPE, JOBEXCEPTION));
SJobDescriptor persistedJobDescriptor = getFirstPersistedJob();

//we have failed job
List<SFailedJob> failedJobs = await().until(() -> inTx(() -> jobService.getFailedJobs(0, 3)), hasSize(1));
// we should have a failed job:
// Job can trigger in up to 'org.quartz.scheduler.idleWaitTime' milliseconds, so better wait long enough:
List<SFailedJob> failedJobs = await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> {
System.out.println("condition not here yet. Waiting again...");
return inTx(() -> jobService.getFailedJobs(0, 3));
}, hasSize(1));
assertThat(failedJobs.get(0).getLastMessage()).contains("a Job exception");

// small sleep because quartz does not always immediately delete the associated trigger (done in the quartz Thread)
// because of that, it can cause issues when rescheduling (Foreign key violation)
Thread.sleep(100);
// reschedule the job: should be no more exception
try {
inTx(() -> {
schedulerService.retryJobThatFailed(persistedJobDescriptor.getId(),
toJobParameterList(singletonMap(TYPE, NO_EXCEPTION)));
return null;
});
// System.err.println("nbSuccess: " + storage.getVariableValue("nbSuccess"));
await().pollDelay(FIVE_HUNDRED_MILLISECONDS)
.until(() -> storage.getVariableValue("nbSuccess", 0).equals(1));
} catch (ConditionTimeoutException e) {
// System.err.println("nbSuccess: " + storage.getVariableValue("nbSuccess"));
System.err.println("retrying to reschedule failed job");
inTx(() -> {
schedulerService.retryJobThatFailed(persistedJobDescriptor.getId(),
toJobParameterList(singletonMap(TYPE, NO_EXCEPTION)));
return null;
});
await().pollDelay(FIVE_HUNDRED_MILLISECONDS)
.until(() -> storage.getVariableValue("nbSuccess", 0).equals(1));
System.err.println("Yes, retrying the job later solved the problem!");
}
inTx(() -> {
schedulerService.retryJobThatFailed(persistedJobDescriptor.getId(),
toJobParameterList(singletonMap(TYPE, NO_EXCEPTION)));
return null;
});
await().pollDelay(FIVE_HUNDRED_MILLISECONDS).atMost(ONE_MINUTE).pollInterval(ONE_SECOND)
.until(() -> storage.getVariableValue("nbSuccess", 0).equals(1));
}

@Test
Expand All @@ -206,7 +195,8 @@ public void should_be_able_to_restart_a_cron_job_that_failed_because_of_a_SJobEx
SJobDescriptor persistedJobDescriptor = getFirstPersistedJob();

//ensure there is more than one failure: i.e. cron is still triggering new jobs
await().until(() -> storage.getVariableValue("nbJobException", 0), isGreaterThan(1));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbJobException", 0),
isGreaterThan(1));
//wait a little because the failure is registered later...
Callable<List<SFailedJob>> getFailedJobs = () -> {
try {
Expand Down Expand Up @@ -241,7 +231,8 @@ public void describeTo(Description description) {
});

//ensure there is more than one success: i.e. cron is still triggering new jobs
await().until(() -> storage.getVariableValue("nbSuccess", 0), isGreaterThan(1));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbSuccess", 0),
isGreaterThan(1));
//ensure no more failed job is present
assertThat(inTx(() -> jobService.getFailedJobs(0, 100))).isEmpty();
}
Expand All @@ -255,8 +246,10 @@ public void should_keep_a_failed_job_when_failing_once() throws Exception {
SJobDescriptor persistedJobDescriptor = getFirstPersistedJob();

//this job fail only the first time
await().until(() -> storage.getVariableValue("nbJobException", 0), isGreaterThan(0));
await().until(() -> storage.getVariableValue("nbSuccess", 0), isGreaterThan(0));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbJobException", 0),
isGreaterThan(0));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbSuccess", 0),
isGreaterThan(0));

List<SFailedJob> sFailedJobs = inTx(() -> jobService.getFailedJobs(0, 100));

Expand All @@ -272,7 +265,8 @@ public void should_keep_a_failed_job_when_failing_once() throws Exception {
});

//ensure there is more than one success: i.e. cron is still triggering new jobs
await().until(() -> storage.getVariableValue("nbSuccess", 0), isGreaterThan(1));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbSuccess", 0),
isGreaterThan(1));
//ensure no more failed job is present
assertThat(inTx(() -> jobService.getFailedJobs(0, 100))).isEmpty();
}
Expand All @@ -286,8 +280,10 @@ public void should_let_quartz_retry_a_job_that_failed_because_of_a_SRetryableExc
SJobDescriptor persistedJobDescriptor = getFirstPersistedJob();

//this job fail once and is immediately retried, even if its a one shot job
await().until(() -> storage.getVariableValue("nbJobException", 0), isGreaterThan(0));
await().until(() -> storage.getVariableValue("nbSuccess", 0), isGreaterThan(0));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbJobException", 0),
isGreaterThan(0));
await().atMost(ONE_MINUTE).pollInterval(ONE_SECOND).until(() -> storage.getVariableValue("nbSuccess", 0),
isGreaterThan(0));

List<SFailedJob> sFailedJobs = inTx(() -> jobService.getFailedJobs(0, 100));

Expand Down

0 comments on commit 6566c2a

Please sign in to comment.