NateAdere commented on code in PR #2122:
URL: https://github.com/apache/cassandra/pull/2122#discussion_r1108944068
##########
test/unit/org/apache/cassandra/utils/Generators.java:
##########
@@ -314,11 +324,36 @@ 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);
+ return handleCases(cases, rnd, offset, size);
};
+ };
+
+ private enum BBCases { HEAP, READ_ONLY_HEAP, DIRECT, READ_ONLY_DIRECT }
+
+ private static ByteBuffer handleCases(Gen<BBCases> cases, RandomnessSource
rnd, int offset, int 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:
the new handleCases helps with readability so my plan is to keep that method
and add "ByteBuffer bb = directBufferFromSharedBlob(offset, size);" to address
the copy/paste code. Any opinions on removing or keeping the method?
--
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]