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


##########
test/unit/org/apache/cassandra/utils/AbstractTypeGenerators.java:
##########
@@ -72,42 +103,271 @@
               TypeSupport.of(LongType.instance, SourceDSL.longs().all()),
               TypeSupport.of(FloatType.instance, SourceDSL.floats().any()),
               TypeSupport.of(DoubleType.instance, SourceDSL.doubles().any()),
-              TypeSupport.of(BytesType.instance, Generators.bytes(1, 1024)),
+              TypeSupport.of(BytesType.instance, Generators.bytes(0, 1024), 
FastByteOperations::compareUnsigned), // use the faster version...
               TypeSupport.of(UUIDType.instance, Generators.UUID_RANDOM_GEN),
-              TypeSupport.of(InetAddressType.instance, 
Generators.INET_ADDRESS_UNRESOLVED_GEN), // serialization strips the hostname, 
only keeps the address
-              TypeSupport.of(AsciiType.instance, 
SourceDSL.strings().ascii().ofLengthBetween(1, 1024)),
-              TypeSupport.of(UTF8Type.instance, Generators.utf8(1, 1024)),
+              TypeSupport.of(TimeUUIDType.instance, 
Generators.UUID_TIME_GEN.map(TimeUUID::fromUuid)),
+              TypeSupport.of(LexicalUUIDType.instance, 
Generators.UUID_RANDOM_GEN.mix(Generators.UUID_TIME_GEN)),
+              TypeSupport.of(InetAddressType.instance, 
Generators.INET_ADDRESS_UNRESOLVED_GEN, (a, b) -> 
FastByteOperations.compareUnsigned(a.getAddress(), b.getAddress())), // 
serialization strips the hostname, only keeps the address
+              /*
+              TODO
+              if (type instanceof StringType)
+        {
+            StringType st = (StringType) type;
+            return (Comparator<Object>) (Comparator<?>) (String a, String b) 
-> FastByteOperations.compareUnsigned(st.decompose(a), st.decompose(b));
+        }
+               */
+              TypeSupport.of(AsciiType.instance, 
SourceDSL.strings().ascii().ofLengthBetween(0, 1024)),
+              TypeSupport.of(UTF8Type.instance, Generators.utf8(0, 1024)),
               TypeSupport.of(TimestampType.instance, Generators.DATE_GEN),
+              TypeSupport.of(SimpleDateType.instance, 
SourceDSL.integers().between(0, Integer.MAX_VALUE)), // can't use time gen as 
this is an int, and in Milliseconds... so overflows...
               // null is desired here as #decompose will call 
org.apache.cassandra.serializers.EmptySerializer.serialize which ignores the 
input and returns empty bytes
-              TypeSupport.of(EmptyType.instance, rnd -> null)
-              //TODO add the following
-              // IntegerType.instance,
-              // DecimalType.instance,
-              // TimeUUIDType.instance,
-              // LexicalUUIDType.instance,
-              // SimpleDateType.instance,
-              // TimeType.instance,
-              // DurationType.instance,
+              TypeSupport.of(EmptyType.instance, rnd -> null, (a, b) -> 0),
+              TypeSupport.of(DurationType.instance, 
CassandraGenerators.duration(), Comparator.comparingInt(Duration::getMonths)
+                                                                               
               .thenComparingInt(Duration::getDays)
+                                                                               
               .thenComparingLong(Duration::getNanoseconds))
     ).collect(Collectors.toMap(t -> t.type, t -> t));
     // NOTE not supporting reversed as CQL doesn't allow nested reversed types
     // when generating part of the clustering key, it would be good to allow 
reversed types as the top level
-    private static final Gen<AbstractType<?>> PRIMITIVE_TYPE_GEN = 
SourceDSL.arbitrary().pick(new ArrayList<>(PRIMITIVE_TYPE_DATA_GENS.keySet()));
+    private static final Gen<AbstractType<?>> PRIMITIVE_TYPE_GEN;
+    static
+    {
+        ArrayList<AbstractType<?>> types = new 
ArrayList<>(PRIMITIVE_TYPE_DATA_GENS.keySet());
+        Collections.sort(types, Comparator.comparing(a -> 
a.getClass().getName()));
+        PRIMITIVE_TYPE_GEN = SourceDSL.arbitrary().pick(types);
+    }
+    private static final Set<Class<? extends AbstractType>> 
NON_PRIMITIVE_TYPES = ImmutableSet.<Class<? extends AbstractType>>builder()
+                                                                               
               .add(SetType.class)
+                                                                               
               .add(ListType.class)
+                                                                               
               .add(MapType.class)
+                                                                               
               .add(TupleType.class)
+                                                                               
               .add(UserType.class)
+                                                                               
               .add(VectorType.class)
+                                                                               
               .build();
 
     private AbstractTypeGenerators()
     {
 
     }
 
     public enum TypeKind
-    {PRIMITIVE, SET, LIST, MAP, TUPLE, UDT}
+    {PRIMITIVE, SET, LIST, MAP, TUPLE, UDT, VECTOR}
 
     private static final Gen<TypeKind> TYPE_KIND_GEN = 
SourceDSL.arbitrary().enumValuesWithNoOrder(TypeKind.class);
 
+    public static Set<Class<? extends AbstractType>> knownTypes()
+    {
+        Set<Class<? extends AbstractType>> types = 
PRIMITIVE_TYPE_DATA_GENS.keySet().stream().map(a -> 
a.getClass()).collect(Collectors.toSet());
+        types.addAll(NON_PRIMITIVE_TYPES);
+        types.add(FrozenType.class);
+        types.add(ReversedType.class);

Review Comment:
   not tested here but is tested in 
`CasssandraGenerators.TableMetadataBuilder`... this is here so the test that 
makes sure all cases are covered doesn't fail for this type



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