ProjectManagerServlet extends LoginAbstractAzkabanServlet { static void removeScheduleOfDeletedFlows(final Project project, final ScheduleManager scheduleManager, final Consumer<Schedule> onDeletedSchedule) throws ScheduleManagerException { final Set<String> flowNameList = project.getFlows().stream().map(f -> f.getId()).collect( Collectors.toSet()); for (final Schedule schedule : scheduleManager.getSchedules()) { if (schedule.getProjectId() == project.getId() && !flowNameList.contains(schedule.getFlowName())) { scheduleManager.removeSchedule(schedule); onDeletedSchedule.accept(schedule); } } } ProjectManagerServlet(); @Override void init(final ServletConfig config); static final String API_UPLOAD; }
@Test public void testRemoveScheduleOfDeletedFlows() throws Exception { final Project project = new Project(1, "myTestProject"); final DirectoryYamlFlowLoader loader = new DirectoryYamlFlowLoader(new Props()); loader.loadProjectFlow(project, ExecutionsTestUtil.getFlowDir("multipleflowyamltest")); project.setFlows(loader.getFlowMap()); Assert.assertEquals(2, project.getFlows().size()); final Set<String> flowNameList = project.getFlows().stream().map(f -> f.getId()).collect(Collectors.toSet()); Assert.assertTrue(flowNameList.containsAll(Arrays.asList("basic_flow", "basic_flow2"))); final List<Schedule> schedules = new ArrayList<>(); final long now = System.currentTimeMillis(); final Schedule sched1 = new Schedule(1, 1, "myTestProject", "basic_flow_renamed", "ready", now, now, null, null, now, now, now, "testUser1", null, null); schedules.add(sched1); final Schedule sched2 = new Schedule(2, 1, "myTestProject", "basic_flow2", "ready", now + 20, now + 20, null, null, now + 20, now + 20, now + 20, "testUser1", null, null); schedules.add(sched2); final Schedule sched3 = new Schedule(3, 3, "anotherTestProject", "anotherFlow", "ready", now + 30, now + 30, null, null, now + 30, now + 30, now + 30, "testUser3", null, null); schedules.add(sched3); when(this.scheduleManager.getSchedules()).thenReturn(new ArrayList<>(schedules)); doAnswer(invocation -> schedules.remove(invocation.getArguments()[0])) .when(this.scheduleManager).removeSchedule(any(Schedule.class)); this.projectManagerServlet .removeScheduleOfDeletedFlows(project, this.scheduleManager, schedule -> { }); Assert.assertEquals(2, schedules.size()); Assert.assertTrue(schedules.containsAll(Arrays.asList(sched2, sched3))); }