private ProduceResponse produceResponse(Map<TopicPartition, OffsetAndError> responses, Map<TopicPartition, ProduceResponseData.LeaderIdAndEpoch> partitionLeaderInfo, List<Node> nodes) {
        ProduceResponseData data = new ProduceResponseData();

        for (Map.Entry<TopicPartition, OffsetAndError> entry : responses.entrySet()) {
            TopicPartition topicPartition = entry.getKey();
            ProduceResponseData.TopicProduceResponse topicData = data.responses().find(topicPartition.topic());
            if (topicData == null) {
                topicData = new ProduceResponseData.TopicProduceResponse().setName(topicPartition.topic());
                data.responses().add(topicData);
            }

            OffsetAndError offsetAndError = entry.getValue();
            ProduceResponseData.PartitionProduceResponse partitionData =
                new ProduceResponseData.PartitionProduceResponse()
                    .setIndex(topicPartition.partition())
                    .setBaseOffset(offsetAndError.offset)
                    .setErrorCode(offsetAndError.error.code())
                    .setRecordErrors(offsetAndError.recordErrors);

            if (partitionLeaderInfo != null && partitionLeaderInfo.containsKey(topicPartition)) {
                partitionData.setCurrentLeader(partitionLeaderInfo.get(topicPartition));
            }

            topicData.partitionResponses().add(partitionData);
        }

        if (nodes != null) {
            nodes.stream().map(n -> {
                ProduceResponseData.NodeEndpoint nodeEndPt = new ProduceResponseData.NodeEndpoint();
                nodeEndPt.setNodeId(n.id());
                nodeEndPt.setPort(n.port());
                nodeEndPt.setHost(n.host());
                nodeEndPt.setRack(n.rack());
                return nodeEndPt;
            }).forEach(nodeEndpoint -> data.nodeEndpoints().add(nodeEndpoint));
        }

        return new ProduceResponse(data);
    }
It creates response with new leader info and new nodes, as stated in KIP-951
clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java