Пример #1
0
 private void write(Checkpoint checkpoint, byte[] buf) throws IOException {
   BufferedChecksumStreamOutput output =
       new BufferedChecksumStreamOutput(new ByteArrayStreamOutput(buf));
   output.writeShort((short) Checkpoint.VERSION);
   output.writeInt(checkpoint.getPageNum());
   output.writeInt(checkpoint.getFirstUnackedPageNum());
   output.writeLong(checkpoint.getFirstUnackedSeqNum());
   output.writeLong(checkpoint.getMinSeqNum());
   output.writeInt(checkpoint.getElementCount());
   output.writeInt((int) output.getChecksum());
 }
Пример #2
0
  @Test
  public void writeNewReadExisting() throws IOException {
    io.write("checkpoint.head", 1, 2, 3, 4, 5);

    Checkpoint checkpoint = io.read("checkpoint.head");

    assertThat(checkpoint.getPageNum(), is(equalTo(1)));
    assertThat(checkpoint.getFirstUnackedPageNum(), is(equalTo(2)));
    assertThat(checkpoint.getFirstUnackedSeqNum(), is(equalTo(3L)));
    assertThat(checkpoint.getMinSeqNum(), is(equalTo(4L)));
    assertThat(checkpoint.getElementCount(), is(equalTo(5)));
  }