diff options
author | Aleksandar Prokopec <aleksandar.prokopec@gmail.com> | 2015-02-11 20:40:35 +0100 |
---|---|---|
committer | Aleksandar Prokopec <aleksandar.prokopec@gmail.com> | 2015-02-18 23:34:24 +0100 |
commit | da2d4caae990bcb9fabb13e7a242b2b7babe0e0b (patch) | |
tree | 8d972c91aa4a3c4da1f2631689e1fc558cc80fc5 /test | |
parent | d14e065eb792a1eb77289f4a1320071c57c5d09b (diff) | |
download | scala-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')
-rw-r--r-- | test/files/scalacheck/Ctrie.scala | 19 |
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 + }) + } + } |