|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
*/ |
|
|
|
|
package org.apache.dolphinscheduler.common.utils; |
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.DependResult; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.DependentRelation; |
|
|
|
|
import org.apache.dolphinscheduler.common.model.DateInterval; |
|
|
|
@ -343,6 +344,45 @@ public class DependentUtilsTest {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testGetCurretHour() { |
|
|
|
|
String dateValue = "currentHour"; |
|
|
|
|
|
|
|
|
|
Date curDay = DateUtils.stringToDate("2020-05-15 12:10:00"); |
|
|
|
|
|
|
|
|
|
List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); |
|
|
|
|
|
|
|
|
|
DateInterval expect = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 12:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 12:59:59"))); |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(expect, dateIntervals.get(0)); |
|
|
|
|
Assert.assertEquals(1, dateIntervals.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testGetLast24Hour() { |
|
|
|
|
Date curDay = DateUtils.stringToDate("2020-05-15 12:10:00"); |
|
|
|
|
String dateValue = "last24Hours"; |
|
|
|
|
|
|
|
|
|
List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue); |
|
|
|
|
|
|
|
|
|
List<DateInterval> expect = Lists.newArrayList(); |
|
|
|
|
for (int a = 1; a < 24; a++) { |
|
|
|
|
String i = a + ""; |
|
|
|
|
if (a < 10) { |
|
|
|
|
i = "0" + i; |
|
|
|
|
} |
|
|
|
|
DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":59:59"))); |
|
|
|
|
expect.add(dateInterval); |
|
|
|
|
} |
|
|
|
|
DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 00:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 00:59:59"))); |
|
|
|
|
expect.add(dateInterval); |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(24, dateIntervals.size()); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i< expect.size(); i++) { |
|
|
|
|
Assert.assertEquals(expect.get(i), dateIntervals.get(i)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testMonth(){ |
|
|
|
|