janithkv commented on a change in pull request #2911: STORM-2720 : Add
TIMESTAMP option for FirstPollOffset for Kafka Trident spout
URL: https://github.com/apache/storm/pull/2911#discussion_r282384457
##########
File path:
external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/trident/KafkaTridentSpoutEmitterEmitTest.java
##########
@@ -303,4 +315,38 @@ public void testLatestStrategyWhenTopologyIsRedeployed() {
verify(collectorMock, never()).emit(anyList());
}
+ @Test
+ public void testTimeStampStrategyWhenTopologyIsRedeployed() {
+ /**
+ * TIMESTAMP strategy should be applied if the emitter is new and the
topology has been redeployed (storm id has changed)
+ * Offset should be reset according to the offset corresponding to
startTimeStamp
+ */
+ 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());
Review comment:
Adding a verify on seek
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services