title: Clear kafka topics for unit testing
body: <p>I need to perform unit testing on a kafka application avoiding third-party libraries.</p>
  
  <p>My problem right now is that I would like to clear all the topics between tests but I don't know how.</p>
  
  <p>This is my temporary solution: commit every message produced after each test and put all test consumers in the same consumer group.</p>
  
  <pre><code>override protected def afterEach():Unit={
      val cleanerConsumer= newConsumer(Seq.empty)
      val topics=cleanerConsumer.listTopics()
      println("pulisco")
      cleanerConsumer.subscribe(topics.keySet())
      cleanerConsumer.poll(100)
      cleanerConsumer.commitSync()
      cleanerConsumer.close()
  }
  </code></pre>
  
  <p>This doesn't work though and I don't know why.</p>
  
  <p>For example, when I create a new consumer inside a test, <code>messages</code> contains the messages produced in the previous test.</p>
  
  <pre><code>val consumerProbe = newConsumer(SMSGatewayTopic)
  
  val messages = consumerProbe.poll(1000)
  </code></pre>
  
  <p>How can I solve this?</p>