maedhroz commented on code in PR #3474:
URL: https://github.com/apache/cassandra/pull/3474#discussion_r1722470137
##########
test/unit/org/apache/cassandra/utils/CassandraGenerators.java:
##########
@@ -610,6 +628,58 @@ public static Gen<Token> tokensInRange(Range<Token> range)
throw new UnsupportedOperationException("Unsupported partitioner: " +
partitioner.getClass());
}
+ private enum SupportedPartitioners { Murmur, ByteOrdered, Random, Local,
OrderPreserving}
+
+ public static Gen<IPartitioner> partitioners()
+ {
+ var pGen =
SourceDSL.arbitrary().enumValues(SupportedPartitioners.class);
+ return pGen.flatMap(p -> {
+ switch (p)
+ {
+ case Murmur: return ignore -> Murmur3Partitioner.instance;
+ case ByteOrdered: return ignore ->
ByteOrderedPartitioner.instance;
+ case Random: return ignore -> RandomPartitioner.instance;
+ case OrderPreserving: return ignore ->
OrderPreservingPartitioner.instance;
+ case Local: return localPartitioner();
+ default: throw new AssertionError("Unknown partition: " + p);
+ }
+ });
+ }
+
+ public static Gen<IPartitioner> nonLocalPartitioners()
+ {
+ var pGen =
SourceDSL.arbitrary().enumValues(SupportedPartitioners.class);
+ return pGen.assuming(p -> p != SupportedPartitioners.Local).flatMap(p
-> {
+ switch (p)
+ {
+ case Murmur: return ignore -> Murmur3Partitioner.instance;
+ case ByteOrdered: return ignore ->
ByteOrderedPartitioner.instance;
+ case Random: return ignore -> RandomPartitioner.instance;
+ case OrderPreserving: return ignore ->
OrderPreservingPartitioner.instance;
+ default: throw new AssertionError("Unknown partition: " + p);
+ }
+ });
+ }
Review Comment:
Could always write the above as...
```
private enum SupportedPartitioners
{
Murmur(ignore -> Murmur3Partitioner.instance),
ByteOrdered(ignore -> ByteOrderedPartitioner.instance),
Random(ignore -> RandomPartitioner.instance),
Local(localPartitioner()),
OrderPreserving(ignore -> OrderPreservingPartitioner.instance);
private final Gen<IPartitioner> partitioner;
SupportedPartitioners(Gen<IPartitioner> partitioner)
{
this.partitioner = partitioner;
}
public Gen<IPartitioner> partitioner()
{
return partitioner;
}
}
public static Gen<IPartitioner> partitioners()
{
return
SourceDSL.arbitrary().enumValues(SupportedPartitioners.class).flatMap(SupportedPartitioners::partitioner);
}
public static Gen<IPartitioner> nonLocalPartitioners()
{
return SourceDSL.arbitrary().enumValues(SupportedPartitioners.class)
.assuming(p -> p !=
SupportedPartitioners.Local)
.flatMap(SupportedPartitioners::partitioner);
}
```
...to make the `AssertionError`s unnecessary?
--
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]