コード例 #1
0
  @Test
  public void testCoveringPartitions() {
    Iterable<PartitionView<TestRecord>> partitions = unpartitioned.getCoveringPartitions();
    Assert.assertEquals(
        "Should have a single partition view at the root",
        unpartitioned.getPartitionView(URI.create("file:/tmp/datasets/unpartitioned")),
        Iterables.getOnlyElement(partitions));

    partitions = partitioned.getCoveringPartitions();
    Set<PartitionView<TestRecord>> expected = Sets.newHashSet();
    expected.add(
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/id_hash=0")));
    expected.add(
        partitioned.getPartitionView(new Path("file:/tmp/datasets/partitioned/id_hash=1")));
    expected.add(
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/id_hash=2")));
    expected.add(
        partitioned.getPartitionView(new Path("file:/tmp/datasets/partitioned/id_hash=3")));
    Assert.assertEquals(
        "Should have a partition view for each partition", expected, Sets.newHashSet(partitions));

    PartitionView<TestRecord> partition0 =
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/id_hash=0"));
    partition0.deleteAll();
    expected.remove(partition0);
    Assert.assertEquals(
        "Should have a partition view for each partition", expected, Sets.newHashSet(partitions));
  }
コード例 #2
0
  @Test
  public void testDeletePartitions() {
    Iterable<PartitionView<TestRecord>> partitions = partitioned.getCoveringPartitions();

    Set<PartitionView<TestRecord>> expected = Sets.newHashSet(partitions);
    for (PartitionView<TestRecord> partition : partitions) {
      Assert.assertTrue("Should delete data", partition.deleteAll());

      expected.remove(partition);
      Set<PartitionView<TestRecord>> actual = Sets.newHashSet(partitioned.getCoveringPartitions());
      Assert.assertEquals("Should only list remaining partitions", expected, actual);
    }

    for (PartitionView<TestRecord> partition : partitions) {
      Assert.assertFalse("Should indicate no data was present", partition.deleteAll());
    }
  }