@Test public void testScheduler() throws MalformedURLException { Map<String, Object> stormConf = new HashMap<>(); stormConf.put("fetchInterval.FETCHED.testKey=someValue", 360); stormConf.put("fetchInterval.testKey=someValue", 3600); DefaultScheduler scheduler = new DefaultScheduler(); scheduler.init(stormConf); Metadata metadata = new Metadata(); metadata.addValue("testKey", "someValue"); Date nextFetch = scheduler.schedule(Status.FETCHED, metadata); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 360); Assert.assertEquals(DateUtils.round(cal.getTime(), Calendar.SECOND), DateUtils.round(nextFetch, Calendar.SECOND)); nextFetch = scheduler.schedule(Status.ERROR, metadata); cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 3600); Assert.assertEquals(DateUtils.round(cal.getTime(), Calendar.SECOND), DateUtils.round(nextFetch, Calendar.SECOND)); }
@Test public void testCustomWithDot() throws MalformedURLException { Map<String, Object> stormConf = new HashMap<>(); stormConf.put("fetchInterval.FETCHED.testKey.key2=someValue", 360); DefaultScheduler scheduler = new DefaultScheduler(); scheduler.init(stormConf); Metadata metadata = new Metadata(); metadata.addValue("testKey.key2", "someValue"); Date nextFetch = scheduler.schedule(Status.FETCHED, metadata); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 360); Assert.assertEquals(DateUtils.round(cal.getTime(), Calendar.SECOND), DateUtils.round(nextFetch, Calendar.SECOND)); }
@Test public void testMonthsBetween() throws Exception { int i = 0; assertEquals(getMonthlyCoveringInfo(pairs[i], DateUtils.round(pairs[i + 1], MONTH)), new CoveringInfo(1, true), "2013-Jan-01 to 2013-Jan-31"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], DateUtils.round(pairs[i + 1], MONTH)), new CoveringInfo(5, true), "2013-Jan-01 to 2013-May-31"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], DateUtils.round(pairs[i + 1], MONTH)), new CoveringInfo(12, true), "2013-Jan-01 to 2013-Dec-31"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(2, false), "2013-Feb-01 to 2013-Apr-25"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(12, true), "2012-Feb-01 to 2013-Feb-01"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(24, true), "2011-Feb-01 to 2013-Feb-01"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "2013-Jan-02 to 2013-Feb-02"); i += 2; assertEquals(getMonthlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(1, false), "2013-Jan-02 to 2013-Mar-02"); }
@Test public void testYearsBetween() throws Exception { int i = 0; assertEquals(getYearlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "" + pairs[i] + "->" + pairs[i + 1]); i += 2; assertEquals(getYearlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "" + pairs[i] + "->" + pairs[i + 1]); i += 2; assertEquals(getYearlyCoveringInfo(pairs[i], DateUtils.round(pairs[i + 1], MONTH)), new CoveringInfo(1, true), "" + pairs[i] + "->" + pairs[i + 1]); i += 2; assertEquals(getYearlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "" + pairs[i] + "->" + pairs[i + 1]); i += 2; assertEquals(getYearlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "" + pairs[i] + "->" + pairs[i + 1]); i += 2; assertEquals(getYearlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(1, false), "" + pairs[i] + "->" + pairs[i + 1]); }
@Test public void testQuartersBetween() throws Exception { int i = 0; assertEquals(getQuarterlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "2013-Jan-01 to 2013-Jan-31"); i += 2; assertEquals(getQuarterlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(1, false), "2013-Jan-01 to 2013-May-31"); i += 2; assertEquals(getQuarterlyCoveringInfo(pairs[i], DateUtils.round(pairs[i + 1], MONTH)), new CoveringInfo(4, true), "2013-Jan-01 to 2013-Dec-31"); i += 2; assertEquals(getQuarterlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(0, false), "2013-Feb-01 to 2013-Apr-25"); i += 2; assertEquals(getQuarterlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(3, false), "2012-Feb-01 to 2013-Feb-01"); i += 2; assertEquals(getQuarterlyCoveringInfo(pairs[i], pairs[i + 1]), new CoveringInfo(7, false), "2011-Feb-01 to 2013-Feb-01"); }
nextFetch = DateUtils.round(nextFetch, this.roundDateUnit);