@@ -6,7 +6,9 @@ import io.dapr.actors.runtime.AbstractActor
66import io.dapr.actors.runtime.ActorRuntimeContext
77import io.dapr.client.DaprClient
88import io.dapr.client.DaprClientBuilder
9+ import java.security.SecureRandom
910import java.util.concurrent.TimeUnit
11+ import kotlin.random.Random
1012import kotlin.time.Clock
1113
1214class CustomerActorImpl (runtimeContext : ActorRuntimeContext <CustomerActorImpl >, id : ActorId ) :
@@ -15,6 +17,14 @@ class CustomerActorImpl(runtimeContext: ActorRuntimeContext<CustomerActorImpl>,
1517
1618 val client: DaprClient ? = DaprClientBuilder ().build()
1719
20+ private val seedGenerator = SecureRandom ()
21+ private val threadRng =
22+ object : ThreadLocal <Random >() {
23+ override fun initialValue (): Random {
24+ return Random (seedGenerator.nextLong())
25+ }
26+ }
27+
1828 var count = 0
1929
2030 override fun request () {
@@ -23,6 +33,7 @@ class CustomerActorImpl(runtimeContext: ActorRuntimeContext<CustomerActorImpl>,
2333
2434 override fun full (data : Map <String , Any >) {
2535 measureEventTime(data)
36+ Thread .sleep(randomAround(10 , 2 ).toLong())
2637 request()
2738 }
2839
@@ -53,4 +64,8 @@ class CustomerActorImpl(runtimeContext: ActorRuntimeContext<CustomerActorImpl>,
5364 .timer(" event.latency" )!!
5465 .update((deltaNanos), TimeUnit .NANOSECONDS )
5566 }
67+
68+ private fun randomAround (base : Int , delta : Int ): Int {
69+ return (base - delta.. base + delta).random(threadRng.get())
70+ }
5671}
0 commit comments