public static <T> Set<T> iteratorToSet(Iterator<T> iterator) {
        HashSet<T> set = new HashSet<>();
        while (iterator.hasNext()) {
            set.add(iterator.next());
        }
        return set;
    }
Materialize the output of an iterator into a set.

@param iterator      The input iterator.

@return              The output set.
metadata/src/test/java/org/apache/kafka/metadata/RecordTestUtils.java