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

    https://github.com/apache/spark/pull/4957#discussion_r26092828
  
    --- Diff: 
streaming/src/test/scala/org/apache/spark/streaming/ReceiverSuite.scala ---
    @@ -161,50 +161,27 @@ class ReceiverSuite extends TestSuiteBase with 
Timeouts with Serializable {
         val maxRate = 100
         val conf = new SparkConf().set("spark.streaming.blockInterval", 
blockInterval.toString).
           set("spark.streaming.receiver.maxRate", maxRate.toString)
    -    val blockGenerator = new BlockGenerator(blockGeneratorListener, 1, 
conf)
         val expectedBlocks = 20
         val waitTime = expectedBlocks * blockInterval
         val expectedMessages = maxRate * waitTime / 1000
    -    val expectedMessagesPerBlock = maxRate * blockInterval / 1000
    -    val generatedData = new ArrayBuffer[Int]
    +    val generatedData = 0 until expectedMessages
     
         // Generate blocks
         val startTime = System.currentTimeMillis()
    +    val blockGenerator = new BlockGenerator(blockGeneratorListener, 1, 
conf)
         blockGenerator.start()
    -    var count = 0
    -    while(System.currentTimeMillis - startTime < waitTime) {
    -      blockGenerator.addData(count)
    -      generatedData += count
    -      count += 1
    -      Thread.sleep(1)
    -    }
    +    generatedData.foreach(blockGenerator.addData(_))
         blockGenerator.stop()
    +    val endTime = System.currentTimeMillis()
     
    +    // should have been rate limited
    +    assert(endTime - startTime >= waitTime, "Should have taken longer than 
the theoretical minimum time")
    +
    +    // we should get the same data
         val recordedBlocks = blockGeneratorListener.arrayBuffers
         val recordedData = recordedBlocks.flatten
         assert(blockGeneratorListener.arrayBuffers.size > 0, "No blocks 
received")
         assert(recordedData.toSet === generatedData.toSet, "Received data not 
same")
    -
    --- End diff --
    
    I had added these test to make sure each block generated gets around 
expected number of messages. Ultimately that is the goal of the rate limiter in 
the block generator, the block to not contains more than the expected number of 
messages. 


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