Esempio n. 1
0
  public void testTruncatedHeader() throws IOException, DatabaseException {

    /* Create a log file */
    FileManagerTestUtils.createLogFile(fileManager, envImpl, FILE_SIZE);

    /* Truncate the header */
    RandomAccessFile file0 =
        new RandomAccessFile(
            fileManager.getFullFileName(0, FileManager.JE_SUFFIX),
            FileManager.FileMode.READWRITE_MODE.getModeValue());
    file0.getChannel().truncate(FileManager.firstLogEntryOffset() / 2);
    file0.close();

    try {
      fileManager.getFileHandle(0);
      fail("Should see assertion");
    } catch (DatabaseException e) {
    }
  }
Esempio n. 2
0
  /** See if we can catch a file with an invalid header. */
  public void testBadHeader() throws IOException, DatabaseException {

    /* First try a bad environment r/w. */
    try {
      FileManager test = new FileManager(envImpl, new File("xxyy"), true);
      fail("expect creation of " + test + "to fail.");
    } catch (LogException e) {
      /* should throw */
    }

    /* Next try a bad environment r/o. */
    try {
      FileManager test = new FileManager(envImpl, new File("xxyy"), false);
      fail("expect creation of " + test + "to fail.");
    } catch (DatabaseException e) {
      /* should throw */
    }

    /* Now create a file, but mess up the header. */
    FileManagerTestUtils.createLogFile(fileManager, envImpl, FILE_SIZE);

    byte[] badData = new byte[] {1, 1};
    int headerSize = FileManager.firstLogEntryOffset();
    RandomAccessFile file0 =
        new RandomAccessFile(
            fileManager.getFullFileName(0, FileManager.JE_SUFFIX),
            FileManager.FileMode.READWRITE_MODE.getModeValue());
    file0.write(badData);
    file0.close();
    fileManager.clear();

    try {
      FileHandle file0Handle = fileManager.getFileHandle(0L);
      fail("expect to catch a checksum error");
    } catch (DbChecksumException e) {
    }
  }