Examples of HeapRecord


Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

  public void testStoreRestore() throws Exception {// NOPMD
    /*
     * data record
     */
    HeapRecord heapRecord = new HeapRecord(
    /**/this/*
         * IHeapElementManager heapElementManager
         */,
    /**/0/* long positionInFile */,
    /**/1L/* long previousRecordPositionInFile */,
    /**/DataRecordIdentifier.ZERO/* long nodeIdentification */,
    /**/false/* boolean freeRecord */,
    /**/10/* int dataAssociatedSize */,
    /**/100/* int areaSize */);
    final HeapIdNode heapIdNode = (HeapIdNode) heapRecord.getIdNode();
    heapIdNode.setLeftPositionInFile(2);
    heapIdNode.setRightPositionInFile(3);
    heapIdNode.setParentPositionInFile(4);
    try {
      heapIdNode.setBlack();
    } catch (Exception exception) {
      // ignore error
    }
    // byte[] data = heapRecord.getDataAssociated();
    final byte[] data = new byte[10];
    heapRecord.setDataAssociated(data);
    System.arraycopy("0123456789".getBytes(), 0, data, 0, 10);
    heapRecord.setValueIsChangedValueToSave();
    heapRecord.writeToFile();
    readAndCheck(heapRecord, data);

    /*
     * free record
     */
    heapRecord = new HeapRecord(
    /**/this/*
         * IHeapElementManager heapElementManager
         */,
    /**/0/* long positionInFile */,
    /**/90L/* long previousRecordPositionInFile */,
    /**/DataRecordIdentifier.ZERO/* long nodeIdentification */,
    /**/true/* boolean freeRecord */,
    /**/0/* int dataAssociatedSize */,
    /**/100/* int areaSize */);

    final HeapFreeNode heapFreeNode = (HeapFreeNode) heapRecord
        .getFreeNode();
    heapFreeNode.setLeftPositionInFile(91);
    heapFreeNode.setRightPositionInFile(92);
    heapFreeNode.setParentPositionInFile(93);
    try {
      heapFreeNode.setBlack();
    } catch (Exception exception) {
      // ignore error
    }
    // to force write
    heapRecord.setValueIsChangedValueToSave();
    heapRecord.writeToFile();
    readAndCheck(heapRecord, null);
  }
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

   * @throws RBTException
   * @throws FileCorruptedException
   */
  private void readAndCheck(final HeapRecord heapRecordWrote,
      final byte[] expectedData) throws HeapException, RBTException {
    final HeapRecord heapRecordRead = new HeapRecord(
    /**/this,/* IHeapElementManager heapElementManager */
    /**/0/* long positionInFile */);
    heapRecordRead.readFromFile();
    assertHeapNodeEquals(heapRecordWrote, heapRecordRead, expectedData);
  }
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

    /* then read header */
    heapElementManager.startService();
    heapElementManager.openTransaction();
    final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
    /* create heap record */
    final HeapRecord heapRecord = new HeapRecord(heapElementManager,
    /**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
    // heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
    // heapElementManager, heapRecord).getPositionInFile());
    heapHeader2.setFreeRootNodeFilePosition(heapRecord.getPositionInFile());
    // heapHeader2.setIdRootNodeFilePosition(new HeapIdNode(
    // heapElementManager, heapRecord).getPositionInFile());
    heapHeader2.setIdRootNodeFilePosition(heapRecord.getPositionInFile());
    /* write modifications */
    heapElementManager.closeTransaction();

    /* read the last modification */
    heapElementManager.openTransaction();
 
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

    appendRecord();
    heapElementManager.startService();
    heapElementManager.openTransaction();

    final int dataSize = 100;
    final HeapRecord heapRecord1 = readHeapFileDataRecord(record1pos);
    assertEquals("bad record position", record1pos,
        heapRecord1.getPositionInFile());
    assertEquals("bad record data size", dataSize, heapRecord1
        .getDataAssociatedSize().intValue());
    final byte[] data1 = heapRecord1.getDataAssociated();
    for (int index = 0; index < dataSize; index++) {
      assertEquals("bad record data", index, data1[index]);
    }
    logger.debug("heap record1\n" + heapRecord1.toString());
    assertEquals("read must be equals appened", heapRecordAppened1,
        heapRecord1);

    final HeapRecord heapRecord2 = readHeapFileDataRecord(record2pos);
    assertEquals("bad record position", record2pos,
        heapRecord2.getPositionInFile());
    assertEquals("bad record data size", dataSize, heapRecord2
        .getDataAssociatedSize().intValue());
    final byte[] data2 = heapRecord2.getDataAssociated();
    assertNotSame("heap record 1 and 2 must not have the same data", data1,
        data2);
    for (int index = 0; index < 100; index++) {
      assertEquals("bad record data", index, data2[index]);
    }
    logger.debug("heap record2\n" + heapRecord2.toString());
    assertEquals("read must be equals appened", heapRecordAppened2,
        heapRecord2);

    heapElementManager.closeTransaction();
    heapElementManager.stopService();
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

    appendRecord();
    final long pos = record1pos;

    heapElementManager.startService();
    heapElementManager.openTransaction();
    HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
    byte[] data1 = heapRecord1.getDataAssociated();
    for (int index = 0; index < data1.length; index++) {
      data1[index] = (byte) (data1.length - index);
    }
    heapRecord1.setDataAssociated(data1);
    heapElementManager.closeTransaction();

    heapElementManager.openTransaction();
    heapRecord1 = readHeapFileDataRecord(pos);
    data1 = heapRecord1.getDataAssociated();
    for (int index = 0; index < data1.length; index++) {
      assertEquals("bad record data", data1.length - index, data1[index]);
    }
    heapElementManager.closeTransaction();
    heapElementManager.stopService();
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

    final long pos = record1pos;

    heapElementManager.startService();

    heapElementManager.openTransaction();
    HeapRecord heapRecord1 = readHeapFileDataRecord(pos);

    try {
      assert false;
    } catch (AssertionError error) {
      try {
        heapRecord1.getFreeNode();
        fail("must not obtain free node");// NOPMD
      } catch (AssertionError error2) {// NOPMD nothing to do when
        // exception thrown
        // expected
      }
    }
    IRBTNode<?> node = heapRecord1.getIdNode();
    boolean color;
    if (node.isColorSetted()) {
      color = node.getColor();
    } else {
      color = true;
    }
    node.setColor(!color);
    assertTrue("value must have changed",
        heapRecord1.isValueChangedToSave());
    heapElementManager.closeTransaction();

    heapElementManager.openTransaction();
    heapRecord1 = readHeapFileDataRecord(pos);
    node = heapRecord1.getIdNode();
    assertEquals("color must have changed", !color, node.getColor());
    assertFalse("not modified record", heapRecord1.isValueChangedToSave());
    heapElementManager.closeTransaction();

    heapElementManager.openTransaction();
    heapRecord1 = readHeapFileDataRecord(pos);
    heapRecord1.freeRecord();
    try {
      assert false;
    } catch (AssertionError error) {
      try {
        heapRecord1.getIdNode();
        fail("must not obtain id node");// NOPMD
      } catch (AssertionError error2) {// NOPMD nothing to do when
        // exception thrown
        // expected
      }
    }
    node = heapRecord1.getFreeNode();
    if (node.isColorSetted()) {
      color = node.getColor();
    } else {
      color = true;
    }
    node.setColor(!color);
    heapElementManager.closeTransaction();

    heapElementManager.openTransaction();
    heapRecord1 = readHeapFileDataRecord(pos);
    node = heapRecord1.getFreeNode();
    assertEquals("color must have changed", !color, node.getColor());
    heapElementManager.closeTransaction();
    heapElementManager.stopService();
  }
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

    heapElementManager.startService();
    heapElementManager.openTransaction();
    /*
     * read record 1 whithout data managing and check state
     */
    HeapRecord heapRecord1 = readHeapFileDataRecord(
    /**/pos/* position in file */);
    assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
    assertFalse("record1 must be in state just created",
        heapRecord1.isJustCreated());
    assertTrue("record1 has been read", heapRecord1.isHeaderRead());
    assertFalse("record1 value must not changed state",
        heapRecord1.isValueChangedToSave());

    /*
     * set record 1 value changer, check if added to be wrote
     */
    heapRecord1.setValueIsChangedValueToSave();
    assertNotNull("must be in cache",
        heapElementManager.getHeapFileRecordInWriteCache(pos));

    // heapRecord1.createDataArea();

    heapElementManager.closeTransaction();
    heapElementManager.openTransaction();

    /*
     * change to manage data mode
     */
    heapRecord1 = readHeapFileDataRecord(
    /**/pos/* position in file */);
    assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
    assertFalse("must not be just created", heapRecord1.isJustCreated());
    assertTrue("must has been read", heapRecord1.isHeaderRead());
    assertFalse("value changed must not change",
        heapRecord1.isValueChangedToSave());
    assertNotNull("must be in cache",
        heapElementManager.getHeapFileRecordInReadCache(pos));

    heapElementManager.closeTransaction();
    heapElementManager.stopService();
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

    heapElementManager.startService();
    heapElementManager.openTransaction();
    record1pos = HeapHeader.HEAP_HEADER_SIZE;
    final int dataSize = 100;
    final DataRecordIdentifier dataRecordIdentifier = DataRecordIdentifier.ZERO;
    heapRecordAppened1 = new HeapRecord(heapElementManager, record1pos,
        -1L/* prev pos */, dataRecordIdentifier/* id */,
        false/* free */, dataSize, dataSize
            + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
                                 * area size: +
                                 * 4 for crc32
                                 */);

    // heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
    // -1L/* prev pos */, dataRecordIdentifier/* id */,
    // false/* free */, dataSize, dataSize
    // + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
    // * area size: +
    // * 4 for crc32
    // */);
    heapElementManager.appendHeapFileRecord(heapRecordAppened1);

    IRBTNode<DataRecordIdentifier> idNode = heapRecordAppened1.getIdNode();
    idNode.setColor(RedBlackTree.BLACK);

    try {
      assert false;
    } catch (AssertionError error) {
      try {
        heapRecordAppened1.getDataAssociated();
        fail("there is no data associated to record");
      } catch (AssertionError error2) {// NOPMD
        // expected error
      }
    }

    byte[] testData = new byte[dataSize];
    for (int index = 0; index < dataSize; index++) {
      testData[index] = (byte) index;
    }
    heapRecordAppened1.setDataAssociated(testData);

    heapElementManager.closeTransaction();
    logger.debug("appened heap record1\n" + heapRecordAppened1.toString());

    heapElementManager.openTransaction();

    record2pos = record1pos + heapRecordAppened1.getRecordSize();
    heapRecordAppened2 = new HeapRecord(heapElementManager, record2pos,
        record1pos, dataRecordIdentifier/* id */, false/* free */,
        dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
                                     * 4 for
                                     * crc32
                                     */);
 
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

  @Override
  public IFileStorable createHeapRecord(
      final IHeapElementManager heapElementManager,
      final long positionInFile) throws HeapException {
    return new HeapRecord(heapElementManager, positionInFile);
  }
