summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/Ctrie.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <aleksandar.prokopec@gmail.com>2015-02-11 20:40:35 +0100
committerAleksandar Prokopec <aleksandar.prokopec@gmail.com>2015-02-18 23:34:24 +0100
commitda2d4caae990bcb9fabb13e7a242b2b7babe0e0b (patch)
tree8d972c91aa4a3c4da1f2631689e1fc558cc80fc5 /test/files/scalacheck/Ctrie.scala
parentd14e065eb792a1eb77289f4a1320071c57c5d09b (diff)
downloadscala-da2d4caae990bcb9fabb13e7a242b2b7babe0e0b.tar.gz
scala-da2d4caae990bcb9fabb13e7a242b2b7babe0e0b.tar.bz2
scala-da2d4caae990bcb9fabb13e7a242b2b7babe0e0b.zip
Fix SI-7943 -- make `TrieMap.getOrElseUpdate` atomic.
Override `getOrElseUpdate` method in `TrieMap`. The signature and contract of this method corresponds closely to the `computeIfAbsent` from `java.util.concurrent.ConcurrentMap`. Eventually, `computeIfAbsent` should be added to `scala.collection.concurrent.Map`. Add tests. Review by @Ichoran
Diffstat (limited to 'test/files/scalacheck/Ctrie.scala')
-rw-r--r--test/files/scalacheck/Ctrie.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/files/scalacheck/Ctrie.scala b/test/files/scalacheck/Ctrie.scala
index 714f1c3b09..eef9d06f37 100644
--- a/test/files/scalacheck/Ctrie.scala
+++ b/test/files/scalacheck/Ctrie.scala
@@ -186,6 +186,25 @@ object Test extends Properties("concurrent.TrieMap") {
})
}
+ property("concurrent getOrElseUpdate") = forAll(threadCounts, sizes) {
+ (p, sz) =>
+ val totalInserts = new java.util.concurrent.atomic.AtomicInteger
+ val ct = new TrieMap[Wrap, String]
+
+ val results = inParallel(p) {
+ idx =>
+ (0 until sz) foreach {
+ i =>
+ val v = ct.getOrElseUpdate(Wrap(i), idx + ":" + i)
+ if (v == idx + ":" + i) totalInserts.incrementAndGet()
+ }
+ }
+
+ (totalInserts.get == sz) && ((0 until sz) forall {
+ case i => ct(Wrap(i)).split(":")(1).toInt == i
+ })
+ }
+
}