akshat0395 commented on code in PR #4540:
URL: https://github.com/apache/hive/pull/4540#discussion_r1299811410


##########
kafka-handler/src/test/org/apache/hadoop/hive/kafka/KafkaStorageHandlerInfoTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.hadoop.hive.kafka;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class KafkaStorageHandlerInfoTest {
+    private static final Logger LOG = 
LoggerFactory.getLogger(KafkaStorageHandlerInfo.class);
+
+    private static final int RECORD_NUMBER = 17384;
+    private static final String TOPIC = "TEST1";
+    private static final byte[] KEY_BYTES = 
"KEY".getBytes(Charset.forName("UTF-8"));
+    private static final KafkaBrokerResource KAFKA_BROKER_RESOURCE = new 
KafkaBrokerResource();
+    private static final List<ConsumerRecord<byte[], byte[]>> RECORDS = 
getRecords(TOPIC);
+
+    private static List<ConsumerRecord<byte[], byte[]>> getRecords(String 
topic) {
+        return IntStream.range(0, RECORD_NUMBER).mapToObj(number -> {
+            final byte[] value = ("VALUE-" + 
Integer.toString(number)).getBytes(Charset.forName("UTF-8"));
+            return new ConsumerRecord<>(topic, 0, (long) number, 0L, null, 0L, 
0, 0, KEY_BYTES, value);
+        }).collect(Collectors.toList());
+    }
+    private final Configuration conf = new Configuration();
+    private KafkaConsumer<byte[], byte[]> consumer;
+
+    private Properties consumerProps;
+    private static KafkaProducer<byte[], byte[]> producer;
+
+    private static final String RESULT = "Partition(topic = TEST1, partition = 
0, leader = 0, replicas = [0], isr = [0], offlineReplicas = []) [start offset = 
[0], end offset = [17384]]";

Review Comment:
   can we use RECORD_NUMBER in the end offset? this will ensure that this 
result string will be accurate in case the value of RECORD_NUMBER changes, and 
test doesnt start failing



##########
kafka-handler/src/test/org/apache/hadoop/hive/kafka/KafkaStorageHandlerInfoTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.hadoop.hive.kafka;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class KafkaStorageHandlerInfoTest {
+    private static final Logger LOG = 
LoggerFactory.getLogger(KafkaStorageHandlerInfo.class);
+
+    private static final int RECORD_NUMBER = 17384;
+    private static final String TOPIC = "TEST1";
+    private static final byte[] KEY_BYTES = 
"KEY".getBytes(Charset.forName("UTF-8"));
+    private static final KafkaBrokerResource KAFKA_BROKER_RESOURCE = new 
KafkaBrokerResource();
+    private static final List<ConsumerRecord<byte[], byte[]>> RECORDS = 
getRecords(TOPIC);
+
+    private static List<ConsumerRecord<byte[], byte[]>> getRecords(String 
topic) {
+        return IntStream.range(0, RECORD_NUMBER).mapToObj(number -> {
+            final byte[] value = ("VALUE-" + 
Integer.toString(number)).getBytes(Charset.forName("UTF-8"));
+            return new ConsumerRecord<>(topic, 0, (long) number, 0L, null, 0L, 
0, 0, KEY_BYTES, value);
+        }).collect(Collectors.toList());
+    }
+    private final Configuration conf = new Configuration();
+    private KafkaConsumer<byte[], byte[]> consumer;
+
+    private Properties consumerProps;
+    private static KafkaProducer<byte[], byte[]> producer;
+
+    private static final String RESULT = "Partition(topic = TEST1, partition = 
0, leader = 0, replicas = [0], isr = [0], offlineReplicas = []) [start offset = 
[0], end offset = [17384]]";
+
+    @BeforeClass
+    public static void setupCluster() throws Throwable {
+        KAFKA_BROKER_RESOURCE.before();
+        sendData();
+    }
+
+    @AfterClass
+    public static void tearDownCluster() {
+        KAFKA_BROKER_RESOURCE.deleteTopic(TOPIC);
+        KAFKA_BROKER_RESOURCE.after();
+    }
+
+    @Before
+    public void setUp() {
+        LOG.info("setting up Config");
+        setupConsumer();
+    }
+
+    @After
+    public void tearDown() {
+        consumer.close();
+        LOG.info("tearDown");
+    }
+
+    private void setupConsumer() {
+        
this.conf.set(KafkaTableProperties.HIVE_KAFKA_BOOTSTRAP_SERVERS.getName(), 
KafkaBrokerResource.BROKER_IP_PORT);
+        consumerProps = new Properties();
+        consumerProps.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, 
"false");
+        consumerProps.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, 
"none");
+        consumerProps.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, 
KafkaBrokerResource.BROKER_IP_PORT);
+        
consumerProps.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, 
ByteArrayDeserializer.class.getName());
+        
consumerProps.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, 
ByteArrayDeserializer.class.getName());
+        consumerProps.setProperty(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, 
"3002");

Review Comment:
   Can we add a comment here, explaining the reasoning behind values even if 
they are random, adding a comment will help modify it in future if needed.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to