Esempio n. 1
0
 @Test
 public void testMissingSamplePath() {
   TestHelpers.assertThrows(
       "Should complain when no sample csv is given",
       IllegalArgumentException.class,
       new Callable<Void>() {
         @Override
         public Void call() throws Exception {
           command.run();
           return null;
         }
       });
   verifyZeroInteractions(console);
 }
  @Test
  public void testRelativePaths() {
    FileSystemPartitionView<TestRecord> partition =
        partitioned.getPartitionView(URI.create("id_hash=0"));
    Assert.assertEquals(
        "Should accept a relative URI",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have a the same relative URI",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition = partitioned.getPartitionView(new Path("id_hash=0"));
    Assert.assertEquals(
        "Should accept a relative Path",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have the an equivalent relative Path",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition = partitioned.getPartitionView((URI) null);
    Assert.assertEquals(
        "Should accept a null URI",
        URI.create("file:/tmp/datasets/partitioned"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have the an equivalent relative URI", null, partition.getRelativeLocation());

    partition = partitioned.getPartitionView((Path) null);
    Assert.assertEquals(
        "Should accept a null Path",
        URI.create("file:/tmp/datasets/partitioned"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have the an equivalent relative Path", null, partition.getRelativeLocation());

    TestHelpers.assertThrows(
        "Should reject empty Path",
        NumberFormatException.class,
        new Runnable() {
          @Override
          public void run() {
            partitioned.getPartitionView(URI.create(""));
          }
        });
  }
Esempio n. 3
0
 @Test
 public void testMultipleSamplesFail() throws Exception {
   command.samplePaths = Lists.newArrayList(sample, "target/sample2.csv");
   TestHelpers.assertThrows(
       "Should reject saving multiple schemas in a file",
       IllegalArgumentException.class,
       new Callable<Void>() {
         @Override
         public Void call() throws Exception {
           command.run();
           return null;
         }
       });
   verifyNoMoreInteractions(console);
 }
  @Test
  public void testFullPaths() {
    FileSystemPartitionView<TestRecord> partition =
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned"));
    Assert.assertEquals(
        "Should accept a full root URI",
        URI.create("file:/tmp/datasets/partitioned"),
        partition.getLocation());
    Assert.assertEquals("Should have a null relative URI", null, partition.getRelativeLocation());

    partition = partitioned.getPartitionView(new Path("file:/tmp/datasets/partitioned"));
    Assert.assertEquals(
        "Should accept a full root Path",
        URI.create("file:/tmp/datasets/partitioned"),
        partition.getLocation());
    Assert.assertEquals("Should have a null relative Path", null, partition.getRelativeLocation());

    partition =
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/id_hash=0"));
    Assert.assertEquals(
        "Should accept a full sub-partition URI",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have a correct relative URI",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition = partitioned.getPartitionView(new Path("file:/tmp/datasets/partitioned/id_hash=0"));
    Assert.assertEquals(
        "Should accept a full sub-partition Path",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have a correct relative Path",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition = partitioned.getPartitionView(URI.create("/tmp/datasets/partitioned/id_hash=0"));
    Assert.assertEquals(
        "Should accept a schemeless URI",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have a correct relative URI",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition = partitioned.getPartitionView(new Path("/tmp/datasets/partitioned/id_hash=0"));
    Assert.assertEquals(
        "Should accept a schemeless Path",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should have a correct relative Path",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition = partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/"));
    Assert.assertEquals(
        "Should strip trailing slash from full URI",
        URI.create("file:/tmp/datasets/partitioned"),
        partition.getLocation());
    Assert.assertEquals(
        "Should should strip trailing slash from relative URI",
        null,
        partition.getRelativeLocation());

    partition =
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/id_hash=0/"));
    Assert.assertEquals(
        "Should strip trailing slash from full URI",
        URI.create("file:/tmp/datasets/partitioned/id_hash=0"),
        partition.getLocation());
    Assert.assertEquals(
        "Should should strip trailing slash from relative URI",
        URI.create("id_hash=0"),
        partition.getRelativeLocation());

    partition =
        partitioned.getPartitionView(URI.create("file:/tmp/datasets/partitioned/id_hash=5"));
    Assert.assertEquals(
        "Should accept non-existent full URI",
        URI.create("file:/tmp/datasets/partitioned/id_hash=5"),
        partition.getLocation());
    Assert.assertEquals(
        "Should should have correct non-existent relative URI",
        URI.create("id_hash=5"),
        partition.getRelativeLocation());

    TestHelpers.assertThrows(
        "Should reject paths not in the dataset",
        IllegalArgumentException.class,
        new Runnable() {
          @Override
          public void run() {
            partitioned.getPartitionView(URI.create("file:/tmp/datasets/unpartitioned"));
          }
        });

    TestHelpers.assertThrows(
        "Should reject paths not in the dataset",
        IllegalArgumentException.class,
        new Runnable() {
          @Override
          public void run() {
            partitioned.getPartitionView(URI.create("file:/tmp/datasets"));
          }
        });

    TestHelpers.assertThrows(
        "Should reject paths in other file systems",
        IllegalArgumentException.class,
        new Runnable() {
          @Override
          public void run() {
            partitioned.getPartitionView(URI.create("hdfs:/tmp/datasets/partitioned"));
          }
        });

    TestHelpers.assertThrows(
        "Should reject paths deeper than partitions",
        IllegalArgumentException.class,
        new Runnable() {
          @Override
          public void run() {
            partitioned.getPartitionView(
                URI.create("hdfs:/tmp/datasets/partitioned/id_hash=0/data_hash=2"));
          }
        });

    TestHelpers.assertThrows(
        "Should reject invalid paths",
        NumberFormatException.class,
        new Runnable() {
          @Override
          public void run() {
            partitioned.getPartitionView(
                URI.create("file:/tmp/datasets/partitioned/id_hash=trees"));
          }
        });
  }