LcL3ProductionType extends HadoopProductionType { static List<DateRange> getDateRanges(ProductionRequest productionRequest, int periodLengthDefault) throws ProductionException { List<DateRange> dateRangeList = new ArrayList<DateRange>(); Date minDate = productionRequest.getDate("minDate"); Date maxDate = productionRequest.getDate("maxDate"); int periodLength = productionRequest.getInteger("periodLength", periodLengthDefault); Calendar calendarMax = DateUtils.createCalendar(); calendarMax.setTime(maxDate); long time = minDate.getTime(); while (true) { Calendar calendar1 = DateUtils.createCalendar(); Calendar calendar2 = DateUtils.createCalendar(); calendar1.setTimeInMillis(time); calendar2.setTimeInMillis(time); calendar2.add(Calendar.DAY_OF_MONTH, periodLength - 1); if (calendar2.after(calendarMax)) { break; } Calendar calendar3 = DateUtils.createCalendar(); calendar3.setTimeInMillis(time); calendar3.add(Calendar.DAY_OF_MONTH, periodLength + periodLength - 1); if (calendar3.get(Calendar.MONTH) != calendar2.get(Calendar.MONTH)) { calendar2.set(Calendar.DAY_OF_MONTH, calendar2.getActualMaximum(Calendar.DAY_OF_MONTH)); } dateRangeList.add(new DateRange(calendar1.getTime(), calendar2.getTime())); calendar2.add(Calendar.DAY_OF_MONTH, 1); time = calendar2.getTimeInMillis(); } return dateRangeList; } LcL3ProductionType(FileSystemService fileSystemService, HadoopProcessingService processingService,
                       StagingService stagingService); @Override Production createProduction(ProductionRequest productionRequest);  }
@Test public void testGetDatePairList_period7() throws ProductionException, ParseException { ProductionRequest productionRequest = new ProductionRequest("LCL3", "ewa", "minDate", "2010-06-01", "maxDate", "2010-06-30", "periodLength", "7"); List<DateRange> dateRangeList = LcL3ProductionType.getDateRanges(productionRequest, 7); assertEquals(4, dateRangeList.size()); assertEquals("2010-06-01", asString(dateRangeList.get(0).getStartDate())); assertEquals("2010-06-07", asString(dateRangeList.get(0).getStopDate())); assertEquals("2010-06-08", asString(dateRangeList.get(1).getStartDate())); assertEquals("2010-06-14", asString(dateRangeList.get(1).getStopDate())); assertEquals("2010-06-15", asString(dateRangeList.get(2).getStartDate())); assertEquals("2010-06-21", asString(dateRangeList.get(2).getStopDate())); assertEquals("2010-06-22", asString(dateRangeList.get(3).getStartDate())); assertEquals("2010-06-30", asString(dateRangeList.get(3).getStopDate())); }
@Test public void testGetDatePairList_period10() throws ProductionException, ParseException { ProductionRequest productionRequest = new ProductionRequest("LCL3", "ewa", "minDate", "2010-06-01", "maxDate", "2010-08-31", "periodLength", "10"); List<DateRange> dateRangeList = LcL3ProductionType.getDateRanges(productionRequest, 10); assertEquals(9, dateRangeList.size()); assertEquals("2010-06-01", asString(dateRangeList.get(0).getStartDate())); assertEquals("2010-06-10", asString(dateRangeList.get(0).getStopDate())); assertEquals("2010-06-11", asString(dateRangeList.get(1).getStartDate())); assertEquals("2010-06-20", asString(dateRangeList.get(1).getStopDate())); assertEquals("2010-06-21", asString(dateRangeList.get(2).getStartDate())); assertEquals("2010-06-30", asString(dateRangeList.get(2).getStopDate())); assertEquals("2010-07-01", asString(dateRangeList.get(3).getStartDate())); assertEquals("2010-07-10", asString(dateRangeList.get(3).getStopDate())); assertEquals("2010-07-11", asString(dateRangeList.get(4).getStartDate())); assertEquals("2010-07-20", asString(dateRangeList.get(4).getStopDate())); assertEquals("2010-07-21", asString(dateRangeList.get(5).getStartDate())); assertEquals("2010-07-31", asString(dateRangeList.get(5).getStopDate())); assertEquals("2010-08-01", asString(dateRangeList.get(6).getStartDate())); assertEquals("2010-08-10", asString(dateRangeList.get(6).getStopDate())); assertEquals("2010-08-11", asString(dateRangeList.get(7).getStartDate())); assertEquals("2010-08-20", asString(dateRangeList.get(7).getStopDate())); assertEquals("2010-08-21", asString(dateRangeList.get(8).getStartDate())); assertEquals("2010-08-31", asString(dateRangeList.get(8).getStopDate())); }
@Test public void testGetDatePairList_period15() throws ProductionException, ParseException { ProductionRequest productionRequest = new ProductionRequest("LCL3", "ewa", "minDate", "2010-07-01", "maxDate", "2010-07-31", "periodLength", "15"); List<DateRange> dateRangeList = LcL3ProductionType.getDateRanges(productionRequest, 10); assertEquals(2, dateRangeList.size()); assertEquals("2010-07-01", asString(dateRangeList.get(0).getStartDate())); assertEquals("2010-07-15", asString(dateRangeList.get(0).getStopDate())); assertEquals("2010-07-16", asString(dateRangeList.get(1).getStartDate())); assertEquals("2010-07-31", asString(dateRangeList.get(1).getStopDate())); }