Skip to content

Commit

Permalink
[HWORKS-792] Hopsworks job schedule update doesn't update cron expres…
Browse files Browse the repository at this point in the history
…… (#1587)
  • Loading branch information
SirOibaf committed Oct 16, 2023
1 parent 44d61e5 commit 4398ba1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public JobScheduleV2 updateSchedule(JobScheduleV2DTO jobScheduleV2DTO) throws Jo
JobScheduleV2 jobSchedule = jobScheduleFacade.getById(jobScheduleV2DTO.getId())
.orElseThrow(() -> new JobException(RESTCodes.JobErrorCode.JOB_SCHEDULE_NOT_FOUND, Level.FINE));
jobSchedule.setEnabled(jobScheduleV2DTO.getEnabled());
jobSchedule.setCronExpression(jobScheduleV2DTO.getCronExpression());
jobSchedule.setStartDateTime(jobScheduleV2DTO.getStartDateTime());
jobSchedule.setEndDateTime(jobScheduleV2DTO.getEndDateTime());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public void testEnableSchedulerWithPreviousExecutions() throws JobException {

JobScheduleV2DTO updatedJobScheduleDTO = new JobScheduleV2DTO();
updatedJobScheduleDTO.setEnabled(true);
updatedJobScheduleDTO.setCronExpression("0 */10 * ? * * *");
target.updateSchedule(updatedJobScheduleDTO);
verify(jobScheduleV2Facade, times(1)).update(argumentCaptor.capture());

Expand Down Expand Up @@ -266,6 +267,7 @@ public void testEnableSchedulerWithPreviousExecutionPriorToNewStartDateTime() th
JobScheduleV2DTO updatedJobScheduleDTO = new JobScheduleV2DTO();
updatedJobScheduleDTO.setEnabled(true);
updatedJobScheduleDTO.setStartDateTime(newStartDateTime.toInstant());
updatedJobScheduleDTO.setCronExpression("0 */10 * ? * * *");
target.updateSchedule(updatedJobScheduleDTO);

verify(jobScheduleV2Facade, times(1)).update(argumentCaptor.capture());
Expand Down Expand Up @@ -297,6 +299,7 @@ public void testEnableSchedulerWithNoPreviousExecutions() throws JobException {
JobScheduleV2DTO updatedJobScheduleDTO = new JobScheduleV2DTO();
updatedJobScheduleDTO.setEnabled(true);
updatedJobScheduleDTO.setStartDateTime(startDateTime.toInstant());
updatedJobScheduleDTO.setCronExpression("0 */10 * ? * * *");
target.updateSchedule(updatedJobScheduleDTO);

verify(jobScheduleV2Facade, times(1)).update(argumentCaptor.capture());
Expand Down Expand Up @@ -324,6 +327,7 @@ public void testDisableScheduler() throws JobException {

JobScheduleV2DTO updatedJobScheduleDTO = new JobScheduleV2DTO();
updatedJobScheduleDTO.setEnabled(false);
updatedJobScheduleDTO.setCronExpression("0 0 0 ? * 1 *");
target.updateSchedule(updatedJobScheduleDTO);

verify(jobScheduleV2Facade, times(1)).update(argumentCaptor.capture());
Expand All @@ -332,4 +336,29 @@ public void testDisableScheduler() throws JobException {
Assert.assertEquals(false, capturedSchedule.getEnabled());
Assert.assertEquals(nextExecutionTime, capturedSchedule.getNextExecutionDateTime());
}

@Test
public void testUpdateCronExpression() throws JobException {
Instant nextExecutionTime = Instant.now();

JobScheduleV2 scheduler = new JobScheduleV2();
scheduler.setEnabled(true);
scheduler.setCronExpression("0 0 0 ? * 1 *");
scheduler.setNextExecutionDateTime(nextExecutionTime);

Mockito.when(jobScheduleV2Facade.getById(any())).thenReturn(Optional.of(scheduler));
Mockito.when(jobScheduleV2Facade.update(any(JobScheduleV2.class))).thenReturn(scheduler);
ArgumentCaptor<JobScheduleV2> argumentCaptor = ArgumentCaptor.forClass(JobScheduleV2.class);

String updatedCronExpression = "0 */5 */5 ? * 1 *";
JobScheduleV2DTO updatedJobScheduleDTO = new JobScheduleV2DTO();
updatedJobScheduleDTO.setCronExpression(updatedCronExpression);
updatedJobScheduleDTO.setEnabled(true);
target.updateSchedule(updatedJobScheduleDTO);

verify(jobScheduleV2Facade, times(1)).update(argumentCaptor.capture());

JobScheduleV2 capturedSchedule = argumentCaptor.getValue();
Assert.assertEquals(updatedCronExpression, capturedSchedule.getCronExpression());
}
}

0 comments on commit 4398ba1

Please sign in to comment.