@Test
  public void testBucketMonthComparator() throws Exception {
    DataSegment[] sortedOrder = {
      makeDataSegment("test1", "2011-01-01/2011-01-02", "a"),
      makeDataSegment("test1", "2011-01-02/2011-01-03", "a"),
      makeDataSegment("test1", "2011-01-02/2011-01-03", "b"),
      makeDataSegment("test2", "2011-01-01/2011-01-02", "a"),
      makeDataSegment("test2", "2011-01-02/2011-01-03", "a"),
      makeDataSegment("test1", "2011-02-01/2011-02-02", "a"),
      makeDataSegment("test1", "2011-02-02/2011-02-03", "a"),
      makeDataSegment("test1", "2011-02-02/2011-02-03", "b"),
      makeDataSegment("test2", "2011-02-01/2011-02-02", "a"),
      makeDataSegment("test2", "2011-02-02/2011-02-03", "a"),
    };

    List<DataSegment> shuffled = Lists.newArrayList(sortedOrder);
    Collections.shuffle(shuffled);

    Set<DataSegment> theSet = Sets.newTreeSet(DataSegment.bucketMonthComparator());
    theSet.addAll(shuffled);

    int index = 0;
    for (DataSegment dataSegment : theSet) {
      Assert.assertEquals(sortedOrder[index], dataSegment);
      ++index;
    }
  }
示例#2
0
  public Set<DataSegment> getAvailableDataSegments() {
    Set<DataSegment> availableSegments =
        Sets.newTreeSet(Comparators.inverse(DataSegment.bucketMonthComparator()));

    Iterable<DataSegment> dataSegments =
        Iterables.concat(
            Iterables.transform(
                databaseSegmentManager.getInventory(),
                new Function<DruidDataSource, Iterable<DataSegment>>() {
                  @Override
                  public Iterable<DataSegment> apply(DruidDataSource input) {
                    return input.getSegments();
                  }
                }));

    for (DataSegment dataSegment : dataSegments) {
      if (dataSegment.getSize() < 0) {
        log.makeAlert("No size on Segment, wtf?").addData("segment", dataSegment).emit();
      }
      availableSegments.add(dataSegment);
    }

    return availableSegments;
  }