public static <T> boolean sameElementsWithOrder(Iterator<T> iterator1,
                                                    Iterator<T> iterator2) {
        while (iterator1.hasNext()) {
            if (!iterator2.hasNext()) {
                return false;
            }

            if (!Objects.equals(iterator1.next(), iterator2.next())) {
                return false;
            }
        }

        return !iterator2.hasNext();
    }
Returns true if both iterators have same elements in the same order.

@param iterator1 first iterator.
@param iterator2 second iterator.
@param <T>       type of element in the iterators.
clients/src/test/java/org/apache/kafka/test/TestUtils.java