Package net.sf.joafip.file.entity

Examples of net.sf.joafip.file.entity.FileAccessRecordForTests


          + randomFileAccess.getPageSet().toString());
    }
    // check page 0 wrote
    assertEquals(BAD_READ_ACCESS, 0, probe.readLogSize());
    assertEquals(BAD_WRITE_ACCESS, 1, probe.writeLogSize());
    FileAccessRecordForTests record = probe.pollFirstWrote();
    assertNotNull("must write at 3*PAGE_SIZE", record);
    assertEquals(BAD_POSITION_IN_FILE, 3 * PAGE_SIZE,
        record.getPositionInFile());
    assertEquals(BAD_DATA, createStrPageData('3'), record.getStrData());

    if (flushMode) {
      randomFileAccess.flush();
    } else {
      randomFileAccess.close();
    }
    // check wrote at close or flush
    assertEquals(BAD_READ_ACCESS, 0, probe.readLogSize());
    assertEquals(BAD_WRITE_ACCESS, 4, probe.writeLogSize());
    record = probe.pollFirstWrote();
    assertEquals(BAD_POSITION_IN_FILE, 0 * PAGE_SIZE,
        record.getPositionInFile());
    assertEquals(BAD_DATA, createStrPageData('0'), record.getStrData());
    record = probe.pollFirstWrote();
    assertEquals(BAD_POSITION_IN_FILE, 1 * PAGE_SIZE,
        record.getPositionInFile());
    assertEquals(BAD_DATA, createStrPageData('1'), record.getStrData());
    record = probe.pollFirstWrote();
    assertEquals(BAD_POSITION_IN_FILE, 2 * PAGE_SIZE,
        record.getPositionInFile());
    assertEquals(BAD_DATA, createStrPageData('2'), record.getStrData());
    record = probe.pollFirstWrote();
    assertEquals(BAD_POSITION_IN_FILE, 4 * PAGE_SIZE,
        record.getPositionInFile());
    assertEquals(BAD_DATA, createStrPageData('4'), record.getStrData());

    // check in read cache
    if (flushMode) {
      randomFileAccess.seek(0);
    } else {
      randomFileAccess.open();
    }
    int read = randomFileAccess.read(buffer);
    assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
    assertEquals(BAD_DATA, createStrPageData('0'), new String(buffer));
    read = randomFileAccess.read(buffer);
    assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
    assertEquals(BAD_DATA, createStrPageData('1'), new String(buffer));
    read = randomFileAccess.read(buffer);
    assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
    assertEquals(BAD_DATA, createStrPageData('2'), new String(buffer));
    read = randomFileAccess.read(buffer);
    assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
    assertEquals(BAD_DATA, createStrPageData('3'), new String(buffer));
    read = randomFileAccess.read(buffer);
    assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
    assertEquals(BAD_DATA, createStrPageData('4'), new String(buffer));
    read = randomFileAccess.read(buffer);
    assertEquals(BAD_NUMBER_OF_READ, -1, read);
    if (LOGGER.debugEnabled) {
      LOGGER.debug("after read 0,1,2,3,4 : "
          + randomFileAccess.getPageSet().toString());
    }

    if (flushMode) {
      // data kept in cache
      assertEquals(BAD_READ_ACCESS + '\n' + probe.readLogToString(), 2,
          probe.readLogSize());
      assertEquals(BAD_WRITE_ACCESS, 0, probe.writeLogSize());
      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 3 * PAGE_SIZE,
          record.getPositionInFile());
      assertEquals(BAD_DATA, createStrPageData('3'), record.getStrData());
      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 4 * PAGE_SIZE,
          record.getPositionInFile());
      assertEquals(BAD_DATA, createStrPageData('4'), record.getStrData());
    } else {
      // cache was cleared, so check read 5 records
      assertEquals(BAD_READ_ACCESS + '\n' + probe.readLogToString(), 5,
          probe.readLogSize());
      assertEquals(BAD_WRITE_ACCESS, 0, probe.writeLogSize());

      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 0 * PAGE_SIZE,
          record.getPositionInFile());
      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 1 * PAGE_SIZE,
          record.getPositionInFile());
      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 2 * PAGE_SIZE,
          record.getPositionInFile());
      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 3 * PAGE_SIZE,
          record.getPositionInFile());
      assertEquals(BAD_DATA, createStrPageData('3'), record.getStrData());
      record = probe.pollFirstRead();
      assertEquals(BAD_POSITION_IN_FILE, 4 * PAGE_SIZE,
          record.getPositionInFile());
      assertEquals(BAD_DATA, createStrPageData('4'), record.getStrData());
    }

    randomFileAccess.close();
  }
View Full Code Here


  @Override
  public int read(final byte[] data) throws FileIOException {
    final long positionInFile = delegate.currentPositionInFile();
    final int read = delegate.read(data);
    if (read > 0) {
      final FileAccessRecordForTests fileAccessRecord = new FileAccessRecordForTests(
          positionInFile, data, 0, data.length);
      readLog.add(fileAccessRecord);
    }
    return read;
  }
View Full Code Here

  public int read(final byte[] data, final int offset, final int length)
      throws FileIOException {
    final long positionInFile = delegate.currentPositionInFile();
    final int read = delegate.read(data, offset, length);
    if (read > 0) {
      final FileAccessRecordForTests fileAccessRecord = new FileAccessRecordForTests(
          positionInFile, data, offset, length);
      readLog.add(fileAccessRecord);
    }
    return read;
  }
View Full Code Here

  }

  @Override
  public void write(final byte[] data) throws FileIOException {
    final long positionInFile = delegate.currentPositionInFile();
    final FileAccessRecordForTests fileAccessRecord = new FileAccessRecordForTests(
        positionInFile, data, 0, data.length);
    delegate.write(data);
    writeLog.add(fileAccessRecord);
  }
View Full Code Here

  @Override
  public void write(final byte[] data, final int length)
      throws FileIOException {
    final long positionInFile = delegate.currentPositionInFile();
    final FileAccessRecordForTests fileAccessRecord = new FileAccessRecordForTests(
        positionInFile, data, 0, length);
    delegate.write(data);
    writeLog.add(fileAccessRecord);
  }
View Full Code Here

  @Override
  public void write(final byte[] data, final int offset, final int length)
      throws FileIOException {
    final long positionInFile = delegate.currentPositionInFile();
    final FileAccessRecordForTests fileAccessRecord = new FileAccessRecordForTests(
        positionInFile, data, offset, length);
    delegate.write(data);
    writeLog.add(fileAccessRecord);
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.file.entity.FileAccessRecordForTests

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.