コード例 #1
0
  @Test
  public void open_ignores_rollback() {
    File f = TT.tempDbFile();
    WriteAheadLog wal = new WriteAheadLog(f.getPath());
    wal.walPutLong(1L, 11L);
    wal.commit();
    wal.walPutLong(2L, 33L);
    wal.rollback();
    wal.walPutLong(3L, 33L);
    wal.commit();
    wal.seal();
    wal.close();

    wal = new WriteAheadLog(f.getPath());
    wal.open(
        new WALSequence(
            new Object[] {WALSequence.beforeReplayStart},
            new Object[] {WALSequence.writeLong, 1L, 11L},
            new Object[] {WALSequence.commit},
            // 2L is ignored, rollback section is skipped on hard replay
            new Object[] {WALSequence.writeLong, 3L, 33L},
            new Object[] {WALSequence.commit}));
    wal.destroyWalFiles();
    wal.close();

    f.delete();
  }
コード例 #2
0
  @Test
  public void overflow_record() {
    File f = TT.tempDbFile();
    f.delete();
    File f0 = new File(f.getPath() + ".wal.0");
    File f1 = new File(f.getPath() + ".wal.1");
    WriteAheadLog wal = new WriteAheadLog(f.getPath());
    wal.open(WriteAheadLog.NOREPLAY);

    long lastPos = 0;
    while (!f1.exists()) {
      lastPos = wal.fileOffset;
      wal.walPutRecord(111L, new byte[100], 0, 100);
      assertTrue(f0.exists());
    }
    assertTrue(WriteAheadLog.MAX_FILE_SIZE - 1000 < lastPos);
    assertTrue(WriteAheadLog.MAX_FILE_SIZE + 120 > lastPos);
    wal.destroyWalFiles();
  }