dcapwell commented on code in PR #4537:
URL: https://github.com/apache/cassandra/pull/4537#discussion_r2674139225


##########
test/unit/org/apache/cassandra/service/RetryStrategyTest.java:
##########
@@ -64,6 +71,33 @@ public void fuzzParser()
         });
     }
 
+    @Test
+    public void testSeededWaitRandomizer()
+    {
+        RetrySpec spec = new RetrySpec(new RetrySpec.MaxAttempt(10),
+                                       new 
DurationSpec.LongMillisecondsBound("200ms"),
+                                       new 
DurationSpec.LongMillisecondsBound("1000ms"));
+        long wait1 = RetrySpec.toStrategy(sharedContext(100), 
spec).computeWait(1, TimeUnit.MILLISECONDS);
+        long wait2 = RetrySpec.toStrategy(sharedContext(100), 
spec).computeWait(1, TimeUnit.MILLISECONDS);
+        long wait3 = RetrySpec.toStrategy(sharedContext(200), 
spec).computeWait(1, TimeUnit.MILLISECONDS);
+        Assertions.assertThat(wait1).isEqualTo(wait2);
+        Assertions.assertThat(wait1).isNotEqualTo(wait3);
+    }
+
+    private static SharedContext sharedContext(long seed)
+    {
+        return new 
SharedContext.ForwardingSharedContext(SharedContext.Global.instance)
+        {
+            private final Random seededRandom = new Random(seed);
+
+            @Override
+            public Supplier<Random> random()
+            {
+                return () -> seededRandom;

Review Comment:
   nit: `() -> new Random(seed);` would be better, you would save 2 lines of 
code.  For the test it doesn't change the behavior as `random` is only called 
once per usage



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to