diff options
author | Tiark Rompf <tiark.rompf@epfl.ch> | 2010-03-16 21:53:07 +0000 |
---|---|---|
committer | Tiark Rompf <tiark.rompf@epfl.ch> | 2010-03-16 21:53:07 +0000 |
commit | 704aa0362f48c26f3cf0b166d3a64c75f5387e8b (patch) | |
tree | ce87eb20fd7385c97a18f405fc36e815c441cd9f /test/files/run/t2417.scala | |
parent | 5ea6fc6807c84234e197116026a07ab49a581db9 (diff) | |
download | scala-704aa0362f48c26f3cf0b166d3a64c75f5387e8b.tar.gz scala-704aa0362f48c26f3cf0b166d3a64c75f5387e8b.tar.bz2 scala-704aa0362f48c26f3cf0b166d3a64c75f5387e8b.zip |
added test case for #2417. no review
Diffstat (limited to 'test/files/run/t2417.scala')
-rw-r--r-- | test/files/run/t2417.scala | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/files/run/t2417.scala b/test/files/run/t2417.scala new file mode 100644 index 0000000000..31d4c143fa --- /dev/null +++ b/test/files/run/t2417.scala @@ -0,0 +1,77 @@ +// #2417 +object Test { + + def parallel(numThreads: Int)(block: => Unit) { + var failure: Throwable = null + val threads = Array.fromFunction(i => new Thread { + override def run { + try { + block + } catch { + case x => failure = x + } + } + })(numThreads) + for (t <- threads) t.start + for (t <- threads) t.join + if (failure != null) println("FAILURE: " + failure) + } + + def testSet(initialSize: Int, numThreads: Int, passes: Int) { + val orig = Set.empty ++ (1 to initialSize) + parallel(numThreads) { + for (pass <- 0 until passes) { + var s = orig + for (e <- (initialSize to 1 by -1)) { + s -= e + val obs = s.size + if (obs != e - 1) { + throw new Exception("removed e=" + e + ", size was " + obs + ", s=" + s) + } + } + } + } + } + + def testMap(initialSize: Int, numThreads: Int, passes: Int) { + val orig = Map.empty ++ ((1 to initialSize) map ((_,"v"))) + parallel(numThreads) { + for (pass <- 0 until passes) { + var m = orig + for (e <- (initialSize to 1 by -1)) { + m -= e + val obs = m.size + if (obs != e - 1) { + throw new Exception("removed e=" + e + ", size was " + obs + ", m=" + m) + } + } + } + } + } + + def main(args: Array[String]) { + println("testing small Map that doesn't promote to HashMap...") + testMap(4, 2, 1000000) + println() + + println("testing single-threaded HashMap use...") + testMap(5, 1, 1000000) + println() + + println("testing HashMap.size from multiple threads...") + testMap(5, 2, 1000000) + println() + + println("testing small Set that doesn't promote to HashSet...") + testSet(4, 2, 1000000) + println() + + println("testing single-threaded HashSet use...") + testSet(5, 1, 1000000) + println() + + println("testing HashSet.size from multiple threads...") + testSet(5, 2, 1000000) + println() + } +}
\ No newline at end of file |