From 4398ba157bc3da83c008b11ec573a31ff819cc01 Mon Sep 17 00:00:00 2001 From: Fabio Buso Date: Mon, 16 Oct 2023 11:43:24 +0200 Subject: [PATCH] =?UTF-8?q?[HWORKS-792]=20Hopsworks=20job=20schedule=20upd?= =?UTF-8?q?ate=20doesn't=20update=20cron=20expres=E2=80=A6=20(#1587)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/JobScheduleV2Controller.java | 1 + .../jobs/TestJobSchedulerV2Controller.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/jobs/scheduler/JobScheduleV2Controller.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/jobs/scheduler/JobScheduleV2Controller.java index 15155dfb73..ef7de48ec7 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/jobs/scheduler/JobScheduleV2Controller.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/jobs/scheduler/JobScheduleV2Controller.java @@ -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()); diff --git a/hopsworks-common/src/test/io/hops/hopsworks/common/jobs/TestJobSchedulerV2Controller.java b/hopsworks-common/src/test/io/hops/hopsworks/common/jobs/TestJobSchedulerV2Controller.java index 90cefa2d1e..d67e2fa14a 100644 --- a/hopsworks-common/src/test/io/hops/hopsworks/common/jobs/TestJobSchedulerV2Controller.java +++ b/hopsworks-common/src/test/io/hops/hopsworks/common/jobs/TestJobSchedulerV2Controller.java @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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 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()); + } } \ No newline at end of file