public ProduceRequestResult asyncRequest(final long baseOffset, final RuntimeException error, final long timeout) {
        final ProduceRequestResult request = new ProduceRequestResult(topicPartition);
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(timeout);
                if (error == null) {
                    request.set(baseOffset, RecordBatch.NO_TIMESTAMP, null);
                } else {
                    request.set(-1L, RecordBatch.NO_TIMESTAMP, index -> error);
                }

                request.done();
            } catch (InterruptedException e) { }
        });
        thread.start();
        return request;
    }
Test that an asynchronous request will eventually return the right offset
clients/src/test/java/org/apache/kafka/clients/producer/RecordSendTest.java