@DataProvider(name = "update-periods") public static Object[][] provideUpdatePeriods() { UpdatePeriod[] values = UpdatePeriod.values(); Object[][] ret = new Object[values.length][1]; for (int i = 0; i < values.length; i++) { ret[i][0] = values[i]; } return ret; }
public static UpdatePeriod fromUnitName(String unitName) throws LensException { for (UpdatePeriod up : values()) { if (up.getUnitName().equals(unitName)) { return up; } } throw new LensException(LensCubeErrorCode.INVALID_TIME_UNIT.getLensErrorInfo(), unitName); }
public static UpdatePeriod fromUnitName(String unitName) throws LensException { for (UpdatePeriod up : values()) { if (up.getUnitName().equals(unitName)) { return up; } } throw new LensException(LensCubeErrorCode.INVALID_TIME_UNIT.getLensErrorInfo(), unitName); }
@DataProvider(name = "update-periods-and-timeline-classes") public Object[][] provideUpdatePeriodsAndTimelineClasses() { UpdatePeriod[] values = UpdatePeriod.values(); Object[][] ret = new Object[values.length * TIMELINE_IMPLEMENTATIONS.size()][2]; for (int i = 0; i < values.length; i++) { for (int j = 0; j < TIMELINE_IMPLEMENTATIONS.size(); j++) { ret[TIMELINE_IMPLEMENTATIONS.size() * i + j] = new Object[]{ values[i], TIMELINE_IMPLEMENTATIONS.get(j), }; } } return ret; }
public void add(String partCol, TimePartition partition) throws LensException { if (get(partCol) == null) { put(partCol, new RangesPartitionTimeline("", UpdatePeriod.values()[0], partCol)); } get(partCol).add(partition.withUpdatePeriod(UpdatePeriod.values()[0]) .rangeUpto(partition.next().withUpdatePeriod(UpdatePeriod.values()[0]))); }
public void add(String partCol, TimePartition partition) throws LensException { if (get(partCol) == null) { put(partCol, new RangesPartitionTimeline("", UpdatePeriod.values()[0], partCol)); } get(partCol).add(partition.withUpdatePeriod(UpdatePeriod.values()[0]) .rangeUpto(partition.next().withUpdatePeriod(UpdatePeriod.values()[0]))); }
@Test public void testMaxUpdatePeriodInInterval() throws Exception { Set<UpdatePeriod> allPeriods = new HashSet<UpdatePeriod>(); allPeriods.addAll(Arrays.asList(UpdatePeriod.values())); int i = 0; Assert.assertEquals(UpdatePeriod.WEEKLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2013-Jan-01 to 2013-Jan-31"); i += 2; Assert.assertEquals(UpdatePeriod.QUARTERLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2013-Jan-01 to 2013-May-31"); i += 2; Assert.assertEquals(UpdatePeriod.QUARTERLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2013-Jan-01 to 2013-Dec-31"); i += 2; Assert.assertEquals(UpdatePeriod.MONTHLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2013-Feb-01 to 2013-Apr-25"); i += 2; Assert.assertEquals(UpdatePeriod.QUARTERLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2012-Feb-01 to 2013-Feb-01"); i += 2; Assert.assertEquals(UpdatePeriod.YEARLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2011-Feb-01 to 2013-Feb-01"); i += 2; Assert.assertEquals(UpdatePeriod.WEEKLY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2013-Feb-01 to 2013-Feb-21"); i += 2; Assert.assertEquals(UpdatePeriod.DAILY, CubeFactTable.maxIntervalInRange(pairs[i], pairs[i + 1], allPeriods), "2013-Feb-01 to 2013-Feb-4"); }
@Test(dataProvider = "update-periods") public void test(UpdatePeriod up) throws LensException { // Normal date object parsable String nowStr = up.format(NOW); // Create partition by date object or it's string representation -- both should be same. TimePartition nowPartition = TimePartition.of(up, NOW); TimePartition nowStrPartition = TimePartition.of(up, nowStr); assertEquals(nowPartition, nowStrPartition); // Test next and previous assertTrue(nowPartition.next().after(nowPartition)); assertTrue(nowPartition.previous().before(nowPartition)); // date parse failures should give lens exception assertEquals(getLensExceptionFromPartitionParsing(up, "garbage").getMessage(), TimePartition.getWrongUpdatePeriodMessage(up, "garbage")); getLensExceptionFromPartitionParsing(up, (Date) null); getLensExceptionFromPartitionParsing(up, (String) null); getLensExceptionFromPartitionParsing(up, ""); // parse with other update periods for (UpdatePeriod up2 : UpdatePeriod.values()) { // handles the equality case and the case where monthly-quarterly have same format strings. if (up.formatStr().equals(up2.formatStr())) { continue; } // Parsing a string representation with differnet update period should give lens exception. assertEquals(getLensExceptionFromPartitionParsing(up2, nowStr).getMessage(), TimePartition.getWrongUpdatePeriodMessage(up2, nowStr)); } }
@Test public void testTimeRange() throws LensException { for (UpdatePeriod up : UpdatePeriod.values()) {