@@ -871,6 +871,31 @@ public void testQueryInvalidSortingUsage() {
871
871
}
872
872
}
873
873
874
+ @ Test
875
+ public void testQueryByExecuting () {
876
+ Calendar lockExpDate = Calendar .getInstance ();
877
+ //given - lock expiration date in future
878
+ lockExpDate .add (Calendar .MILLISECOND , 30000000 );
879
+
880
+ createJobWithLockExpiration (lockExpDate .getTime ());
881
+
882
+ Job job = managementService .createJobQuery ().jobId (timerEntity .getId ()).singleResult ();
883
+ assertNotNull (job );
884
+
885
+ List <Job > list = managementService .createJobQuery ().executing ().list ();
886
+ assertEquals (list .size (), 1 );
887
+ deleteJobInDatabase ();
888
+
889
+ //given - lock expiration date in the past
890
+ lockExpDate .add (Calendar .MILLISECOND , -60000000 );
891
+ createJobWithLockExpiration (lockExpDate .getTime ());
892
+
893
+ list = managementService .createJobQuery ().executing ().list ();
894
+ assertEquals (list .size (), 0 );
895
+
896
+ deleteJobInDatabase ();
897
+ }
898
+
874
899
//helper ////////////////////////////////////////////////////////////
875
900
876
901
private void setRetries (final String processInstanceId , final int retries ) {
@@ -886,6 +911,27 @@ public Void execute(CommandContext commandContext) {
886
911
});
887
912
}
888
913
914
+ private void createJobWithLockExpiration (Date lockDate ) {
915
+ CommandExecutor commandExecutor = processEngineConfiguration .getCommandExecutorTxRequired ();
916
+ commandExecutor .execute (new Command <Void >() {
917
+ public Void execute (CommandContext commandContext ) {
918
+ JobManager jobManager = commandContext .getJobManager ();
919
+ timerEntity = new TimerEntity ();
920
+ timerEntity .setLockOwner (UUID .randomUUID ().toString ());
921
+ timerEntity .setDuedate (new Date ());
922
+ timerEntity .setRetries (0 );
923
+ timerEntity .setLockExpirationTime (lockDate );
924
+
925
+ jobManager .insert (timerEntity );
926
+
927
+ assertNotNull (timerEntity .getId ());
928
+
929
+ return null ;
930
+
931
+ }
932
+ });
933
+ }
934
+
889
935
private ProcessInstance startProcessInstanceWithFailingJob () {
890
936
// start a process with a failing job
891
937
ProcessInstance processInstance = runtimeService .startProcessInstanceByKey ("exceptionInJobExecution" );
0 commit comments