Kafka MockConsumer not receiving records
<p>I'm writing against the new kafka consumer API in 0.9 using java interop in clojure. I've had success so far but now I'm trying to write some unit tests with <code>MockConsumer</code> and <code>MockProducer</code>. My test always fails because <code>(first values)</code> is <code>nil</code>. </p>

<p>I don't understand why the consumer isn't seeing any of the messages that the producer is sending to the topic. </p>

<pre><code>(ns blah
  (:require [cheshire.core :as json]
            [clojure.test :refer [is testing deftest]])
  (:import [org.apache.kafka.clients.consumer MockConsumer OffsetResetStrategy]
           [org.apache.kafka.clients.producer MockProducer]
           [org.apache.kafka.common.serialization StringSerializer]
           [org.apache.kafka.clients.consumer KafkaConsumer ConsumerRecords ConsumerRecord]
           [org.apache.kafka.clients.producer KafkaProducer ProducerRecord]
           [java.util ArrayList]))

(defn send-message
  [producer topic value]
  (let [pr (ProducerRecord. topic value)]
    (.send producer pr)))

(defn messages
  "Return seq of messages from consumer."
  ([consumer] (messages consumer 100))
  ([consumer timeout]
   (println "poll consumer for messages")
   (let [records (seq (.poll consumer timeout))]
     (when records
       (map record-&gt;map records)))))

(deftest consuming
  (let [c (MockConsumer. (OffsetResetStrategy/EARLIEST))
        _ (.subscribe c (doto (ArrayList.) (.add "unittest")))
        p (MockProducer. true (StringSerializer.) (StringSerializer.))]
    (send-message p "unittest" (json/generate-string {:a 1 :b "two"}))
    (let [values (seq (messages c))]
      (is (= {:a 1 :b "two"}
          (first values))))
    (.close c)
    (.close p)))
</code></pre>

<p>Any ideas?</p>