Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Problem with Java 7 UUID.random()
package com.automatak.archivist.server.uuid
import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import com.automatak.commons.testing._
import java.util.UUID
@RunWith(classOf[JUnitRunner])
class MutlithreadedUniquenessOfUUID extends FunSuite with ShouldMatchers {
test("Warm up the generator") {
1000000.times(UUID.randomUUID())
}
test("Highly concurrently generated UUIDS are still unique") {
val uuidPerThread = 100000
val numThreads = 64
val totalUUID = uuidPerThread * numThreads
val set = collection.mutable.Set.empty[UUID]
val threads = numThreads create {
onAnotherThread {
uuidPerThread times {
val uuid = UUID.randomUUID()
set.synchronized {
if (set.contains(uuid)) println(uuid)
else set += uuid
}
}
}
}
val (ns, _) = time(threads.foreach(_.join()))
set.size should equal(totalUUID)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.