Hi Neha, I am sorry about the design of this program, but what I am trying to do is to expose API to read and write from Kafka. I have some unit test cases as given below. The problem is that the first test case passes but the second test case fails saying that : org.junit.ComparisonFailure: expected:<Hi there[123]!> but was:<Hi there[]!>
import java.util.Iterator; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; public class KafkaManagerTest { private static final String TOPIC = "testTopic"; private static Iterator iter; private static KafkaManager kafkaManager = new KafkaManager(); @BeforeClass public static void setupOnce() { iter = kafkaManager.fetchIterator(TOPIC); } @Test public void testSendAndReceiveMessage1() { String message = "Hi there!"; kafkaManager.publish(TOPIC, message); String messageFromTopic = null; do { } while((messageFromTopic = kafkaManager.fetchNextMessage(TOPIC, iter)) == null); Assert.assertEquals(message,messageFromTopic); } @Test public void testSendAndReceiveMessage2() { String message = "Hi there123!"; kafkaManager.publish(TOPIC, message); String messageFromTopic = null; do { } while((messageFromTopic = kafkaManager.fetchNextMessage(TOPIC, iter)) == null); Assert.assertEquals(message,messageFromTopic); } } Could you please help me out with why this unit test would fail. I have the following line while creating ConsumerConfig: props.put("auto.offset.reset", "largest"); Is there something else I need to do to always get the latest message always? Regards, Kishore