aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorKaren Feng <karenfeng.us@gmail.com>2013-07-10 13:53:39 -0700
committerKaren Feng <karenfeng.us@gmail.com>2013-07-10 13:53:39 -0700
commit5f8a20b4a8a4cb7e4b14ee989f1b4f83981ce61a (patch)
tree55b1eb4520039feb69d3e997164be6fb68199a1b /core
parent0d4580360ba4bbcd2f73877743d746c071a92e34 (diff)
downloadspark-5f8a20b4a8a4cb7e4b14ee989f1b4f83981ce61a.tar.gz
spark-5f8a20b4a8a4cb7e4b14ee989f1b4f83981ce61a.tar.bz2
spark-5f8a20b4a8a4cb7e4b14ee989f1b4f83981ce61a.zip
Moved unit tests for Utils from UISuite to UtilsSuite
Diffstat (limited to 'core')
-rw-r--r--core/src/test/scala/spark/UtilsSuite.scala71
-rw-r--r--core/src/test/scala/spark/ui/UISuite.scala71
2 files changed, 71 insertions, 71 deletions
diff --git a/core/src/test/scala/spark/UtilsSuite.scala b/core/src/test/scala/spark/UtilsSuite.scala
index 4a113e16bf..73050a1d3b 100644
--- a/core/src/test/scala/spark/UtilsSuite.scala
+++ b/core/src/test/scala/spark/UtilsSuite.scala
@@ -71,5 +71,76 @@ class UtilsSuite extends FunSuite {
assert(Utils.splitCommandString("''") === Seq(""))
assert(Utils.splitCommandString("\"\"") === Seq(""))
}
+
+ test("string formatting of time durations") {
+ val second = 1000
+ val minute = second * 60
+ val hour = minute * 60
+ def str = Utils.msDurationToString(_)
+
+ assert(str(123) === "123 ms")
+ assert(str(second) === "1.0 s")
+ assert(str(second + 462) === "1.5 s")
+ assert(str(hour) === "1.00 h")
+ assert(str(minute) === "1.0 m")
+ assert(str(minute + 4 * second + 34) === "1.1 m")
+ assert(str(10 * hour + minute + 4 * second) === "10.02 h")
+ assert(str(10 * hour + 59 * minute + 59 * second + 999) === "11.00 h")
+ }
+
+ test("reading last n bytes of a file") {
+ val tmpDir = Files.createTempDir()
+
+ // File smaller than limit
+ val f1Path = tmpDir + "/f1"
+ val f1 = new FileOutputStream(f1Path)
+ f1.write("a\nb\nc\nd".getBytes(Charsets.UTF_8))
+ f1.close()
+ assert(Utils.lastNBytes(f1Path, 1024) === "a\nb\nc\nd")
+
+ // File larger than limit
+ val f2Path = tmpDir + "/f2"
+ val f2 = new FileOutputStream(f2Path)
+ f2.write("1\n2\n3\n4\n5\n6\n7\n8\n".getBytes(Charsets.UTF_8))
+ f2.close()
+ assert(Utils.lastNBytes(f2Path, 8) === "5\n6\n7\n8\n")
+
+ // Request limit too
+ val f3Path = tmpDir + "/f2"
+ val f3 = new FileOutputStream(f3Path)
+ f3.write("1\n2\n3\n4\n5\n6\n7\n8\n".getBytes(Charsets.UTF_8))
+ f3.close()
+ assert(Utils.lastNBytes(f3Path, 8) === "5\n6\n7\n8\n")
+
+ FileUtils.deleteDirectory(tmpDir)
+ }
+
+ test("reading offset bytes of a file") {
+ val tmpDir2 = Files.createTempDir()
+ val f1Path = tmpDir2 + "/f1"
+ val f1 = new FileOutputStream(f1Path)
+ f1.write("1\n2\n3\n4\n5\n6\n7\n8\n9\n".getBytes(Charsets.UTF_8))
+ f1.close()
+
+ // Read first few bytes
+ assert(Utils.offsetBytes(f1Path, 0, 5) === "1\n2\n3")
+
+ // Read some middle bytes
+ assert(Utils.offsetBytes(f1Path, 4, 11) === "3\n4\n5\n6")
+
+ // Read last few bytes
+ assert(Utils.offsetBytes(f1Path, 12, 18) === "7\n8\n9\n")
+
+ // Read some nonexistent bytes in the beginning
+ assert(Utils.offsetBytes(f1Path, -5, 5) === "1\n2\n3")
+
+ // Read some nonexistent bytes at the end
+ assert(Utils.offsetBytes(f1Path, 12, 22) === "7\n8\n9\n")
+
+ // Read some nonexistent bytes on both ends
+ assert(Utils.offsetBytes(f1Path, -3, 25) === "1\n2\n3\n4\n5\n6\n7\n8\n9\n")
+
+ FileUtils.deleteDirectory(tmpDir2)
+ }
}
diff --git a/core/src/test/scala/spark/ui/UISuite.scala b/core/src/test/scala/spark/ui/UISuite.scala
index ab174732e3..ef2e9c2ec4 100644
--- a/core/src/test/scala/spark/ui/UISuite.scala
+++ b/core/src/test/scala/spark/ui/UISuite.scala
@@ -31,75 +31,4 @@ class UISuite extends FunSuite {
case Failure (e) =>
}
}
-
- test("string formatting of time durations") {
- val second = 1000
- val minute = second * 60
- val hour = minute * 60
- def str = Utils.msDurationToString(_)
-
- assert(str(123) === "123 ms")
- assert(str(second) === "1.0 s")
- assert(str(second + 462) === "1.5 s")
- assert(str(hour) === "1.00 h")
- assert(str(minute) === "1.0 m")
- assert(str(minute + 4 * second + 34) === "1.1 m")
- assert(str(10 * hour + minute + 4 * second) === "10.02 h")
- assert(str(10 * hour + 59 * minute + 59 * second + 999) === "11.00 h")
- }
-
- test("reading last n bytes of a file") {
- val tmpDir = Files.createTempDir()
-
- // File smaller than limit
- val f1Path = tmpDir + "/f1"
- val f1 = new FileOutputStream(f1Path)
- f1.write("a\nb\nc\nd".getBytes(Charsets.UTF_8))
- f1.close()
- assert(Utils.lastNBytes(f1Path, 1024) === "a\nb\nc\nd")
-
- // File larger than limit
- val f2Path = tmpDir + "/f2"
- val f2 = new FileOutputStream(f2Path)
- f2.write("1\n2\n3\n4\n5\n6\n7\n8\n".getBytes(Charsets.UTF_8))
- f2.close()
- assert(Utils.lastNBytes(f2Path, 8) === "5\n6\n7\n8\n")
-
- // Request limit too
- val f3Path = tmpDir + "/f2"
- val f3 = new FileOutputStream(f3Path)
- f3.write("1\n2\n3\n4\n5\n6\n7\n8\n".getBytes(Charsets.UTF_8))
- f3.close()
- assert(Utils.lastNBytes(f3Path, 8) === "5\n6\n7\n8\n")
-
- FileUtils.deleteDirectory(tmpDir)
- }
-
- test("reading offset bytes of a file") {
- val tmpDir2 = Files.createTempDir()
- val f1Path = tmpDir2 + "/f1"
- val f1 = new FileOutputStream(f1Path)
- f1.write("1\n2\n3\n4\n5\n6\n7\n8\n9\n".getBytes(Charsets.UTF_8))
- f1.close()
-
- // Read first few bytes
- assert(Utils.offsetBytes(f1Path, 0, 5) === "1\n2\n3")
-
- // Read some middle bytes
- assert(Utils.offsetBytes(f1Path, 4, 11) === "3\n4\n5\n6")
-
- // Read last few bytes
- assert(Utils.offsetBytes(f1Path, 12, 18) === "7\n8\n9\n")
-
- // Read some nonexistent bytes in the beginning
- assert(Utils.offsetBytes(f1Path, -5, 5) === "1\n2\n3")
-
- // Read some nonexistent bytes at the end
- assert(Utils.offsetBytes(f1Path, 12, 22) === "7\n8\n9\n")
-
- // Read some nonexistent bytes on both ends
- assert(Utils.offsetBytes(f1Path, -3, 25) === "1\n2\n3\n4\n5\n6\n7\n8\n9\n")
-
- FileUtils.deleteDirectory(tmpDir2)
- }
}