public synchronized void fenceProducer() {
        verifyNotClosed();
        verifyNotFenced();
        verifyTransactionsInitialized();
        this.producerFenced = true;
    }
Set a mock metric for testing purpose
clients/src/main/java/org/apache/kafka/clients/producer/MockProducer.java