Github user dibbhatt commented on a diff in the pull request:
https://github.com/apache/spark/pull/3798#discussion_r24000571
--- Diff:
external/kafka/src/test/scala/org/apache/spark/streaming/kafka/KafkaClusterSuite.scala
---
@@ -0,0 +1,73 @@
+/*
+ * 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.spark.streaming.kafka
+
+import scala.util.Random
+
+import org.scalatest.BeforeAndAfter
+import kafka.common.TopicAndPartition
+
+class KafkaClusterSuite extends KafkaStreamSuiteBase with BeforeAndAfter {
+ val brokerHost = "localhost"
+
+ val kafkaParams = Map("metadata.broker.list" ->
s"$brokerHost:$brokerPort")
+
+ val kc = new KafkaCluster(kafkaParams)
+
+ val topic = "kcsuitetopic" + Random.nextInt(10000)
+
+ val topicAndPartition = TopicAndPartition(topic, 0)
+
+ before {
+ setupKafka()
+ createTopic(topic)
+ produceAndSendMessage(topic, Map("a" -> 1))
+ }
+
+ after {
+ tearDownKafka()
+ }
+
+ test("metadata apis") {
+ val leader = kc.findLeaders(Set(topicAndPartition)).right.get
+ assert(leader(topicAndPartition) === (brokerHost, brokerPort), "didn't
get leader")
+
+ val parts = kc.getPartitions(Set(topic)).right.get
+ assert(parts(topicAndPartition), "didn't get partitions")
+ }
+
+ test("leader offset apis") {
+ val earliest =
kc.getEarliestLeaderOffsets(Set(topicAndPartition)).right.get
+ assert(earliest(topicAndPartition).offset === 0, "didn't get earliest")
+
+ val latest =
kc.getLatestLeaderOffsets(Set(topicAndPartition)).right.get
+ assert(latest(topicAndPartition).offset === 1, "didn't get latest")
+ }
+
+ test("consumer offset apis") {
+ val group = "kcsuitegroup" + Random.nextInt(10000)
+
+ val offset = Random.nextInt(10000)
+
+ val set = kc.setConsumerOffsets(group, Map(topicAndPartition ->
offset))
+ assert(set.isRight, "didn't set consumer offsets")
+
--- End diff --
Is this a reliable way to get the Next range offset for topic partitions ?
You are explicitly not using any External Store for storing Consumed offset,
but this getConsumerOffset internally stores consumer group offset in ZK which
is controlled by Kafka Consumer Coordinator. Will there be no possibility that
this offset can go out of sync with the offset which was checkpointed ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]