Exemplo n.º 1
0
  //
  // Verify that, after replacing a hole and the highest-offset extent in a
  // two entry map with one that leaves a byte of the replaced extent
  // protruding:
  //  -   The resulting map has the correct number of entries.
  //  -   The protrusion from the high end of the map properly appears in
  //      the resulting map.
  //
  // This test recreates the circumstances of a bug observed while testing
  // the BufferCache class.
  //
  @Test
  public final void testReplaceExtentsR0() {
    ByteBuffer b00_01 = ByteBuffer.wrap("0".getBytes());
    ByteBuffer b02_04 = ByteBuffer.wrap("23".getBytes());
    ExtentBuffer eb00_01 = new ExtentBuffer(0L, b00_01);
    ExtentBuffer eb02_04 = new ExtentBuffer(2L, b02_04);
    ExtentBufferMap m00_04 = new ExtentBufferMap();
    m00_04.put(eb00_01);
    m00_04.put(eb02_04);

    ByteBuffer b01_03 = ByteBuffer.wrap("ab".getBytes());
    ExtentBuffer eb01_03 = new ExtentBuffer(1L, b01_03);

    m00_04.replaceExtents(eb01_03);
    assertEquals("resulting map should have 3 extents", m00_04.size(), 3);
    assertEquals(
        "the extent starting at offset 1 in the result "
            + " should be the one given as the replacement",
        m00_04.get(1L),
        eb01_03);
    //
    // XXX: Verify tail's contents as well as its bounds?
    //
    Extent tail = m00_04.get(m00_04.lastKey());
    assertTrue(
        "resulting map should have an extent for protrusion",
        tail.getStartOffset() == 3L && tail.getEndOffset() == 4L);
  }
Exemplo n.º 2
0
  //
  // Verify that, after replacing the highest-offset extent in a two entry
  // map with one that fits entirely within the replacee's interior:
  //  -   The resulting map has the correct number of extents.
  //  -   The replacement extent appears within the resulting map.
  //
  // XXX: There are more things that can and should be checked here.
  //
  @Test
  public final void testReplaceExtentsLR0() {
    ByteBuffer b00_01 = ByteBuffer.wrap("0".getBytes());
    ByteBuffer b01_09 = ByteBuffer.wrap("12345678".getBytes());
    ExtentBuffer eb00_01 = new ExtentBuffer(0L, b00_01);
    ExtentBuffer eb01_09 = new ExtentBuffer(1L, b01_09);
    ExtentBufferMap m00_09 = new ExtentBufferMap();
    m00_09.put(eb00_01);
    m00_09.put(eb01_09);

    ByteBuffer b05_08 = ByteBuffer.wrap("XYZ".getBytes());
    ExtentBuffer eb05_08 = new ExtentBuffer(5L, b05_08);

    m00_09.replaceExtents(eb05_08);
    assertEquals("resulting map should have 4 extents", m00_09.size(), 4);
    assertEquals(
        "the extent starting at offset 5 in the result "
            + " should be the one given as the replacement",
        m00_09.get(5L),
        eb05_08);
  }