use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testRepeatWithWeekdayExclusion.
@Test
public void testRepeatWithWeekdayExclusion() throws ParseException {
Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago excluding weekdays");
Date now = new Date();
// avoid DST impacts if near Midnight
now.setHours(6);
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(2, intervals.size());
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testSparse.
@Test
public void testSparse() {
for (String text : new String[] { "30 minute window every 1 hour from 2 hours ago to 30 minutes ago", "30 minute window every 1 hour starting from 2 hours ago to 30 minutes ago", "30 minute window every 1 hour starting from 2 hours ago until 30 minutes ago", "30 minute window for every 1 hour starting from 2 hours ago until 30 minutes ago" }) {
Window w = WindowProcessor.process(text);
/*
A window size of 30 minutes
Starting 2 hour ago and continuing until 30 minutes ago
window 1: ( now - 2 hour, now - 2 hour + 30 minutes)
window 2: (now - 1 hour, now - 1 hour + 30 minutes)
*/
Date now = new Date();
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(2, intervals.size());
assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), intervals.get(1).getMinimum());
assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30), intervals.get(1).getMaximum());
}
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testBaseCase.
@Test
public void testBaseCase() {
for (String text : new String[] { "1 hour", "1 hour(s)", "1 hours" }) {
Window w = WindowProcessor.process(text);
Date now = new Date();
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(1, intervals.size());
assertEquals(now.getTime(), (long) intervals.get(0).getMaximum());
assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), (long) intervals.get(0).getMinimum());
}
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testRepeatTilNow.
@Test
public void testRepeatTilNow() {
Window w = WindowProcessor.process("30 minute window every 1 hour from 3 hours ago");
/*
A window size of 30 minutes
Starting 3 hours ago and continuing until now
window 1: ( now - 3 hour, now - 3 hour + 30 minutes)
window 2: ( now - 2 hour, now - 2 hour + 30 minutes)
window 3: ( now - 1 hour, now - 1 hour + 30 minutes)
*/
Date now = new Date();
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(3, intervals.size());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(3), intervals.get(0).getMinimum());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(3) + TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(1).getMinimum());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(30), intervals.get(1).getMaximum());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), intervals.get(2).getMinimum());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30), intervals.get(2).getMaximum());
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testRepeatWithInclusionExclusion.
@Test
public void testRepeatWithInclusionExclusion() throws ParseException {
Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago including holidays:us excluding weekends");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Date now = sdf.parse("2017/12/26 12:00");
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(1, intervals.size());
}
Aggregations