public void testAbsoluteRange() throws Exception { init("coord-action-create"); ds = new SyncCoordDataset(); ds.setFrequency(7); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-08-20T01:00Z")); ds.setTimeUnit(TimeUnit.DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setName("test"); ds.setUriTemplate("hdfs:///tmp/workflows/${YEAR}/${MONTH}/${DAY};region=us"); ds.setType("SYNC"); ds.setDoneFlag(""); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-08-20T01:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); String expr = "${coord:absoluteRange(\"2009-08-20T01:00Z\",\"0\")}"; assertEquals(CoordELFunctions.evalAndWrap(eval, expr), "2009-08-20T01:00Z"); expr = "${coord:absoluteRange(\"2009-08-20T01:00Z\",\"1\")}"; assertEquals(CoordELFunctions.evalAndWrap(eval, expr), "2009-08-27T01:00Z#2009-08-20T01:00Z"); try { expr = "${coord:absoluteRange(\"2009-08-20T01:00Z\",\"-1\")}"; CoordELFunctions.evalAndWrap(eval, expr); fail("start-instance is greater than the end-instance and there was no exception"); } catch (Exception e) { assertTrue( e.getCause() .getMessage() .contains("start-instance should be equal or earlier than the end-instance")); } }
public void testTZOffset() throws Exception { init("coord-action-create"); String expr = "${coord:tzOffset()}"; // eval.setVariable("resolve_tzOffset", "true"); assertEquals("0", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2012-06-13T00:00Z")); // Summer CoordELFunctions.configureEvaluator(eval, ds, appInst); // PDT is UTC - 7 assertEquals("-420", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2012-12-13T00:00Z")); // Winter CoordELFunctions.configureEvaluator(eval, ds, appInst); // PST is UTC - 8 assertEquals("-480", CoordELFunctions.evalAndWrap(eval, expr)); }
private void init(String tag, String uriTemplate) throws Exception { eval = Services.get().get(ELService.class).createEvaluator(tag); eval.setVariable(OozieClient.USER_NAME, "test_user"); eval.setVariable(OozieClient.GROUP_NAME, "test_group"); appInst = new SyncCoordAction(); ds = new SyncCoordDataset(); ds.setFrequency(1); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-09-01T23:59Z")); ds.setTimeUnit(TimeUnit.DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setName("test"); ds.setUriTemplate(uriTemplate); ds.setType("SYNC"); ds.setDoneFlag(""); appInst.setActualTime(DateUtils.parseDateOozieTZ("2009-09-10T23:59Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-09-09T23:59Z")); appInst.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); appInst.setActionId("00000-oozie-C@1"); appInst.setName("mycoordinator-app"); CoordELFunctions.configureEvaluator(eval, ds, appInst); }
public void testCurrent() throws Exception { init("coord-action-create"); String expr = "${coord:current(-1)}"; assertEquals("2009-09-08T23:59Z", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-05-30T00:45Z")); ds.setFrequency(1); ds.setTimeUnit(TimeUnit.DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); expr = "${coord:current(0)} ${coord:current(1)} ${coord:current(-1)} ${coord:current(-3)}"; assertEquals( "2009-05-29T23:00Z 2009-05-30T23:00Z 2009-05-28T23:00Z 2009-05-26T23:00Z", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-05-30T00:45Z")); ds.setFrequency(30); ds.setTimeUnit(TimeUnit.MINUTE); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-08T00:00Z")); expr = "${coord:current(0)} ${coord:current(1)} ${coord:current(-1)} ${coord:current(-3)}"; assertEquals( "2009-05-30T00:30Z 2009-05-30T01:00Z 2009-05-30T00:00Z 2009-05-29T23:00Z", eval.evaluate(expr, String.class)); SyncCoordAction appInst = new SyncCoordAction(); SyncCoordDataset ds = new SyncCoordDataset(); ; ds.setFrequency(1); ds.setTimeUnit(TimeUnit.DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setName("test1"); ds.setType("SYNC"); appInst.setActualTime(DateUtils.parseDateOozieTZ("2009-09-10T23:59Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-05-30T00:00Z ")); appInst.setTimeZone(DateUtils.getTimeZone("UTC")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-05-30T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-05-31T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(-1)}"; assertEquals("2009-05-29T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(-3)}"; assertEquals("2009-05-27T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); ds.setFrequency(7); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-08T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-05-28T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-06-04T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(-1)}"; assertEquals("2009-05-21T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(-3)}"; assertEquals("2009-05-07T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Spring DST transition appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-08T10:45Z")); ds.setFrequency(1); ds.setTimeUnit(TimeUnit.DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-03-06T10:00Z")); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); expr = "${coord:current(-2)} ${coord:current(-1)} ${coord:current(0)} ${coord:current(1)} ${coord:current(2)}"; assertEquals( "2009-03-06T10:00Z 2009-03-07T10:00Z 2009-03-08T09:00Z 2009-03-09T09:00Z 2009-03-10T09:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Winter DST Transition appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-11-01T08:00Z")); ds.setFrequency(1); ds.setTimeUnit(TimeUnit.DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-10-30T08:00Z")); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); expr = "${coord:current(-2)} ${coord:current(-1)} ${coord:current(0)} ${coord:current(1)} ${coord:current(2)}"; // System.out.println("AAAAA " + CoordELFunctions.evalAndWrap(eval, // expr)); assertEquals( "2009-10-30T08:00Z 2009-10-31T08:00Z 2009-11-01T08:00Z 2009-11-02T09:00Z 2009-11-03T09:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // EndofDay testing ds.setFrequency(1); ds.setTimeUnit(TimeUnit.DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T09:00Z")); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setName("test1"); ds.setType("SYNC"); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-05-30T12:00Z ")); ds.setEndOfDuration(TimeUnit.END_OF_DAY); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-05-30T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-05-31T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // From Specification // Case 1 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("", CoordELFunctions.evalAndWrap(eval, expr)); // Case 2 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; // assertEquals("2009-01-02T08:00Z", CoordELFunctions.evalAndWrap(eval, // expr)); assertEquals("", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; // assertEquals("2009-01-03T08:00Z", CoordELFunctions.evalAndWrap(eval, // expr)); assertEquals("", CoordELFunctions.evalAndWrap(eval, expr)); // Case 3 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T07:01Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-01-01T08:01Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-01-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-01-02T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 4 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T7:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-01-01T18:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-01-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-01-02T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 5 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-03-07T07:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-07T09:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-07T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-08T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 6 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-03-08T07:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-08T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-08T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-09T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 7 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-03-09T07:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-10T08:01Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-10T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-11T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 8 ds.setEndOfDuration(TimeUnit.END_OF_DAY); ds.setFrequency(2); // Changed ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-03-09T07:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-10T07:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-10T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-12T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Test with EOM ds.setTimeUnit(TimeUnit.MONTH); // Case 1 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setFrequency(1); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T00:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-02-01T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-01T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 2 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-02-01T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-01T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 3 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-31T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-02-01T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-01T00:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 4 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-02-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-03-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 5 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-02-02T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-02T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-04-01T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 6 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-02-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-04-01T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); // Case 7 ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setFrequency(3); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-02-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-01T08:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:current(0)}"; assertEquals("2009-03-01T08:00Z", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:current(1)}"; assertEquals("2009-06-01T07:00Z", CoordELFunctions.evalAndWrap(eval, expr)); }
public void testDaysInMonth() throws Exception { init("coord-action-create"); String expr = "${coord:daysInMonth(1)}"; assertEquals("30", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(coord:daysInMonth(1))}"; assertEquals("31", CoordELFunctions.evalAndWrap(eval, expr)); SyncCoordAction appInst = new SyncCoordAction(); SyncCoordDataset ds = new SyncCoordDataset(); ; ds.setFrequency(1); ds.setTimeUnit(TimeUnit.MONTH); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setName("test1"); ds.setType("SYNC"); appInst.setActualTime(DateUtils.parseDateOozieTZ("2009-09-10T23:59Z")); appInst.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T00:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T11:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:daysInMonth(0)}"; assertEquals("28", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(-1)}"; assertEquals("31", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(2)}"; assertEquals("30", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(-3)}"; assertEquals("30", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(3)}"; assertEquals("31", CoordELFunctions.evalAndWrap(eval, expr)); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T11:00Z")); // Feb appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:daysInMonth(0)}"; assertEquals("28", CoordELFunctions.evalAndWrap(eval, expr)); // Jan // 31 // End of Month ds.setFrequency(1); ds.setTimeUnit(TimeUnit.MONTH); ds.setEndOfDuration(TimeUnit.END_OF_MONTH); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setName("test1"); ds.setType("SYNC"); appInst.setActualTime(DateUtils.parseDateOozieTZ("2009-09-10T23:59Z")); appInst.setTimeZone(DateUtils.getTimeZone("UTC")); // Case 1 ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T00:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T11:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:daysInMonth(0)}"; assertEquals("28", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(-1)}"; assertEquals("31", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(2)}"; assertEquals("30", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(-3)}"; assertEquals("30", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:daysInMonth(3)}"; assertEquals("31", CoordELFunctions.evalAndWrap(eval, expr)); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-02-01T11:00Z")); // Feb appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:daysInMonth(0)}"; assertEquals("28", CoordELFunctions.evalAndWrap(eval, expr)); // Jan // 31 }
public void testHoursInDay() throws Exception { init("coord-action-create"); String expr = "${coord:hoursInDay(1)}"; String res = CoordELFunctions.evalAndWrap(eval, expr); assertEquals("24", res); expr = "${coord:hoursInDay(coord:hoursInDay(1))}"; res = CoordELFunctions.evalAndWrap(eval, expr); SyncCoordAction appInst = new SyncCoordAction(); SyncCoordDataset ds = new SyncCoordDataset(); ; ds.setFrequency(1); ds.setTimeUnit(TimeUnit.DAY); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-02T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setName("test1"); ds.setType("SYNC"); appInst.setActualTime(DateUtils.parseDateOozieTZ("2009-09-10T23:59Z")); appInst.setTimeZone(DateUtils.getTimeZone("UTC")); ds.setInitInstance(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-01-01T08:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:hoursInDay(-2)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-08T08:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("UTC")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); ds.setTimeZone(DateUtils.getTimeZone("Europe/London")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-08T08:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("23", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:hoursInDay(1)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-11-01T08:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("25", CoordELFunctions.evalAndWrap(eval, expr)); appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-03-08T08:00Z")); appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z")); ds.setTimeZone(DateUtils.getTimeZone("America/Los_Angeles")); ds.setEndOfDuration(TimeUnit.END_OF_DAY); CoordELFunctions.configureEvaluator(eval, ds, appInst); expr = "${coord:hoursInDay(0)}"; assertEquals("23", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:hoursInDay(1)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); expr = "${coord:hoursInDay(-1)}"; assertEquals("24", CoordELFunctions.evalAndWrap(eval, expr)); }