dcapwell commented on code in PR #2122:
URL: https://github.com/apache/cassandra/pull/2122#discussion_r1099011365
##########
src/java/org/apache/cassandra/transport/CBUtil.java:
##########
@@ -478,7 +487,35 @@ public static void writeValue(ByteBuffer bytes, ByteBuf cb)
cb.writeInt(remaining);
if (remaining > 0)
- cb.writeBytes(bytes.duplicate());
+ {
Review Comment:
remove the `{}`
##########
test/unit/org/apache/cassandra/utils/Generators.java:
##########
@@ -299,6 +299,16 @@ private static char[] createDNSDomainPartDomain()
}
public static Gen<ByteBuffer> bytes(int min, int max)
+ {
+ return bytes(min, max, SourceDSL.arbitrary().constant(BBCases.HEAP));
+ }
+
+ public static Gen<ByteBuffer> bytesAnyType(int min, int max)
+ {
+ return bytes(min, max,
SourceDSL.arbitrary().enumValues(BBCases.class));
+ }
+
+ public static Gen<ByteBuffer> bytes(int min, int max, Gen<BBCases> cases)
Review Comment:
have to make this private, or fix `BBCases`. You can't have a public method
expose a private class (the build should be failing right now...).
If you choose to keep this method (I would not) then you should rename
`BBCases` to be more clear to readers...
##########
src/java/org/apache/cassandra/transport/CBUtil.java:
##########
@@ -478,7 +487,35 @@ public static void writeValue(ByteBuffer bytes, ByteBuf cb)
cb.writeInt(remaining);
if (remaining > 0)
- cb.writeBytes(bytes.duplicate());
+ {
+ addBytes(bytes, cb);
+ }
+ }
+
+ public static void addBytes(ByteBuffer src, ByteBuf dest)
+ {
+ if (src == null)
Review Comment:
why the null check? at least in the single usage this doesn't allow null...
I prefer if we remove and allow the NPE if a user provides null
##########
test/unit/org/apache/cassandra/transport/WriteBytesDuplicateTest.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.transport;
+
+import org.junit.Test;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.apache.cassandra.utils.Generators;
+import org.assertj.core.api.Assertions;
+
+import static org.quicktheories.QuickTheory.qt;
+
+
+public class WriteBytesDuplicateTest
Review Comment:
why `Duplicate`? You are "writing"
##########
test/unit/org/apache/cassandra/utils/Generators.java:
##########
@@ -314,11 +324,32 @@ public static Gen<ByteBuffer> bytes(int min, int max)
// to add more randomness, also shift offset in the array so the
same size doesn't yield the same bytes
int offset = (int) rnd.next(Constraint.between(0, MAX_BLOB_LENGTH
- size));
- return ByteBuffer.wrap(LazySharedBlob.SHARED_BYTES, offset, size);
+ switch (cases.generate(rnd))
+ {
+ case HEAP: return ByteBuffer.wrap(LazySharedBlob.SHARED_BYTES,
offset, size);
+ case READ_ONLY_HEAP: return
ByteBuffer.wrap(LazySharedBlob.SHARED_BYTES, offset, size).asReadOnlyBuffer();
+ case DIRECT:
+ {
+ ByteBuffer bb = ByteBuffer.allocateDirect(size);
+ bb.put(LazySharedBlob.SHARED_BYTES, offset, size);
+ bb.flip();
+ return bb;
Review Comment:
can you make this a function? best not to copy/paste
--
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]