Source:
public void testTimeStampStrategyWhenTopologyIsRedeployed() { long preRestartEmittedOffset = 20; int preRestartEmittedRecords = 10; long timeStampStartOffset = 2L; long pollTimeout = 1L; KafkaTridentSpoutBatchMetadata preExecutorRestartLastMeta = new KafkaTridentSpoutBatchMetadata(preRestartEmittedOffset, preRestartEmittedOffset + preRestartEmittedRecords - 1, "Some older topology"); Consumer kafkaConsumer = Mockito.mock(Consumer.class); when(kafkaConsumer.assignment()).thenReturn(Collections.singleton(partition)); OffsetAndTimestamp offsetAndTimestamp = new OffsetAndTimestamp(timeStampStartOffset, startTimeStamp); HashedMap map = new HashedMap(); map.put(partition,offsetAndTimestamp); when(kafkaConsumer.offsetsForTimes(Collections.singletonMap(partition, startTimeStamp))).thenReturn(map); HashedMap topicPartitionMap = new HashedMap(); List<ConsumerRecord<String, String>> newRecords = SpoutWithMockedConsumerSetupHelper.createRecords(partition, timeStampStartOffset, recordsInKafka); topicPartitionMap.put(partition,newRecords); when(kafkaConsumer.poll(pollTimeout)).thenReturn(new ConsumerRecords<String,String>(topicPartitionMap)); KafkaTridentSpoutEmitter<String, String> emitter = createEmitter(kafkaConsumer, FirstPollOffsetStrategy.TIMESTAMP); TransactionAttempt txid = new TransactionAttempt(0L, 0); KafkaTridentSpoutTopicPartition kttp = new KafkaTridentSpoutTopicPartition(partition); Map<String, Object> meta = emitter.emitPartitionBatchNew(txid, collectorMock, kttp, preExecutorRestartLastMeta.toMap()); verify(collectorMock, times(recordsInKafka)).emit(emitCaptor.capture()); List<List<Object>> emits = emitCaptor.getAllValues(); assertThat(emits.get(0).get(0), is(timeStampStartOffset)); KafkaTridentSpoutBatchMetadata deserializedMeta = KafkaTridentSpoutBatchMetadata.fromMap(meta); assertThat("The batch should start at the first offset for startTimestamp", deserializedMeta.getFirstOffset(), is(timeStampStartOffset)); }

Target:
public void testTimeStampStrategyWhenTopologyIsRedeployed() { long preRestartEmittedOffset = 20; int preRestartEmittedRecords = 10; long timeStampStartOffset = 2L; long pollTimeout = 1L; KafkaTridentSpoutBatchMetadata preExecutorRestartLastMeta = new KafkaTridentSpoutBatchMetadata(preRestartEmittedOffset, preRestartEmittedOffset + preRestartEmittedRecords - 1, "Some older topology"); KafkaConsumer<String, String> kafkaConsumer = Mockito.mock(KafkaConsumer.class); when(kafkaConsumer.assignment()).thenReturn(Collections.singleton(partition)); OffsetAndTimestamp offsetAndTimestamp = new OffsetAndTimestamp(timeStampStartOffset, startTimeStamp); HashMap<TopicPartition, OffsetAndTimestamp> map = new HashMap<>(); map.put(partition, offsetAndTimestamp); when(kafkaConsumer.offsetsForTimes(Collections.singletonMap(partition, startTimeStamp))).thenReturn(map); HashMap<TopicPartition, List<ConsumerRecord<String, String>>> topicPartitionMap = new HashMap<>(); List<ConsumerRecord<String, String>> newRecords = SpoutWithMockedConsumerSetupHelper.createRecords(partition, timeStampStartOffset, recordsInKafka); topicPartitionMap.put(partition, newRecords); when(kafkaConsumer.poll(pollTimeout)).thenReturn(new ConsumerRecords<>(topicPartitionMap)); KafkaTridentSpoutEmitter<String, String> emitter = createEmitter(kafkaConsumer, FirstPollOffsetStrategy.TIMESTAMP); TransactionAttempt txid = new TransactionAttempt(0L, 0); KafkaTridentSpoutTopicPartition kttp = new KafkaTridentSpoutTopicPartition(partition); Map<String, Object> meta = emitter.emitPartitionBatchNew(txid, collectorMock, kttp, preExecutorRestartLastMeta.toMap()); verify(collectorMock, times(recordsInKafka)).emit(emitCaptor.capture()); verify(kafkaConsumer, times(1)).seek(partition, timeStampStartOffset); List<List<Object>> emits = emitCaptor.getAllValues(); assertThat(emits.get(0).get(0), is(timeStampStartOffset)); KafkaTridentSpoutBatchMetadata deserializedMeta = KafkaTridentSpoutBatchMetadata.fromMap(meta); assertThat("The batch should start at the first offset for startTimestamp", deserializedMeta.getFirstOffset(), is(timeStampStartOffset)); }