Program: 37690
Project: 37690
Buggy source:
/** 
 * This tests what happens if we ask to consume from an offset that is invalid (does not exist). Here's what we setup: 2 partitions, produce 4 messages into each. Start a consumer, asking to start at: offset 2 for partition 1, (recorded completed offset = 1) offset 21 for partition 2. (recorded completed offset = 20) Offset 20 does not exist for partition 2, this will raise an exception which by the underlying kafka consumer.  This exception should be handled internally resetting the offset on partition 2 to the earliest available (which happens to be 0). We then consume and expect to receive messages: partition 0 -> messages 2,3      (because we started at offset 2) partition 1 -> messages 0,1,2,3  (because we got reset to earliest) This test also validates that for non-reset partitions, that it does not lose any messages.
 */
@Test public void testWhatHappensIfOffsetIsInvalidShouldResetSmallest(){
  this.topicName="String_Node_Str";
  final int numberOfPartitions=2;
  final int numberOfMsgsPerPartition=4;
  final int numberOfExpectedMessages=6;
  final long partition0StartingOffset=1L;
  final long partition1StartingOffset=20L;
  kafkaTestServer.createTopic(topicName,numberOfPartitions);
  final TopicPartition expectedTopicPartition0=new TopicPartition(topicName,0);
  final TopicPartition expectedTopicPartition1=new TopicPartition(topicName,1);
  produceRecords(numberOfMsgsPerPartition,0);
  produceRecords(numberOfMsgsPerPartition,1);
  SidelineConsumerConfig config=getDefaultSidelineConsumerConfig(topicName);
  config.setKafkaConsumerProperty("String_Node_Str","String_Node_Str");
  PersistenceManager persistenceManager=new InMemoryPersistenceManager();
  persistenceManager.open(Maps.newHashMap());
  ConsumerState startingState=new ConsumerState();
  startingState.setOffset(expectedTopicPartition0,partition0StartingOffset);
  startingState.setOffset(expectedTopicPartition1,partition1StartingOffset);
  SidelineConsumer sidelineConsumer=new SidelineConsumer(config,persistenceManager);
  sidelineConsumer.open(startingState);
  final Set<String> expectedValues=Sets.newHashSet("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  List<ConsumerRecord> records=Lists.newArrayList();
  ConsumerRecord consumerRecord;
  do {
    consumerRecord=sidelineConsumer.nextRecord();
    if (consumerRecord != null) {
      logger.info("String_Node_Str",consumerRecord.offset(),consumerRecord.partition());
      records.add(consumerRecord);
      expectedValues.remove("String_Node_Str" + consumerRecord.partition() + "String_Node_Str"+ consumerRecord.offset());
    }
  }
 while (consumerRecord != null);
  logger.info("String_Node_Str",records.size());
  assertEquals("String_Node_Str",numberOfExpectedMessages,records.size());
  assertTrue("String_Node_Str",expectedValues.isEmpty());
  for (int x=0; x < 2; x++) {
    assertNull("String_Node_Str",sidelineConsumer.nextRecord());
  }
}

Fixed version (ground truth):
/** 
 * This tests what happens if we ask to consume from an offset that is invalid (does not exist). Here's what we setup: 2 partitions, produce 4 messages into each. Start a consumer, asking to start at: offset 2 for partition 1, (recorded completed offset = 1) offset 21 for partition 2. (recorded completed offset = 20) Offset 20 does not exist for partition 2, this will raise an exception which by the underlying kafka consumer.  This exception should be handled internally resetting the offset on partition 2 to the earliest available (which happens to be 0). We then consume and expect to receive messages: partition 0 -> messages 2,3      (because we started at offset 2) partition 1 -> messages 0,1,2,3  (because we got reset to earliest) This test also validates that for non-reset partitions, that it does not lose any messages.
 */
@Test public void testWhatHappensIfOffsetIsInvalidShouldResetSmallest(){
  this.topicName="String_Node_Str";
  final int numberOfPartitions=2;
  final int numberOfMsgsPerPartition=4;
  final int numberOfExpectedMessages=6;
  final long partition0StartingOffset=1L;
  final long partition1StartingOffset=20L;
  kafkaTestServer.createTopic(topicName,numberOfPartitions);
  final TopicPartition expectedTopicPartition0=new TopicPartition(topicName,0);
  final TopicPartition expectedTopicPartition1=new TopicPartition(topicName,1);
  produceRecords(numberOfMsgsPerPartition,0);
  produceRecords(numberOfMsgsPerPartition,1);
  SidelineConsumerConfig config=getDefaultSidelineConsumerConfig(topicName);
  PersistenceManager persistenceManager=new InMemoryPersistenceManager();
  persistenceManager.open(Maps.newHashMap());
  ConsumerState startingState=new ConsumerState();
  startingState.setOffset(expectedTopicPartition0,partition0StartingOffset);
  startingState.setOffset(expectedTopicPartition1,partition1StartingOffset);
  SidelineConsumer sidelineConsumer=new SidelineConsumer(config,persistenceManager);
  sidelineConsumer.open(startingState);
  final Set<String> expectedValues=Sets.newHashSet("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  List<ConsumerRecord> records=Lists.newArrayList();
  ConsumerRecord consumerRecord;
  do {
    consumerRecord=sidelineConsumer.nextRecord();
    if (consumerRecord != null) {
      logger.info("String_Node_Str",consumerRecord.offset(),consumerRecord.partition());
      records.add(consumerRecord);
      expectedValues.remove("String_Node_Str" + consumerRecord.partition() + "String_Node_Str"+ consumerRecord.offset());
    }
  }
 while (consumerRecord != null);
  logger.info("String_Node_Str",records.size());
  assertEquals("String_Node_Str",numberOfExpectedMessages,records.size());
  assertTrue("String_Node_Str",expectedValues.isEmpty());
  for (int x=0; x < 2; x++) {
    assertNull("String_Node_Str",sidelineConsumer.nextRecord());
  }
}