Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.67.x-blue] [RHPAM-4872] Fix RepeatMode=FIXED when deleted records > RecordsPerTransaction #2387

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public void executeGivenJob(RequestInfo request) {
ctx.setData("ClassLoader", cl);

// add scheduled execution time
ctx.setData("scheduledExecutionTime", request.getTime());
if(ctx.getData("scheduledExecutionTime") == null) {
ctx.setData("scheduledExecutionTime", request.getTime());
}

cmd = classCacheManager.findCommand(request.getCommandName(), cl);
// increment execution counter directly to cover both success and failure paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,52 @@ public void logCleanupNextRunFixedIntervalTooSmallTest() throws InterruptedExcep
assertTrue(diff >= 2000 && diff < 3000);
System.clearProperty("byteman.jpaaudit.sleep");
}

@Test(timeout=10000)
@BMScript(value = "byteman-scripts/simulateSlowLogCleanupCommand.btm")
public void logCleanupNextRunFixedPaginationTest() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(1);
// this delay will be invoked 3 times during the test, resulting in an overall delay of 2s
System.setProperty("byteman.jpaaudit.sleep", "666");
// number of records to be returned by JPAAuditLogService.doDelete
System.setProperty("byteman.jpaaudit.delete", "1000");

CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
ctxCMD.setData("NextRun", "10s");
ctxCMD.setData("EmfName", "org.jbpm.executor");
ctxCMD.setData("SkipProcessLog", "true");
ctxCMD.setData("SkipTaskLog", "true");
ctxCMD.setData("RepeatMode", "fixed");
ctxCMD.setData("RecordsPerTransaction", 500);
executorService.scheduleRequest("org.jbpm.executor.commands.LogCleanupCommand", ctxCMD);

// waiting until the first LogCleanupCommand execution is done
countDownListener.waitTillCompleted();
System.clearProperty("byteman.jpaaudit.delete");
// as the number of records to be deleted > RecordsPerTransaction, a second LogCleanupCommand will be scheduled for immediate execution
countDownListener.reset(1);
countDownListener.waitTillCompleted();

List<RequestInfo> rescheduled = executorService.getRequestsByBusinessKey((String)ctxCMD.getData("businessKey"), Arrays.asList(STATUS.QUEUED), new QueryContext());
// check if the job has been rescheduled
assertEquals(1, rescheduled.size());

List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
assertEquals(1, queuedRequests.size());
List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
assertEquals(2, executedRequests.size());

executorService.cancelRequest(queuedRequests.get(0).getId());

long firstExecution = executedRequests.get(0).getTime().getTime();
long lastExecution = queuedRequests.get(queuedRequests.size()-1).getTime().getTime();

// time difference between first and last should be around 10 seconds, even if the original command got split into two executions due to RecordsPerTransaction
long diff = lastExecution - firstExecution;
assertTrue(diff < 11000);
System.clearProperty("byteman.jpaaudit.sleep");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ AT ENTRY
IF TRUE
DO debug("Pausing JPAAuditLogService.doDelete for " + Integer.getInteger("byteman.jpaaudit.sleep", 500) + "ms");
Thread.sleep(Integer.getInteger("byteman.jpaaudit.sleep", 500));
return 1
return Integer.getInteger("byteman.jpaaudit.delete", 1)
ENDRULE

########################################################################
#
# Rule to slow down the execution of JPAAuditLogService.doPartialDelete
#

RULE JPAAuditLogService.doPartialDelete sleep
CLASS org.jbpm.process.audit.JPAAuditLogService
METHOD doPartialDelete
AT ENTRY
IF TRUE
DO debug("Pausing JPAAuditLogService.doPartialDelete for " + Integer.getInteger("byteman.jpaaudit.sleep", 500) + "ms");
Thread.sleep(Integer.getInteger("byteman.jpaaudit.sleep", 500));
return Integer.getInteger("byteman.jpaaudit.delete", 1)
ENDRULE