Example #1
0
  @Test
  @Category(UnitTest.class)
  public void readSplitsPath() throws IOException {
    File splitFolder = folder.newFolder(testName.getMethodName());
    File splitfile = new File(splitFolder, "partitions");

    FileOutputStream stream = new FileOutputStream(splitfile);
    PrintWriter writer = new PrintWriter(stream);

    writer.println(generated.length);
    for (int i = 0; i < generated.length; i++) {
      writer.print(generated[i]);
      writer.print(" ");
      writer.println(i);
    }

    writer.close();
    stream.close();

    Splits splits = new PartitionerSplit();
    splits.readSplits(new Path(splitFolder.toURI()));

    PartitionerSplit.PartitionerSplitInfo[] si =
        (PartitionerSplit.PartitionerSplitInfo[]) splits.getSplits();

    Assert.assertEquals("Splits length not correct", generated.length, si.length);
    for (int i = 0; i < generated.length; i++) {
      Assert.assertEquals("Splits entry not correct", generated[i].longValue(), si[i].getTileId());
    }
  }
Example #2
0
  @Test
  @Category(UnitTest.class)
  public void writeSplitsPath() throws IOException {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    File splitfile = folder.newFolder(testName.getMethodName());

    splits.writeSplits(new Path(splitfile.toURI()));

    FileInputStream in = new FileInputStream(new File(splitfile, "partitions"));
    Scanner reader = new Scanner(in);

    Assert.assertEquals("Wrong number written", generated.length, reader.nextInt());

    PartitionerSplit.PartitionerSplitInfo[] si =
        (PartitionerSplit.PartitionerSplitInfo[]) splits.getSplits();

    for (int i = 0; i < generated.length; i++) {
      Assert.assertEquals("Splits entry not correct", generated[i].longValue(), reader.nextLong());
      Assert.assertEquals("Partition entry not correct", i, reader.nextLong());
    }

    reader.close();
  }
Example #3
0
  @Test
  @Category(UnitTest.class)
  public void getSplitIndexHigh() throws Splits.SplitException {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    Assert.assertEquals(splits.length() - 1, splits.getSplitIndex(1000));
  }
Example #4
0
  @Test
  @Category(UnitTest.class)
  public void getLength() {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    Assert.assertEquals("Splits length not correct", generated.length, splits.length());
  }
Example #5
0
  @Test(expected = Splits.SplitException.class)
  @Category(UnitTest.class)
  public void getSplitHigh() throws Splits.SplitException {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    splits.getSplit(1000);
  }
Example #6
0
  @Test
  @Category(UnitTest.class)
  public void getSplitsNoGenerate() {
    Splits splits = new PartitionerSplit();

    PartitionerSplit.PartitionerSplitInfo[] si =
        (PartitionerSplit.PartitionerSplitInfo[]) splits.getSplits();

    Assert.assertNull("Splits not null", si);
  }
Example #7
0
  @Test
  @Category(UnitTest.class)
  public void getSplitLow() throws Splits.SplitException {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    PartitionerSplit.PartitionerSplitInfo split =
        (PartitionerSplit.PartitionerSplitInfo) splits.getSplit(0);

    Assert.assertEquals("Splits entry not correct", 0, split.getPartition());
  }
Example #8
0
  @Test
  @Category(UnitTest.class)
  public void generateSplits() {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    PartitionerSplit.PartitionerSplitInfo[] si =
        (PartitionerSplit.PartitionerSplitInfo[]) splits.getSplits();

    Assert.assertEquals("Splits length not correct", generated.length, si.length);
    for (int i = 0; i < generated.length; i++) {
      Assert.assertEquals("Splits entry not correct", generated[i].longValue(), si[i].getTileId());
    }
  }
Example #9
0
  @Test
  @Category(UnitTest.class)
  public void getSplit() throws Splits.SplitException {
    Splits splits = new PartitionerSplit();
    splits.generateSplits(new TestGenerator());

    Random rand = new Random();
    for (int i = 0; i < 1000; i++) {
      long test = rand.nextInt(generated[generated.length - 1].intValue());
      long testPartition = findSplit(generated, test);

      PartitionerSplit.PartitionerSplitInfo split =
          (PartitionerSplit.PartitionerSplitInfo) splits.getSplit(test);

      Assert.assertEquals("Splits entry not correct", testPartition, split.getPartition());
    }
  }
Example #10
0
 @Test(expected = Splits.SplitException.class)
 @Category(UnitTest.class)
 public void getSplitNotGenerated() throws Splits.SplitException {
   Splits splits = new PartitionerSplit();
   splits.getSplit(10);
 }