コード例 #1
0
  @Test
  public void testSplitLimitSize() {
    mts = new MerkleTrees(partitioner);

    mts.addMerkleTree(2, fullRange());

    assertTrue(mts.split(tok(4)));
    assertEquals(2, mts.size());

    // should fail to split above maxsize
    assertFalse(mts.split(tok(2)));
    assertEquals(2, mts.size());
    assertEquals(new Range<>(tok(4), tok(-1)), mts.get(tok(-1)));
    assertEquals(new Range<>(tok(-1), tok(4)), mts.get(tok(4)));
  }
コード例 #2
0
  @Test
  public void testSplit() {
    // split the range  (zero, zero] into:
    //  (zero,four], (four,six], (six,seven] and (seven, zero]
    mts.split(tok(4));
    mts.split(tok(6));
    mts.split(tok(7));

    assertEquals(4, mts.size());
    assertEquals(new Range<>(tok(7), tok(-1)), mts.get(tok(-1)));
    assertEquals(new Range<>(tok(-1), tok(4)), mts.get(tok(3)));
    assertEquals(new Range<>(tok(-1), tok(4)), mts.get(tok(4)));
    assertEquals(new Range<>(tok(4), tok(6)), mts.get(tok(6)));
    assertEquals(new Range<>(tok(6), tok(7)), mts.get(tok(7)));

    // check depths
    assertEquals((byte) 1, mts.get(tok(4)).depth);
    assertEquals((byte) 2, mts.get(tok(6)).depth);
    assertEquals((byte) 3, mts.get(tok(7)).depth);
    assertEquals((byte) 3, mts.get(tok(-1)).depth);

    try {
      mts.split(tok(-1));
      fail("Shouldn't be able to split outside the initial range.");
    } catch (AssertionError e) {
      // pass
    }
  }
コード例 #3
0
  @Test
  public void testSplitLimitDepth() {
    mts = new MerkleTrees(partitioner);

    mts.addMerkleTree(Integer.MAX_VALUE, (byte) 2, fullRange());

    assertTrue(mts.split(tok(4)));
    assertTrue(mts.split(tok(2)));
    assertEquals(3, mts.size());

    // should fail to split below hashdepth
    assertFalse(mts.split(tok(1)));
    assertEquals(3, mts.size());
    assertEquals(new Range<>(tok(4), tok(-1)), mts.get(tok(-1)));
    assertEquals(new Range<>(tok(-1), tok(2)), mts.get(tok(2)));
    assertEquals(new Range<>(tok(2), tok(4)), mts.get(tok(4)));
  }