diff options
author | Ryan LeCompte <lecompte@gmail.com> | 2013-01-11 23:48:07 -0800 |
---|---|---|
committer | Ryan LeCompte <lecompte@gmail.com> | 2013-01-11 23:48:07 -0800 |
commit | 0cfea7a2ec467717fbe110f9b15163bea2719575 (patch) | |
tree | 1b01802837901461cb615022dbfac625f0f7da4e /core | |
parent | ff10b3aa0970cc7224adc6bc73d99a7ffa30219f (diff) | |
download | spark-0cfea7a2ec467717fbe110f9b15163bea2719575.tar.gz spark-0cfea7a2ec467717fbe110f9b15163bea2719575.tar.bz2 spark-0cfea7a2ec467717fbe110f9b15163bea2719575.zip |
add unit test
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/spark/util/RateLimitedOutputStream.scala | 2 | ||||
-rw-r--r-- | core/src/test/scala/spark/util/RateLimitedOutputStreamSuite.scala | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/core/src/main/scala/spark/util/RateLimitedOutputStream.scala b/core/src/main/scala/spark/util/RateLimitedOutputStream.scala index ed459c2544..16db7549b2 100644 --- a/core/src/main/scala/spark/util/RateLimitedOutputStream.scala +++ b/core/src/main/scala/spark/util/RateLimitedOutputStream.scala @@ -31,7 +31,7 @@ class RateLimitedOutputStream(out: OutputStream, bytesPerSec: Int) extends Outpu def waitToWrite(numBytes: Int) { while (true) { val now = System.nanoTime - val elapsedSecs = SECONDS.convert(max(now - lastSyncTime, 1), NANOSECONDS) + val elapsedSecs = SECONDS.convert(math.max(now - lastSyncTime, 1), NANOSECONDS) val rate = bytesWrittenSinceSync.toDouble / elapsedSecs if (rate < bytesPerSec) { // It's okay to write; just update some variables and return diff --git a/core/src/test/scala/spark/util/RateLimitedOutputStreamSuite.scala b/core/src/test/scala/spark/util/RateLimitedOutputStreamSuite.scala new file mode 100644 index 0000000000..1dc45e0433 --- /dev/null +++ b/core/src/test/scala/spark/util/RateLimitedOutputStreamSuite.scala @@ -0,0 +1,22 @@ +package spark.util + +import org.scalatest.FunSuite +import java.io.ByteArrayOutputStream +import java.util.concurrent.TimeUnit._ + +class RateLimitedOutputStreamSuite extends FunSuite { + + private def benchmark[U](f: => U): Long = { + val start = System.nanoTime + f + System.nanoTime - start + } + + test("write") { + val underlying = new ByteArrayOutputStream + val data = "X" * 1000 + val stream = new RateLimitedOutputStream(underlying, 100) + val elapsedNs = benchmark { stream.write(data.getBytes("UTF-8")) } + assert(SECONDS.convert(elapsedNs, NANOSECONDS) == 4) + } +} |