Example #1
0
 private void instantiateWriter() throws IOException {
   out =
       new PrintWriter(
           new OutputStreamWriter(fileSystem.openAsOutputStream(file, true), encoding));
   for (Runnable trigger : onRotation) {
     trigger.run();
   }
 }
  @Test
  public void shouldReadALogHeaderFromAFile() throws IOException {
    // given
    final FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
    final File file = File.createTempFile("ReadLogHeader", getClass().getSimpleName());

    final ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
    buffer.putLong(encodeLogVersion(expectedLogVersion));
    buffer.putLong(expectedTxId);

    try (OutputStream stream = fs.openAsOutputStream(file, false)) {
      stream.write(buffer.array());
    }

    // when
    final LogHeader result = readLogHeader(fs, file);

    // then
    assertEquals(new LogHeader(CURRENT_LOG_VERSION, expectedLogVersion, expectedTxId), result);
  }