public long endOffset(TopicPartition topicPartition) throws TimeoutException, InterruptedException, ExecutionException {
        try (Admin admin = createAdminClient()) {
            Map<TopicPartition, OffsetSpec> offsets = Collections.singletonMap(
                    topicPartition, OffsetSpec.latest()
            );
            return admin.listOffsets(offsets)
                    .partitionResult(topicPartition)
                    // Hardcode duration for now; if necessary, we can add a parameter for it later
                    .get(10, TimeUnit.SECONDS)
                    .offset();
        }
    }
Consume all currently-available records for the specified topics in a given duration, or throw an exception.
@param maxDurationMs the max duration to wait for these records (in milliseconds).
@param consumerProps overrides to the default properties the consumer is constructed with; may be null
@param adminProps overrides to the default properties the admin used to query Kafka cluster metadata is constructed with; may be null
@param topics the topics to consume from
@return a {@link ConsumerRecords} collection containing the records for all partitions of the given topics
connect/runtime/src/test/java/org/apache/kafka/connect/util/clusters/EmbeddedKafkaCluster.java