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


##########
test/distributed/org/apache/cassandra/fuzz/sai/SingleNodeSAITestBase.java:
##########
@@ -156,20 +187,28 @@ private void basicSaiTest(EntropySource rng, SchemaSpec 
schema)
                                                                                
             .pageSizeSelector(pageSizeSelector(rng))
                                                                                
             .consistencyLevel(consistencyLevelSelector())
                                                                                
             .doubleWriting(schema, hb, cluster, "debug_table"));
-        List<Integer> partitions = new ArrayList<>();
-        for (int j = 0; j < 5; j++)
-        {
-            int picked = globalPkGen.generate(rng);
-            if (usedPartitions.contains(picked))
-                continue;
-            partitions.add(picked);
-        }
+        Set<Integer> partitions = new HashSet<>();

Review Comment:
   the following patch creates 2 new functions to help with this
   
   ```
   diff --git a/test/harry/main/org/apache/cassandra/harry/gen/Generators.java 
b/test/harry/main/org/apache/cassandra/harry/gen/Generators.java
   index ca2e5f2749..8c3d32943c 100644
   --- a/test/harry/main/org/apache/cassandra/harry/gen/Generators.java
   +++ b/test/harry/main/org/apache/cassandra/harry/gen/Generators.java
   @@ -451,6 +451,32 @@ public class Generators
            };
        }
   
   +    public static <T> Generator<List<T>> uniqueList(Generator<T> gen, int 
size)
   +    {
   +        // unique allocates a shared set, so need to allocate each call to 
generate in case there is concurrent access
   +        return rng -> unique(gen).generate(rng, size);
   +    }
   +
   +    public static <T> Generator<List<T>> uniqueListBestEffort(Generator<T> 
gen, int size)
   +    {
   +        return rng -> {
   +            Set<T> seen = new HashSet<>();
   +            List<T> list = new ArrayList<>(size);
   +            for (int i = 0; i < size; i++)
   +            {
   +                T value = null;
   +                for (int j = 0; j <= 42 && !seen.add(value = 
gen.generate(rng)); j++)
   +                {
   +                    if (j == 42)
   +                        // max attempts... can not reach the target size
   +                        return list;
   +                }
   +                list.add(value);
   +            }
   +            return list;
   +        };
   +    }
   +
        public static <T> Generator<T> constant(T constant)
        {
            return (random) -> constant;
   ```



-- 
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