maedhroz commented on code in PR #2267: URL: https://github.com/apache/cassandra/pull/2267#discussion_r1185460303
########## test/unit/org/apache/cassandra/io/tries/AbstractTrieTestBase.java: ########## @@ -0,0 +1,228 @@ +/* + * 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.io.tries; + +import java.io.IOException; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Collection; +import java.util.function.BiFunction; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.io.util.ChannelProxy; +import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.io.util.DataOutputPlus; +import org.apache.cassandra.io.util.PageAware; +import org.apache.cassandra.io.util.Rebufferer; +import org.apache.cassandra.utils.bytecomparable.ByteComparable; + +@RunWith(Parameterized.class) +abstract public class AbstractTrieTestBase +{ + @Parameterized.Parameter(0) + public TestClass writerClass; + + enum TestClass + { + SIMPLE(IncrementalTrieWriterSimple::new), + PAGE_AWARE(IncrementalTrieWriterPageAware::new), + PAGE_AWARE_DEEP_ON_STACK((serializer, dest) -> new IncrementalDeepTrieWriterPageAware<>(serializer, dest, 256)), + PAGE_AWARE_DEEP_ON_HEAP((serializer, dest) -> new IncrementalDeepTrieWriterPageAware<>(serializer, dest, 0)), + PAGE_AWARE_DEEP_MIXED((serializer, dest) -> new IncrementalDeepTrieWriterPageAware<>(serializer, dest, 2)); + + final BiFunction<TrieSerializer<Integer, DataOutputPlus>, DataOutputPlus, IncrementalTrieWriter<Integer>> constructor; + TestClass(BiFunction<TrieSerializer<Integer, DataOutputPlus>, DataOutputPlus, IncrementalTrieWriter<Integer>> constructor) + { + this.constructor = constructor; + } + } + + @Parameterized.Parameters(name = "{index}: trie writer class={0}") + public static Collection<Object[]> data() + { + return Arrays.asList(new Object[]{ TestClass.SIMPLE }, + new Object[]{ TestClass.PAGE_AWARE }, + new Object[]{ TestClass.PAGE_AWARE_DEEP_ON_STACK }, + new Object[]{ TestClass.PAGE_AWARE_DEEP_ON_HEAP }, + new Object[]{ TestClass.PAGE_AWARE_DEEP_MIXED }); + } + + protected final static Logger logger = LoggerFactory.getLogger(TrieBuilderTest.class); + protected final static int BASE = 80; + + protected boolean dump = false; + protected int payloadSize = 0; + + @Before + public void beforeTest() + { + dump = false; + payloadSize = 0; + } + + IncrementalTrieWriter<Integer> newTrieWriter(TrieSerializer<Integer, DataOutputPlus> serializer, DataOutputPlus out) + { + return writerClass.constructor.apply(serializer, out); + } + + protected final TrieSerializer<Integer, DataOutputPlus> serializer = new TrieSerializer<Integer, DataOutputPlus>() + { + public int sizeofNode(SerializationNode<Integer> node, long nodePosition) + { + return TrieNode.typeFor(node, nodePosition).sizeofNode(node) + payloadSize; + } + + public void write(DataOutputPlus dataOutput, SerializationNode<Integer> node, long nodePosition) throws IOException + { + if (dump) + logger.info("Writing at {} type {} size {}: {}", Long.toHexString(nodePosition), TrieNode.typeFor(node, nodePosition), TrieNode.typeFor(node, nodePosition).sizeofNode(node), node); + TrieNode.typeFor(node, nodePosition).serialize(dataOutput, node, node.payload() != null ? node.payload() : 0, nodePosition); Review Comment: So just to confirm, the test serializer here is actually storing the payload in the payload flags? -- 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]