View Full Code Here

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord

  public void testAddDataRecordNoClose() throws HeapException, RBTException {
    long previousPosition = -1L;
    for (int index = 0; index < 10; index++) {
      final long position = (long) HeapHeader.HEAP_HEADER_SIZE
          + (long) index * 100;
      @SuppressWarnings("PMD")
      final HeapRecord heapRecord = new HeapRecord(heapElementManager,
          position, previousPosition, newDataRecordIdentifier(index),
          false/* freeRecord */, 10/* dataAssociatedSize */, 100/* areaSize */);
      // final HeapRecord heapRecord = heapElementManager
      // .newHeapFileRecord(position, previousPosition,
      // newDataRecordIdentifier(index),
      // false/* freeRecord */, 10/* dataAssociatedSize */,
      // 100/* areaSize */);
      heapElementManager.appendHeapFileRecord(heapRecord);
      heapRecord.setDataAssociated(new byte[10]);// NOPMD new in loop is
      // ok
      previousPosition = position;
      final IRBTNode<DataRecordIdentifier> node = heapRecord.getIdNode();
      idNodeTree.append(node);

      final HeapIdNode foundNode = (HeapIdNode) idNodeTree
          .search(newDataRecordIdentifier(index));
      assertNotNull("must found nod", foundNode);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.