dcapwell commented on code in PR #2310: URL: https://github.com/apache/cassandra/pull/2310#discussion_r1186555245
########## test/unit/org/apache/cassandra/db/marshal/AbstractTypeTest.java: ########## @@ -0,0 +1,439 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.marshal; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.lang.reflect.Modifier; +import java.net.InetAddress; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.google.common.collect.Sets; +import org.junit.Test; + +import org.apache.cassandra.cql3.AssignmentTestable; +import org.apache.cassandra.cql3.ColumnIdentifier; +import org.apache.cassandra.cql3.ColumnSpecification; +import org.apache.cassandra.cql3.Duration; +import org.apache.cassandra.cql3.Json; +import org.apache.cassandra.cql3.VariableSpecifications; +import org.apache.cassandra.io.util.DataInputBuffer; +import org.apache.cassandra.io.util.DataInputPlus; +import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.schema.CQLTypeParser; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.Types; +import org.apache.cassandra.transport.ProtocolVersion; +import org.apache.cassandra.utils.AbstractTypeGenerators; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.FastByteOperations; +import org.apache.cassandra.utils.bytecomparable.ByteComparable; +import org.apache.cassandra.utils.bytecomparable.ByteSource; +import org.quicktheories.core.Gen; +import org.reflections.Reflections; +import org.reflections.scanners.Scanners; +import org.reflections.util.ConfigurationBuilder; + +import static org.apache.cassandra.utils.AbstractTypeGenerators.extractUDTs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.quicktheories.QuickTheory.qt; + +public class AbstractTypeTest +{ + //TODO + // isCompatibleWith/isValueCompatibleWith/isSerializationCompatibleWith, + // withUpdatedUserType/expandUserTypes/referencesDuration - types that recursive check types + // getMaskedValue + + @Test + public void allTypesCovered() + { + // this test just makes sure that all types are covered and no new type is left out + Reflections reflections = new Reflections(new ConfigurationBuilder() + .forPackage("org.apache.cassandra") + .setScanners(Scanners.SubTypes) + .setExpandSuperTypes(true) + .setParallel(true)); + Set<Class<? extends AbstractType>> subTypes = reflections.getSubTypesOf(AbstractType.class); + Set<Class<? extends AbstractType>> coverage = AbstractTypeGenerators.knownTypes(); + StringBuilder sb = new StringBuilder(); + for (Class<? extends AbstractType> klass : Sets.difference(subTypes, coverage)) + { + if (Modifier.isAbstract(klass.getModifiers())) + continue; + if ("test".equals(new File(klass.getProtectionDomain().getCodeSource().getLocation().getPath()).name())) + continue; + String name = klass.getCanonicalName(); + if (name == null) + name = klass.getName(); + sb.append(name).append('\n'); + } + if (sb.length() > 0) + throw new AssertionError("Uncovered types:\n" + sb); + } + + @Test + public void comparableBytes() + { + qt().withShrinkCycles(0).forAll(examples(1)).checkAssert(example -> { + AbstractType type = example.type; + for (Object value : example.samples) + { + ByteBuffer bb = type.decompose(value); + for (ByteComparable.Version bcv : ByteComparable.Version.values()) + { + // LEGACY, // Encoding used in legacy sstable format; forward (value to byte-comparable) translation only + // Legacy is a one-way conversion, so for this test ignore + if (bcv == ByteComparable.Version.LEGACY) + continue; + ByteSource.Peekable comparable = ByteSource.peekable(type.asComparableBytes(bb, bcv)); + if (comparable == null) + throw new NullPointerException(); Review Comment: we are working with non-null data, so this can't be null -- 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]

