예제 #1
0
  private void assertHandlesLogTruncation(XaCommand cmd) throws IOException {
    inMemoryBuffer.reset();
    cmd.writeToFile(inMemoryBuffer);

    int bytesSuccessfullyWritten = inMemoryBuffer.bytesWritten();
    assertEquals(cmd, Command.readCommand(null, null, inMemoryBuffer, ByteBuffer.allocate(100)));

    bytesSuccessfullyWritten--;

    while (bytesSuccessfullyWritten-- > 0) {
      inMemoryBuffer.reset();
      cmd.writeToFile(inMemoryBuffer);
      inMemoryBuffer.truncateTo(bytesSuccessfullyWritten);

      Command deserialized =
          Command.readCommand(null, null, inMemoryBuffer, ByteBuffer.allocate(100));

      assertNull(
          "Deserialization did not detect log truncation! Record: "
              + cmd
              + ", deserialized: "
              + deserialized,
          deserialized);
    }
  }