diff options
author | Reynold Xin <rxin@apache.org> | 2014-03-03 21:24:19 -0800 |
---|---|---|
committer | Matei Zaharia <matei@databricks.com> | 2014-03-03 21:24:19 -0800 |
commit | f5ae38af87d4e6f266cb9af6265743c593f77d41 (patch) | |
tree | e77516f0b33ab74e62328cc540a12acd384e4cc7 /streaming/src/test | |
parent | 923dba5096d4f7a96d67e4ee243b3b1085984bb9 (diff) | |
download | spark-f5ae38af87d4e6f266cb9af6265743c593f77d41.tar.gz spark-f5ae38af87d4e6f266cb9af6265743c593f77d41.tar.bz2 spark-f5ae38af87d4e6f266cb9af6265743c593f77d41.zip |
SPARK-1158: Fix flaky RateLimitedOutputStreamSuite.
There was actually a problem with the RateLimitedOutputStream implementation where the first second doesn't write anything because of integer rounding.
So RateLimitedOutputStream was overly aggressive in throttling.
Author: Reynold Xin <rxin@apache.org>
Closes #55 from rxin/ratelimitest and squashes the following commits:
52ce1b7 [Reynold Xin] SPARK-1158: Fix flaky RateLimitedOutputStreamSuite.
Diffstat (limited to 'streaming/src/test')
-rw-r--r-- | streaming/src/test/scala/org/apache/spark/streaming/util/RateLimitedOutputStreamSuite.scala | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/streaming/src/test/scala/org/apache/spark/streaming/util/RateLimitedOutputStreamSuite.scala b/streaming/src/test/scala/org/apache/spark/streaming/util/RateLimitedOutputStreamSuite.scala index e5bf6d70db..7d18a0fcf7 100644 --- a/streaming/src/test/scala/org/apache/spark/streaming/util/RateLimitedOutputStreamSuite.scala +++ b/streaming/src/test/scala/org/apache/spark/streaming/util/RateLimitedOutputStreamSuite.scala @@ -17,10 +17,11 @@ package org.apache.spark.streaming.util -import org.scalatest.FunSuite import java.io.ByteArrayOutputStream import java.util.concurrent.TimeUnit._ +import org.scalatest.FunSuite + class RateLimitedOutputStreamSuite extends FunSuite { private def benchmark[U](f: => U): Long = { @@ -29,12 +30,14 @@ class RateLimitedOutputStreamSuite extends FunSuite { System.nanoTime - start } - ignore("write") { + test("write") { val underlying = new ByteArrayOutputStream val data = "X" * 41000 - val stream = new RateLimitedOutputStream(underlying, 10000) + val stream = new RateLimitedOutputStream(underlying, desiredBytesPerSec = 10000) val elapsedNs = benchmark { stream.write(data.getBytes("UTF-8")) } - assert(SECONDS.convert(elapsedNs, NANOSECONDS) == 4) - assert(underlying.toString("UTF-8") == data) + + // We accept anywhere from 4.0 to 4.99999 seconds since the value is rounded down. + assert(SECONDS.convert(elapsedNs, NANOSECONDS) === 4) + assert(underlying.toString("UTF-8") === data) } } |