}
public static EditLogOutputStream writeRandomSegment(MiniJournalCluster cluster,
QuorumJournalManager qjm, long startTxId, int numTxns,
boolean finalize, List<FSEditLogOp> writtenTxns) throws IOException {
EditLogOutputStream stm = qjm.startLogSegment(startTxId);
// Should create in-progress
assertExistsInQuorum(cluster,
NNStorage.getInProgressEditsFileName(startTxId));
List<FSEditLogOp> txns = FSEditLogTestUtil.getContiguousLogSegment(
(int) startTxId, ((int) startTxId + numTxns - 1));
for (FSEditLogOp op : txns) {
stm.write(op);
stm.setReadyToFlush();
stm.flush();
if (writtenTxns != null) {
writtenTxns.add(op);
}
}
if (finalize) {
stm.close();
qjm.finalizeLogSegment(startTxId, startTxId + numTxns - 1);
return null;
} else {
return stm;
}