aweisberg commented on code in PR #3785: URL: https://github.com/apache/cassandra/pull/3785#discussion_r1934272404
########## test/distributed/org/apache/cassandra/distributed/test/cql3/SingleNodeTableWalkTest.java: ########## @@ -0,0 +1,535 @@ +/* + * 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.distributed.test.cql3; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.NavigableSet; +import java.util.Optional; +import java.util.TreeMap; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import accord.utils.Gen; +import accord.utils.Gens; +import accord.utils.Property; +import accord.utils.RandomSource; +import org.apache.cassandra.cql3.ast.Bind; +import org.apache.cassandra.cql3.ast.Conditional; +import org.apache.cassandra.cql3.ast.CreateIndexDDL; +import org.apache.cassandra.cql3.ast.FunctionCall; +import org.apache.cassandra.cql3.ast.Mutation; +import org.apache.cassandra.cql3.ast.ReferenceExpression; +import org.apache.cassandra.cql3.ast.Select; +import org.apache.cassandra.cql3.ast.Symbol; +import org.apache.cassandra.cql3.ast.TableReference; +import org.apache.cassandra.cql3.ast.Value; +import org.apache.cassandra.db.Clustering; +import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.InetAddressType; +import org.apache.cassandra.db.marshal.UTF8Type; +import org.apache.cassandra.dht.Murmur3Partitioner; +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.shared.ClusterUtils; +import org.apache.cassandra.harry.model.BytesPartitionState; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.schema.TableMetadata; +import org.apache.cassandra.service.consensus.TransactionalMode; +import org.apache.cassandra.utils.ASTGenerators; +import org.apache.cassandra.utils.AbstractTypeGenerators; +import org.apache.cassandra.utils.AbstractTypeGenerators.TypeGenBuilder; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.CassandraGenerators.TableMetadataBuilder; +import org.apache.cassandra.utils.Generators; +import org.apache.cassandra.utils.ImmutableUniqueList; +import org.quicktheories.generators.SourceDSL; + +import static accord.utils.Property.commands; +import static accord.utils.Property.stateful; +import static org.apache.cassandra.utils.ASTGenerators.safeColumns; +import static org.apache.cassandra.utils.AbstractTypeGenerators.getTypeSupport; +import static org.apache.cassandra.utils.Generators.toGen; + +public class SingleNodeTableWalkTest extends StatefulASTBase +{ + private static final Logger logger = LoggerFactory.getLogger(SingleNodeTableWalkTest.class); + + @Nullable + private final TransactionalMode transactionalMode; + + public SingleNodeTableWalkTest() + { + this(null); + } + + protected SingleNodeTableWalkTest(@Nullable TransactionalMode transactionalMode) + { + this.transactionalMode = transactionalMode; + } + + protected void preCheck(Property.StatefulBuilder builder) + { + // if a failing seed is detected, populate here + // Example: builder.withSeed(42L); + // To show string/blobs + // SHOW_REAL_VALUES = true; + } + + protected TypeGenBuilder supportedTypes() + { + return AbstractTypeGenerators.withoutUnsafeEquality(AbstractTypeGenerators.builder() + .withTypeKinds(AbstractTypeGenerators.TypeKind.PRIMITIVE)); + } + + protected List<CreateIndexDDL.Indexer> supportedIndexers() + { + // since legacy is async it's not clear how the test can wait for the background write to complete... + return Arrays.asList(CreateIndexDDL.SAI); + } + + public Property.Command<State, Void, ?> insert(RandomSource rs, State state) + { + //TODO (maintaince): can this become reusable? its the same as token conflict test... + Mutation mutation = state.mutationGen.next(rs); + return state.command(rs, mutation); + } + + public Property.Command<State, Void, ?> selectExisting(RandomSource rs, State state) + { + NavigableSet<BytesPartitionState.Ref> keys = state.model.partitionKeys(); + BytesPartitionState.Ref ref = rs.pickOrderedSet(keys); + Clustering<ByteBuffer> key = ref.key; + + Select.Builder builder = Select.builder().table(state.metadata); + ImmutableUniqueList<Symbol> pks = state.model.factory.pkPositions; + ImmutableUniqueList<Symbol> cks = state.model.factory.ckPositions; + for (Symbol pk : pks) + builder.value(pk, key.bufferAt(pks.indexOf(pk))); + + boolean wholePartition = cks.isEmpty() ? true : rs.nextBoolean(); + if (!wholePartition) + { + // find a row to select + BytesPartitionState partition = state.model.get(ref); + if (partition.isEmpty()) + { + wholePartition = true; + } + else + { + NavigableSet<Clustering<ByteBuffer>> clusteringKeys = partition.clusteringKeys(); + Clustering<ByteBuffer> clusteringKey = rs.pickOrderedSet(clusteringKeys); Review Comment: Oh my suggestion was to add ranges of clustering keys, not implying that it currently does that. We can call it out of scope for this PR. -- 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]

