You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2020/12/03 09:06:12 UTC

[GitHub] [cassandra] jacek-lewandowski commented on a change in pull request #811: CASSANDRA-16249: Fix the missing bb position in getUnsignedShort

jacek-lewandowski commented on a change in pull request #811:
URL: https://github.com/apache/cassandra/pull/811#discussion_r534975457



##########
File path: test/unit/org/apache/cassandra/db/marshal/ValueAccessorTest.java
##########
@@ -20,75 +20,95 @@
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.Arrays;
 import java.util.Random;
+import java.util.function.Function;
+import java.util.function.Supplier;
 
-import com.google.common.primitives.Shorts;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.apache.cassandra.io.util.DataOutputBuffer;
-import org.apache.cassandra.utils.ByteArrayUtil;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.assertj.core.api.Assertions;
 import org.quicktheories.core.Gen;
 import org.quicktheories.generators.SourceDSL;
 
 import static org.apache.cassandra.db.marshal.ValueAccessors.ACCESSORS;
+import static org.apache.cassandra.utils.ByteArrayUtil.bytesToHex;
+import static org.apache.cassandra.utils.ByteBufferUtil.bytesToHex;
 import static org.quicktheories.QuickTheory.qt;
+import static org.quicktheories.generators.SourceDSL.arbitrary;
+import static org.quicktheories.generators.SourceDSL.doubles;
+import static org.quicktheories.generators.SourceDSL.integers;
 
 public class ValueAccessorTest
 {
-    private static byte[] randomBytes(int minSize, int maxSize, Random random)
+    final static Supplier<Gen<Integer>> leftPadding = () -> integers().between(0, 2);
+    final static Supplier<Gen<Integer>> rightPadding = () -> integers().between(0, 2);
+    final static Supplier<Gen<ValueAccessor>> accessors = () -> SourceDSL.arbitrary().pick(ACCESSORS);
+    final static Supplier<Gen<Function>> paddings = () -> leftPadding.get().zip(rightPadding.get(), (l, r) -> v -> maybePad(v, l, r));
+    final static byte[] bytes = new byte[200];
+
+    @BeforeClass
+    public static void beforeClass()
     {
-        int size = random.nextInt(maxSize - minSize + 1) + minSize;
-        byte[] bytes = new byte[size];
-        random.nextBytes(bytes);
-        return bytes;
+        new Random(0).nextBytes(bytes);
+    }
+
+    /**
+     * This method should be used to test values to be processed by {@link ValueAccessor}
+     * in order to make sure we do not assume position == 0 in the underlying {@link ByteBuffer}
+     */
+    public static <V> V maybePad(V value, int lPad, int rPad)

Review comment:
       The purpose of this was to make sure we read only what we need to read instead of reading everything AFAIR - that is, read the size and only that number of content that is specified by size rather than the rest of the buffer




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org