Package net.sf.joafip.btreeplus.entity

Examples of net.sf.joafip.btreeplus.entity.TestDataBlockContext


    // first add data
    btreePlusElementMgr.openTransaction();
    int index = 0;
    long position = PageConstant.PAGE_SIZE;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = new TestDataBlockContext(bits);// NOPMD
      contextByBits[index] = context;
      context.setPosition(position);
      addDataBlock(context, bits);
      position = context.getPosition();
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // add test
    // secondly check added
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      for (int dataBlockIndex = 0; dataBlockIndex < context.size(); dataBlockIndex++) {
        final long dataBlockPosition = context
            .getPosition(dataBlockIndex);
        final byte[] data = btreePlusElementMgr
            .getData(dataBlockPosition);
        final byte[] expectedData = createData(data.length,
            context.getContentValue(dataBlockIndex));
        assertTrue("bad content", Arrays.equals(expectedData, data));
        final IDataBlock dataBlock = btreePlusElementMgr
            .getDataBlock(dataBlockPosition);
        assertEquals("bad data block type", bits, dataBlock.getBits());
      }
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // remove test
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      final Deque<Long> positionDeque = new LinkedList<Long>();// NOPMD
      for (int dataBlockIndex = 0; dataBlockIndex < context.size(); dataBlockIndex++) {
        final long dataBlockPosition = context
            .getPosition(dataBlockIndex);
        final IDataBlock dataBlock = btreePlusElementMgr
            .getDataBlock(dataBlockPosition);
        btreePlusElementMgr.remove(dataBlock);
        assertEquals("header not updated", dataBlockPosition,
            getHeapHeader().getFreeDataBlockPosition(bits));
        positionDeque.addFirst(dataBlockPosition);
      }
      context.setPositionDeque(positionDeque);
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // check removed state
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      final Deque<Long> positionDeque = context.getPositionDeque();
      long expectedPosition = getHeapHeader().getFreeDataBlockPosition(
          bits);
      for (Long currentPosition : positionDeque) {
        assertEquals("bad free position (bits=" + bits + ")",
            expectedPosition, currentPosition.longValue());
        expectedPosition = btreePlusElementMgr.getDataBlock(
            expectedPosition).getNextFreeDataBlockPositionOfFree();
      }
      assertEquals("bad free position", -1, expectedPosition);
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // add test when free record available
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      final Iterator<Long> iterator = context.getPositionDeque()
          .iterator();
      final DataBlock dataBlock = createDataBlock(bits, (byte) 0);
      assertEquals("bad allocation", iterator.next().longValue(),
          dataBlock.getPositionInFile());
      assertEquals("bad new free", iterator.next().longValue(),
View Full Code Here

TOP

Related Classes of net.sf.joafip.btreeplus.entity.TestDataBlockContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.