Github user dragos commented on a diff in the pull request:
https://github.com/apache/spark/pull/7600#discussion_r35742943
--- Diff:
streaming/src/test/scala/org/apache/spark/streaming/scheduler/RateControllerSuite.scala
---
@@ -0,0 +1,145 @@
+/*
+ * 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.scheduler
+
+import scala.collection.mutable
+import scala.reflect.ClassTag
+import scala.util.control.NonFatal
+
+import org.scalatest.Matchers._
+import org.scalatest.concurrent.Eventually._
+import org.scalatest.time.SpanSugar._
+
+import org.apache.spark.streaming._
+import org.apache.spark.streaming.scheduler.rate.RateEstimator
+
+class RateControllerSuite extends TestSuiteBase {
+
+ override def actuallyWait: Boolean = true
+
+ test("rate controller publishes updates") {
+ val ssc = new StreamingContext(conf, batchDuration)
+ withStreamingContext(ssc) { ssc =>
+ val dstream = new MockRateLimitDStream(ssc, Seq(Seq(1)), 1)
+ val output = new TestOutputStreamWithPartitions(dstream)
+ output.register()
+ runStreams(ssc, 1, 1)
+
+ eventually(timeout(2.seconds)) {
+ assert(dstream.publishCalls === 1)
+ }
+ }
+ }
+
+ test("publish rates reach receivers") {
+ val ssc = new StreamingContext(conf, batchDuration)
+ withStreamingContext(ssc) { ssc =>
+ val dstream = new RateLimitInputDStream(ssc) {
+ override val rateController =
+ Some(new ReceiverRateController(id, new
ConstantEstimator(200.0)))
+ }
+ SingletonDummyReceiver.reset()
+
+ val output = new TestOutputStreamWithPartitions(dstream)
+ output.register()
+ runStreams(ssc, 2, 2)
+
+ eventually(timeout(5.seconds)) {
+ assert(dstream.getCurrentRateLimit === Some(200))
+ }
+ }
+ }
+
+ test("multiple publish rates reach receivers") {
+ val ssc = new StreamingContext(conf, batchDuration)
+ withStreamingContext(ssc) { ssc =>
+ val rates = Seq(100L, 200L, 300L)
+
+ val dstream = new RateLimitInputDStream(ssc) {
+ override val rateController =
+ Some(new ReceiverRateController(id, new
ConstantEstimator(rates.map(_.toDouble): _*)))
+ }
+ SingletonDummyReceiver.reset()
+
+ val output = new TestOutputStreamWithPartitions(dstream)
+ output.register()
+
+ val observedRates = mutable.HashSet.empty[Long]
+
+ @volatile var done = false
+ runInBackground {
+ while (!done) {
+ try {
+ dstream.getCurrentRateLimit.foreach(observedRates += _)
+ } catch {
+ case NonFatal(_) => () // don't stop if the executor wasn't
installed yet
+ }
+ Thread.sleep(20)
--- End diff --
Ok, in the interest of closing this PR I will do the changes you request
ASAP.
However, in the interest of understanding, I ran it 100 times without it
failing once. If you have evidence of it being **SUPER FLAKY** in practice, do
you mind sharing it here?
I guess the reason I'm not seeing these failures is that even if
theoretically the delay could be higher, say 100ms, since the batch interval is
1s, you'd still sample it 10 times. And looking at the implementation of
`SystemClock`, it's still based on `Thread.sleep`, so any systematic delay
(say, system under heavy load) will affect both this test and the batch
interval sampling rate.
BTW, `eventually` is using `Thread.sleep` as well (15ms between attempts,
by default), so I guess the same considerations regarding flakiness should
apply.
---
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]