summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Prokopec <axel22@gmail.com>2012-02-03 16:58:54 +0100
committerAleksandar Prokopec <axel22@gmail.com>2012-02-03 16:58:54 +0100
commita015c08fda8b8556345a802d60557a3ecd627ccc (patch)
treefcd177766e7a394116713b3d0464f012f7482f4d
parent86946630e9a1240fb9a378b2ec62e78b521f4320 (diff)
downloadscala-a015c08fda8b8556345a802d60557a3ecd627ccc.tar.gz
scala-a015c08fda8b8556345a802d60557a3ecd627ccc.tar.bz2
scala-a015c08fda8b8556345a802d60557a3ecd627ccc.zip
Add tests for parallel Ctrie.
Changed parameters in some tests to speed them up.
-rw-r--r--src/library/scala/collection/parallel/Combiner.scala1
-rw-r--r--test/files/jvm/serialization.check4
-rw-r--r--test/files/jvm/serialization.scala5
-rw-r--r--test/files/run/ctries/iterator.scala14
-rw-r--r--test/files/scalacheck/avl.scala18
-rw-r--r--test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala98
-rw-r--r--test/files/scalacheck/parallel-collections/pc.scala3
7 files changed, 126 insertions, 17 deletions
diff --git a/src/library/scala/collection/parallel/Combiner.scala b/src/library/scala/collection/parallel/Combiner.scala
index a2cab7eb5d..e304be92ae 100644
--- a/src/library/scala/collection/parallel/Combiner.scala
+++ b/src/library/scala/collection/parallel/Combiner.scala
@@ -34,7 +34,6 @@ import scala.collection.generic.Sizing
*/
trait Combiner[-Elem, +To] extends Builder[Elem, To] with Sizing with Parallel {
//self: EnvironmentPassingCombiner[Elem, To] =>
- private[collection] final val tasksupport = getTaskSupport
/** Combines the contents of the receiver builder and the `other` builder,
* producing a new builder containing both their elements.
diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check
index cdfc100e0d..67b77639a2 100644
--- a/test/files/jvm/serialization.check
+++ b/test/files/jvm/serialization.check
@@ -287,6 +287,10 @@ x = ParHashMap(1 -> 2, 2 -> 4)
y = ParHashMap(1 -> 2, 2 -> 4)
x equals y: true, y equals x: true
+x = ParCtrie(1 -> 2, 2 -> 4)
+y = ParCtrie(1 -> 2, 2 -> 4)
+x equals y: true, y equals x: true
+
x = ParHashSet(1, 2, 3)
y = ParHashSet(1, 2, 3)
x equals y: true, y equals x: true
diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala
index 4e1ff368ab..75daa8903d 100644
--- a/test/files/jvm/serialization.scala
+++ b/test/files/jvm/serialization.scala
@@ -613,6 +613,11 @@ object Test9_parallel {
val _mpm: mutable.ParHashMap[Int, Int] = read(write(mpm))
check(mpm, _mpm)
+ // mutable.ParCtrie
+ val mpc = mutable.ParCtrie(1 -> 2, 2 -> 4)
+ val _mpc: mutable.ParCtrie[Int, Int] = read(write(mpc))
+ check(mpc, _mpc)
+
// mutable.ParHashSet
val mps = mutable.ParHashSet(1, 2, 3)
val _mps: mutable.ParHashSet[Int] = read(write(mps))
diff --git a/test/files/run/ctries/iterator.scala b/test/files/run/ctries/iterator.scala
index 1cef4f66ea..4bbf9009f0 100644
--- a/test/files/run/ctries/iterator.scala
+++ b/test/files/run/ctries/iterator.scala
@@ -141,8 +141,8 @@ object IteratorSpec extends Spec {
"be consistent when taken with concurrent modifications" in {
val sz = 25000
- val W = 25
- val S = 10
+ val W = 15
+ val S = 5
val checks = 5
val ct = new Ctrie[Wrap, Int]
for (i <- 0 until sz) ct.put(new Wrap(i), i)
@@ -182,8 +182,8 @@ object IteratorSpec extends Spec {
"be consistent with a concurrent removal with a well defined order" in {
val sz = 150000
- val sgroupsize = 40
- val sgroupnum = 20
+ val sgroupsize = 10
+ val sgroupnum = 5
val removerslowdown = 50
val ct = new Ctrie[Wrap, Int]
for (i <- 0 until sz) ct.put(new Wrap(i), i)
@@ -201,7 +201,7 @@ object IteratorSpec extends Spec {
def consistentIteration(it: Iterator[(Wrap, Int)]) = {
class Iter extends Thread {
override def run() {
- val elems = it.toSeq
+ val elems = it.toBuffer
if (elems.nonEmpty) {
val minelem = elems.minBy((x: (Wrap, Int)) => x._1.i)._1.i
assert(elems.forall(_._1.i >= minelem))
@@ -224,8 +224,8 @@ object IteratorSpec extends Spec {
"be consistent with a concurrent insertion with a well defined order" in {
val sz = 150000
- val sgroupsize = 30
- val sgroupnum = 30
+ val sgroupsize = 10
+ val sgroupnum = 10
val inserterslowdown = 50
val ct = new Ctrie[Wrap, Int]
diff --git a/test/files/scalacheck/avl.scala b/test/files/scalacheck/avl.scala
index 51fb1fe8c3..af79ad49e3 100644
--- a/test/files/scalacheck/avl.scala
+++ b/test/files/scalacheck/avl.scala
@@ -47,21 +47,21 @@ package scala.collection.mutable {
}
}
- def genInput: Gen[(Int, List[AVLTree[Int]])] = for {
- size <- Gen.choose(20, 25)
- elements <- Gen.listOfN(size, Gen.choose(0, 1000))
- selected <- Gen.choose(0, 1000)
+ def genInput: org.scalacheck.Gen[(Int, List[AVLTree[Int]])] = for {
+ size <- org.scalacheck.Gen.choose(20, 25)
+ elements <- org.scalacheck.Gen.listOfN(size, org.scalacheck.Gen.choose(0, 1000))
+ selected <- org.scalacheck.Gen.choose(0, 1000)
} yield {
// selected mustn't be in elements already
val list = makeAllBalancedTree(elements.sorted.distinct.map(_*2))
(selected*2+1, list)
}
- def genInputDelete: Gen[(Int, List[AVLTree[Int]])] = for {
- size <- Gen.choose(20, 25)
- elements <- Gen.listOfN(size, Gen.choose(0, 1000))
+ def genInputDelete: org.scalacheck.Gen[(Int, List[AVLTree[Int]])] = for {
+ size <- org.scalacheck.Gen.choose(20, 25)
+ elements <- org.scalacheck.Gen.listOfN(size, org.scalacheck.Gen.choose(0, 1000))
e = elements.sorted.distinct
- selected <- Gen.choose(0, e.size-1)
+ selected <- org.scalacheck.Gen.choose(0, e.size-1)
} yield {
// selected must be in elements already
val list = makeAllBalancedTree(e)
@@ -111,4 +111,4 @@ package scala.collection.mutable {
object Test extends Properties("AVL") {
include(scala.collection.mutable.TestInsert)
include(scala.collection.mutable.TestRemove)
-} \ No newline at end of file
+}
diff --git a/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala b/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala
new file mode 100644
index 0000000000..d1924f0ada
--- /dev/null
+++ b/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala
@@ -0,0 +1,98 @@
+package scala.collection.parallel
+package mutable
+
+
+
+import org.scalacheck._
+import org.scalacheck.Gen
+import org.scalacheck.Gen._
+import org.scalacheck.Prop._
+import org.scalacheck.Properties
+import org.scalacheck.Arbitrary._
+
+import scala.collection._
+import scala.collection.parallel.ops._
+
+
+
+abstract class ParallelCtrieCheck[K, V](tp: String) extends ParallelMapCheck[K, V]("mutable.ParCtrie[" + tp + "]") {
+ // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2)
+ // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2)
+
+ type CollType = ParCtrie[K, V]
+
+ def isCheckingViews = false
+
+ def hasStrictOrder = false
+
+ def ofSize(vals: Seq[Gen[(K, V)]], sz: Int) = {
+ val ct = new mutable.Ctrie[K, V]
+ val gen = vals(rnd.nextInt(vals.size))
+ for (i <- 0 until sz) ct += sample(gen)
+ ct
+ }
+
+ def fromTraversable(t: Traversable[(K, V)]) = {
+ val pct = new ParCtrie[K, V]
+ var i = 0
+ for (kv <- t.toList) {
+ pct += kv
+ i += 1
+ }
+ pct
+ }
+
+}
+
+
+object IntIntParallelCtrieCheck extends ParallelCtrieCheck[Int, Int]("Int, Int")
+with PairOperators[Int, Int]
+with PairValues[Int, Int]
+{
+ def intvalues = new IntValues {}
+ def kvalues = intvalues.values
+ def vvalues = intvalues.values
+
+ val intoperators = new IntOperators {}
+ def voperators = intoperators
+ def koperators = intoperators
+
+ override def printDataStructureDebugInfo(ds: AnyRef) = ds match {
+ case pm: ParCtrie[k, v] =>
+ println("Mutable parallel ctrie")
+ case _ =>
+ println("could not match data structure type: " + ds.getClass)
+ }
+
+ override def checkDataStructureInvariants(orig: Traversable[(Int, Int)], ds: AnyRef) = ds match {
+ // case pm: ParHashMap[k, v] if 1 == 0 => // disabled this to make tests faster
+ // val invs = pm.brokenInvariants
+
+ // val containsall = (for ((k, v) <- orig) yield {
+ // if (pm.asInstanceOf[ParHashMap[Int, Int]].get(k) == Some(v)) true
+ // else {
+ // println("Does not contain original element: " + (k, v))
+ // false
+ // }
+ // }).foldLeft(true)(_ && _)
+
+
+ // if (invs.isEmpty) containsall
+ // else {
+ // println("Invariants broken:\n" + invs.mkString("\n"))
+ // false
+ // }
+ case _ => true
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/test/files/scalacheck/parallel-collections/pc.scala b/test/files/scalacheck/parallel-collections/pc.scala
index cc0382303a..8a0dba3c25 100644
--- a/test/files/scalacheck/parallel-collections/pc.scala
+++ b/test/files/scalacheck/parallel-collections/pc.scala
@@ -25,6 +25,9 @@ class ParCollProperties extends Properties("Parallel collections") {
// parallel mutable hash maps (tables)
include(mutable.IntIntParallelHashMapCheck)
+ // parallel ctrie
+ include(mutable.IntIntParallelCtrieCheck)
+
// parallel mutable hash sets (tables)
include(mutable.IntParallelHashSetCheck)