Program: 37685
Project: 37685
Buggy source:
/** 
 * Verifies that when we call connect that it makes the appropriate calls to ConsumerStateManager to initialize. This test has the ConsumerStateManager (a mock) return ConsumerState. We verify that our internal kafka client then knows to start reading its partition from the previously saved off consumer state returned from ConsumerStateManager.
 */
@Test public void testConnectWithSinglePartitionOnTopicWithStateSaved(){
  final String consumerId="String_Node_Str";
  final long lastCommittedOffset=12345L;
  final long expectedOffsetToStartConsumeFrom=lastCommittedOffset + 1;
  List<String> brokerHosts=Lists.newArrayList(kafkaTestServer.getKafkaServer().serverConfig().advertisedHostName() + "String_Node_Str" + kafkaTestServer.getKafkaServer().serverConfig().advertisedPort());
  final SidelineConsumerConfig config=new SidelineConsumerConfig(brokerHosts,consumerId,topicName);
  config.setKafkaConsumerProperty("String_Node_Str","String_Node_Str");
  KafkaConsumer<byte[],byte[]> mockKafkaConsumer=mock(KafkaConsumer.class);
  List<PartitionInfo> mockPartitionInfos=Lists.newArrayList(new PartitionInfo(topicName,0,new Node(0,"String_Node_Str",9092),new Node[0],new Node[0]));
  when(mockKafkaConsumer.partitionsFor(eq(topicName))).thenReturn(mockPartitionInfos);
  PersistenceManager mockPersistenceManager=mock(PersistenceManager.class);
  ConsumerState consumerState=new ConsumerState();
  consumerState.setOffset(new TopicPartition(topicName,0),lastCommittedOffset);
  when(mockPersistenceManager.retrieveConsumerState(eq(consumerId))).thenReturn(consumerState);
  SidelineConsumer sidelineConsumer=new SidelineConsumer(config,mockPersistenceManager,mockKafkaConsumer);
  sidelineConsumer.open(null);
  verify(mockKafkaConsumer,times(1)).assign(eq(Lists.newArrayList(new TopicPartition(topicName,0))));
  verify(mockKafkaConsumer,never()).seekToBeginning(eq(Lists.newArrayList(new TopicPartition(topicName,0))));
  verify(mockKafkaConsumer,times(1)).seek(eq(new TopicPartition(topicName,0)),eq(expectedOffsetToStartConsumeFrom));
}

Fixed version (ground truth):
/** 
 * Verifies that when we call connect that it makes the appropriate calls to ConsumerStateManager to initialize. This test has the ConsumerStateManager (a mock) return ConsumerState. We verify that our internal kafka client then knows to start reading its partition from the previously saved off consumer state returned from ConsumerStateManager.
 */
@Test public void testConnectWithSinglePartitionOnTopicWithStateSaved(){
  final String consumerId="String_Node_Str";
  final long lastCommittedOffset=12345L;
  final long expectedOffsetToStartConsumeFrom=lastCommittedOffset + 1;
  List<String> brokerHosts=Lists.newArrayList(kafkaTestServer.getKafkaServer().serverConfig().advertisedHostName() + "String_Node_Str" + kafkaTestServer.getKafkaServer().serverConfig().advertisedPort());
  final SidelineConsumerConfig config=new SidelineConsumerConfig(brokerHosts,consumerId,topicName);
  KafkaConsumer<byte[],byte[]> mockKafkaConsumer=mock(KafkaConsumer.class);
  List<PartitionInfo> mockPartitionInfos=Lists.newArrayList(new PartitionInfo(topicName,0,new Node(0,"String_Node_Str",9092),new Node[0],new Node[0]));
  when(mockKafkaConsumer.partitionsFor(eq(topicName))).thenReturn(mockPartitionInfos);
  PersistenceManager mockPersistenceManager=mock(PersistenceManager.class);
  ConsumerState consumerState=new ConsumerState();
  consumerState.setOffset(new TopicPartition(topicName,0),lastCommittedOffset);
  when(mockPersistenceManager.retrieveConsumerState(eq(consumerId))).thenReturn(consumerState);
  SidelineConsumer sidelineConsumer=new SidelineConsumer(config,mockPersistenceManager,mockKafkaConsumer);
  sidelineConsumer.open(null);
  verify(mockKafkaConsumer,times(1)).assign(eq(Lists.newArrayList(new TopicPartition(topicName,0))));
  verify(mockKafkaConsumer,never()).seekToBeginning(eq(Lists.newArrayList(new TopicPartition(topicName,0))));
  verify(mockKafkaConsumer,times(1)).seek(eq(new TopicPartition(topicName,0)),eq(expectedOffsetToStartConsumeFrom));
}