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

    https://github.com/apache/spark/pull/7471#discussion_r35045430
  
    --- Diff: 
streaming/src/test/scala/org/apache/spark/streaming/receiver/RateLimiterSuite.scala
 ---
    @@ -0,0 +1,154 @@
    +/*
    + * 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.receiver
    +
    +import scala.collection.mutable.ArrayBuffer
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.SparkFunSuite
    +import org.apache.spark.streaming.StreamingContext
    +import org.apache.spark.streaming.FakeBlockGeneratorListener
    +
    +/** Testsuite for testing the network receiver behavior */
    +class RateLimiterSuite extends SparkFunSuite {
    +
    +  test("rate limiter initializes even without a maxRate set") {
    +    val conf = new SparkConf()
    +    val rateLimiter = new RateLimiter(conf){}
    +    rateLimiter.updateRate(105)
    +    assert(rateLimiter.getCurrentLimit == 105)
    +  }
    +
    +  test("rate limiter updates when below maxRate") {
    +    val conf = new SparkConf().set("spark.streaming.receiver.maxRate", 
"110")
    +    val rateLimiter = new RateLimiter(conf){}
    +    rateLimiter.updateRate(105)
    +    assert(rateLimiter.getCurrentLimit == 105)
    +  }
    +
    +  test("rate limiter stays below maxRate despite large updates") {
    +    val conf = new SparkConf().set("spark.streaming.receiver.maxRate", 
"100")
    +    val rateLimiter = new RateLimiter(conf){}
    +    rateLimiter.updateRate(105)
    +    assert(rateLimiter.getCurrentLimit === 100)
    +  }
    +
    +  def setupGenerator(blockInterval: Int): (BlockGenerator, 
FakeBlockGeneratorListener) = {
    +    val blockGeneratorListener = new FakeBlockGeneratorListener
    +    val conf = new SparkConf().set("spark.streaming.blockInterval", 
s"${blockInterval}ms")
    +    val blockGenerator = new BlockGenerator(blockGeneratorListener, 1, 
conf)
    +    (blockGenerator, blockGeneratorListener)
    +  }
    +
    +  test("throttling block generator") {
    --- End diff --
    
    This is a good attempt, but this is not the right attempt. This is a 
RateLimiterSuite, so ideally it should not be using something like a 
BlockGenerator to test the RateLimiter. So I would update the first three tests 
("rate limiter **") to use a dummy rate limiter tester, that tests the upper 
limit that has been set, before and after any rate update has been made. The 
tester can be a simple integer increment. Note that only the upper limit needs 
to be tested, unlike the flaky block generator tests which test for both upper 
and lower limit. 


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