[ https://issues.apache.org/jira/browse/GOBBLIN-1040?focusedWorklogId=395728&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-395728 ]
ASF GitHub Bot logged work on GOBBLIN-1040: ------------------------------------------- Author: ASF GitHub Bot Created on: 02/Mar/20 02:42 Start Date: 02/Mar/20 02:42 Worklog Time Spent: 10m Work Description: sv2000 commented on pull request #2900: [GOBBLIN-1040] HighLevelConsumer re-design by removing references to … URL: https://github.com/apache/incubator-gobblin/pull/2900#discussion_r386167110 ########## File path: gobblin-modules/gobblin-kafka-09/src/test/java/org/apache/gobblin/kafka/client/MockBatchKafkaConsumerClient.java ########## @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gobblin.kafka.client; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.kafka.clients.consumer.Consumer; + +import com.google.api.client.util.Lists; +import com.google.common.collect.Iterators; +import com.google.common.collect.Maps; +import com.typesafe.config.Config; + +import org.apache.gobblin.source.extractor.extract.kafka.KafkaOffsetRetrievalFailureException; +import org.apache.gobblin.source.extractor.extract.kafka.KafkaPartition; +import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic; + + +/** + * A Mock Kafka Consumer client that returns an (@link #MockBatchIterator} for a {@link #iteratorBatchSize} + * each time consume called. + * Returns empty iterator if all {@link #records} have been consumed. + */ +public class MockBatchKafkaConsumerClient extends Kafka09ConsumerClient { + + private final List<KafkaConsumerRecord> records; + private int currRecordIdx = 0; + private final int iteratorBatchSize; + + public MockBatchKafkaConsumerClient(Config config, Consumer consumer, List<KafkaConsumerRecord> records, int batchSize) { + super(config, consumer); + this.records = records; + this.iteratorBatchSize = batchSize; + } + + @Override + public List<KafkaTopic> getTopics() { + return Lists.newArrayList(); + } + + @Override + public long getEarliestOffset(KafkaPartition partition) + throws KafkaOffsetRetrievalFailureException { + return 0; + } + + @Override + public long getLatestOffset(KafkaPartition partition) + throws KafkaOffsetRetrievalFailureException { + return 0; + } + + @Override + public Iterator<KafkaConsumerRecord> consume(KafkaPartition partition, long nextOffset, long maxOffset) { + return null; + } + + @Override + public Iterator<KafkaConsumerRecord> consume() { + return consume(iteratorBatchSize); + } + + private Iterator<KafkaConsumerRecord> consume(int batchSize) { + if (currRecordIdx < this.records.size() && batchSize > 0) { + Iterator iterator = new MockBatchIterator(batchSize, records, currRecordIdx); + currRecordIdx+=iteratorBatchSize; Review comment: spaces around "+="? ---------------------------------------------------------------- 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: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 395728) Time Spent: 1h 40m (was: 1.5h) > Fix High level consumer > ------------------------ > > Key: GOBBLIN-1040 > URL: https://issues.apache.org/jira/browse/GOBBLIN-1040 > Project: Apache Gobblin > Issue Type: Improvement > Reporter: Vikram Bohra > Priority: Major > Time Spent: 1h 40m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)