Github user koeninger commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3798#discussion_r24020938
  
    --- 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 --
    
    I'm not sure exactly what the question here is, but this test is just 
verifying that the consumer offset apis work.  They aren't publicly exposed, so 
the question of how people might misuse them is somewhat premature.
    
    That being said, the reason you'd typically want to use this api would be 
for interop with existing kafka monitoring tools that expect offsets in ZK


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

Reply via email to