### Question:
AlarmService extends AbstractService implements LensService { public void schedule(DateTime start, DateTime end, XFrequency frequency, String jobHandle) throws LensException { JobDataMap map = new JobDataMap(); map.put(JOB_HANDLE, jobHandle); map.put(SHOULD_WAIT, shouldWaitForScheduleEventProcessing); JobDetail job = JobBuilder.newJob(LensJob.class).withIdentity(jobHandle, LENS_JOBS).usingJobData(map).build(); Trigger trigger; if (frequency.getEnum() != null) { CalendarIntervalScheduleBuilder scheduleBuilder = CalendarIntervalScheduleBuilder.calendarIntervalSchedule() .withInterval(getTimeInterval(frequency.getEnum()), getTimeUnit(frequency.getEnum())) .withMisfireHandlingInstructionIgnoreMisfires(); trigger = TriggerBuilder.newTrigger().withIdentity(jobHandle, ALARM_SERVICE).startAt(start.toDate()) .endAt(end.toDate()).withSchedule(scheduleBuilder).build(); } else { trigger = TriggerBuilder.newTrigger().withIdentity(jobHandle, ALARM_SERVICE).startAt(start.toDate()) .endAt(end.toDate()).withSchedule(CronScheduleBuilder.cronSchedule(frequency.getCronExpression()) .withMisfireHandlingInstructionIgnoreMisfires()).build(); } try { scheduler.scheduleJob(job, trigger); } catch (SchedulerException e) { log.error("Error scheduling job with jobHandle: {}", jobHandle); throw new LensException(LensSchedulerErrorCode.FAILED_ALARM_SERVICE_OPERATION.getLensErrorInfo(), e, "schedule", jobHandle); } } AlarmService(); @Override HealthStatus getHealthStatus(); synchronized void init(HiveConf hiveConf); @Override synchronized void start(); @Override synchronized void stop(); List<JobExecutionContext> getCurrentlyExecutingJobs(); void schedule(DateTime start, DateTime end, XFrequency frequency, String jobHandle); boolean unSchedule(SchedulerJobHandle jobHandle); boolean checkExists(SchedulerJobHandle handle); void pauseJob(SchedulerJobHandle jobHandle); void resumeJob(SchedulerJobHandle jobHandle); static final String NAME; static final String LENS_JOBS; static final String ALARM_SERVICE; }### Answer:
@Test public void testAlarmServiceEnums() throws InterruptedException, LensException { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-mm-dd"); DateTime start = formatter.parseDateTime("2016-03-03"); DateTime end = formatter.parseDateTime("2016-03-06"); SchedulerJobHandle jobHandle = new SchedulerJobHandle(UUID.randomUUID()); XFrequency frequency = new XFrequency(); frequency.setEnum(XFrequencyEnum.DAILY); alarmService.schedule(start, end, frequency, jobHandle.toString()); Thread.sleep(2000); int count = 0; for (SchedulerAlarmEvent event : events) { if (event.getJobHandle().equals(jobHandle)) { count++; } } Assert.assertEquals(count, 4); DateTime expectedDate = start; Set<DateTime> actualSet = new HashSet<>(); for (SchedulerAlarmEvent e : events) { actualSet.add(e.getNominalTime()); } for (int i = 0; i < actualSet.size(); i++) { Assert.assertTrue(actualSet.contains(expectedDate)); expectedDate = expectedDate.plusDays(1); } }