@Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry(); HolidayCalendar cal = new HolidayCalendar(); java.util.Calendar tomorrow = java.util.Calendar.getInstance(); tomorrow.setTime(new Date()); tomorrow.add(java.util.Calendar.DAY_OF_MONTH, 1); cal.addExcludedDate(tomorrow.getTime()); jndi.bind("calendar", cal); return jndi; }
@Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry(); HolidayCalendar cal = new HolidayCalendar(); cal.addExcludedDate(new Date()); jndi.bind("calendar", cal); return jndi; }
@Test public void holidayCalendar() throws Exception { // HolidayCalendar sets the time of any given Date to 00:00:00 java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(java.util.Calendar.HOUR_OF_DAY, 0); cal.set(java.util.Calendar.MINUTE, 0); cal.set(java.util.Calendar.SECOND, 0); cal.set(java.util.Calendar.MILLISECOND, 0); final Date excludedDate = cal.getTime(); HolidayCalendar calendar = new HolidayCalendar(); calendar.addExcludedDate(excludedDate); final String name = "holidayCalendar"; jobStore.storeCalendar(name, calendar, true, true); final String calendarHashKey = schema.calendarHashKey(name); Map<String, String> calendarMap = jedis.hgetAll(calendarHashKey); assertThat(calendarMap, hasKey("calendar_class")); assertThat(calendarMap.get("calendar_class"), equalTo(HolidayCalendar.class.getName())); assertThat(calendarMap, hasKey("calendar_json")); String json = calendarMap.get("calendar_json"); assertThat(json, containsString("\"dates\":[")); assertThat(json, not(containsString("\"excludedDates\":"))); Calendar retrieved = jobStore.retrieveCalendar(name); assertThat(retrieved, notNullValue()); assertThat(retrieved, instanceOf(HolidayCalendar.class)); HolidayCalendar retrievedHoliday = (HolidayCalendar) retrieved; assertThat(retrievedHoliday.getExcludedDates(), hasItem(excludedDate)); }
@Test public void shouldStoreAndRetrieveCalendar() throws Exception { DateTime now = new DateTime(); HolidayCalendar testCalendar = new HolidayCalendar(); testCalendar.addExcludedDate(now.plusDays(1).toDate()); String calendarName = id("testCalendar"); couchdbStore.storeCalendar(calendarName, testCalendar, false, false); Calendar dbCalendar = couchdbStore.retrieveCalendar(calendarName); assertEquals(testCalendar.getClass(), dbCalendar.getClass()); assertEquals(testCalendar.getExcludedDates(), ((HolidayCalendar) dbCalendar).getExcludedDates()); }
@Test public void shouldReplaceExistingCalendar() throws Exception { HolidayCalendar testCalendar = new HolidayCalendar(); testCalendar.addExcludedDate(new Date()); String calendarName = id("testCalendar"); couchdbStore.storeCalendar(calendarName, testCalendar, false, false); couchdbStore.storeCalendar(calendarName, new HolidayCalendar(), true, false); HolidayCalendar dbCalendar = (HolidayCalendar) couchdbStore.retrieveCalendar(calendarName); assertEquals(0, dbCalendar.getExcludedDates().size()); }
@Test public void shouldNotUpdateExistingTriggers() throws Exception { String triggerName = id("triggerName"); String triggerGroup = id("triggerGroup"); String calendarName = id("testCalendar"); couchdbStore.storeCalendar(calendarName, new HolidayCalendar(), false, false); final DateTime startTime = new DateTime().plusDays(1); OperableTrigger trigger = (SimpleTriggerImpl) newTrigger() .withIdentity(triggerName, triggerGroup) .forJob(JobKey.jobKey(id("jobName"), id("jobGroup"))) .startAt(startTime.toDate()) .withSchedule(simpleSchedule() .withIntervalInHours(24) .repeatForever()) .modifiedByCalendar(calendarName) .build(); trigger.computeFirstFireTime(couchdbStore.retrieveCalendar(calendarName)); couchdbStore.storeTrigger(trigger, false); OperableTrigger triggerWithEmptyCalendar = couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName, triggerGroup)); assertEquals(startTime.toDate(), triggerWithEmptyCalendar.getNextFireTime()); HolidayCalendar testCalendar = new HolidayCalendar(); testCalendar.addExcludedDate(startTime.toDate()); couchdbStore.storeCalendar(calendarName, testCalendar, true, false); assertEquals(startTime.toDate(), triggerWithEmptyCalendar.getNextFireTime()); couchdbStore.storeCalendar(calendarName, testCalendar, true, true); OperableTrigger triggerWithTestCalendar = couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName, triggerGroup)); assertEquals(startTime.plusDays(1).toDate(), triggerWithTestCalendar.getNextFireTime()); }
@Test public void shouldRemoveCalendar() throws JobPersistenceException { HolidayCalendar testCalendar = new HolidayCalendar(); String calendarName = id("testCalendar"); couchdbStore.storeCalendar(calendarName, testCalendar, false, false); assertTrue(couchdbStore.removeCalendar(calendarName)); assertNull(couchdbStore.retrieveCalendar(calendarName)); }
@Test(expected = ObjectAlreadyExistsException.class) public void shouldNotReplaceExistingCalendar() throws Exception { couchdbStore.storeCalendar("testCalendar", new HolidayCalendar(), false, false); couchdbStore.storeCalendar("testCalendar", new HolidayCalendar(), false, false); }