@Override
    public synchronized TransactionAction nextAction() {
        if (messagesInTransaction == -1) {
            messagesInTransaction = 0;
            return TransactionAction.BEGIN_TRANSACTION;
        }
        if (messagesInTransaction == messagesPerTransaction) {
            messagesInTransaction = -1;
            return TransactionAction.COMMIT_TRANSACTION;
        }

        messagesInTransaction += 1;
        return TransactionAction.NO_OP;
    }
A uniform transactions generator where every N records are grouped in a separate transaction
trogdor/src/main/java/org/apache/kafka/trogdor/workload/UniformTransactionsGenerator.java