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

    https://github.com/apache/spark/pull/4537#discussion_r29532960
  
    --- Diff: 
external/kafka/src/main/scala/org/apache/spark/streaming/kafka/KafkaTestUtils.scala
 ---
    @@ -227,10 +229,34 @@ private class KafkaTestUtils extends Logging {
         tryAgain(1)
       }
     
    +  /** wait until the leader offset for the given topic/partition equals 
the specified offset */
    +  def waitUntilLeaderOffset(
    +      topic: String,
    +      partition: Int,
    +      offset: Long): Unit = {
    +    eventually(Time(10000), Time(100)) {
    +      val kc = new KafkaCluster(Map("metadata.broker.list" -> 
brokerAddress))
    +      val tp = TopicAndPartition(topic, partition)
    +      val llo = 
kc.getLatestLeaderOffsets(Set(tp)).right.get.apply(tp).offset
    +      assert(
    +        llo == offset,
    +        s"$topic $partition $offset not reached after timeout")
    +    }
    +  }
    +
       private def waitUntilMetadataIsPropagated(topic: String, partition: 
Int): Unit = {
         eventually(Time(10000), Time(100)) {
           assert(
    -        server.apis.metadataCache.containsTopicAndPartition(topic, 
partition),
    +        server.apis.metadataCache.getPartitionInfo(topic, partition) match 
{
    --- End diff --
    
    Could you put this big piece of code in a separate `def` (can be inside 
`waitUntilMetadata..`) outside the eventually, and then the assert just calls 
that function? Much easier to read.


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