public static MetadataSnapshot metadataSnapshotWith(final int nodes, final Map<String, Integer> topicPartitionCounts) {
        final Node[] ns = new Node[nodes];
        Map<Integer, Node> nodesById = new HashMap<>();
        for (int i = 0; i < nodes; i++) {
            ns[i] = new Node(i, "localhost", 1969);
            nodesById.put(ns[i].id(), ns[i]);
        }
        final List<PartitionMetadata> partsMetadatas = new ArrayList<>();
        for (final Map.Entry<String, Integer> topicPartition : topicPartitionCounts.entrySet()) {
            final String topic = topicPartition.getKey();
            final int partitions = topicPartition.getValue();
            for (int i = 0; i < partitions; i++) {
                TopicPartition tp = new TopicPartition(topic, partitions);
                Node node = ns[i % ns.length];
                partsMetadatas.add(new PartitionMetadata(Errors.NONE, tp, Optional.of(node.id()), Optional.empty(), null, null, null));
            }
        }
        return new MetadataSnapshot("kafka-cluster", nodesById, partsMetadatas, Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), null, Collections.emptyMap());
    }
Test utility function to get MetadataSnapshot with configured nodes and partitions.
@param nodes number of nodes in the cluster
@param topicPartitionCounts map of topic -> # of partitions
@return a MetadataSnapshot with number of nodes, partitions as per the input.
clients/src/test/java/org/apache/kafka/test/TestUtils.java