srdo 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_r282134330
 
 

 ##########
 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:
   The test doesn't actually show that TIMESTAMP works currently. You've made 
the consumer return some messages on poll, and now you're validating that those 
messages are returned when the emitter polls. I think the test would pass even 
if TIMESTAMP wasn't implemented properly.
   
   I think a better test would be one of the following:
   * Modify the current test to verify that consumer.seek was called with the 
expected offset before poll was called
   Or
   * Use a partial mock for the consumer, put some real records in Kafka, wait 
a few milliseconds, take a timestamp, put a few more records in Kafka. Start 
the emitter at the stored timestamp, and verify that only the second set of 
messages are received.

----------------------------------------------------------------
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

Reply via email to