Add getNextIndex to RaftAlgorithm

- Also update leader checks to avoid potential NPE
Add randomized AppendEntriesReplyInputTest for the "PREFIX_SEARCH" phase