netudima commented on code in PR #4789:
URL: https://github.com/apache/cassandra/pull/4789#discussion_r3237170672


##########
test/unit/org/apache/cassandra/db/ReadResponseTest.java:
##########
@@ -172,6 +191,212 @@ public void makeDigestDoesntConsiderRepairedDataInfo()
         assertEquals(response1.digest(command1), response2.digest(command2));
     }
 
+    @Test
+    public void inMemoryResponseEmptyIteratorMatchesLocalDataResponse()
+    {
+        ReadCommand command = command(key(), metadata);
+        StubRepairedDataInfo rdi = new 
StubRepairedDataInfo(ByteBufferUtil.EMPTY_BYTE_BUFFER, true);
+
+        ReadResponse localResponse = 
command.createResponse(EmptyIterators.unfilteredPartition(metadata), rdi);
+        ReadResponse inMemoryResponse = 
command.createLocalObjectResponse(EmptyIterators.unfilteredPartition(metadata), 
rdi);
+
+        assertIteratorsEqual(command, localResponse, inMemoryResponse);
+    }
+
+    @Test
+    public void inMemoryResponseWithRowsMatchesLocalDataResponse()
+    {
+        int key = key();
+        ReadCommand command = command(key, metadata);
+        StubRepairedDataInfo rdi = new 
StubRepairedDataInfo(ByteBufferUtil.EMPTY_BYTE_BUFFER, true);
+
+        DecoratedKey dk = 
metadata.partitioner.decorateKey(ByteBufferUtil.bytes(key));
+        Row row = buildRow(metadata, dk);
+        PartitionUpdate update = PartitionUpdate.singleRowUpdate(metadata, dk, 
row);
+
+        ReadResponse localResponse = 
command.createResponse(singlePartitionIterator(update), rdi);
+        ReadResponse inMemoryResponse = 
command.createLocalObjectResponse(singlePartitionIterator(update), rdi);
+
+        assertIteratorsEqual(command, localResponse, inMemoryResponse);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void inMemoryResponseCannotBeSerialized()
+    {
+        ReadCommand command = command(key(), metadata);
+        StubRepairedDataInfo rdi = new 
StubRepairedDataInfo(ByteBufferUtil.EMPTY_BYTE_BUFFER, true);
+        ReadResponse response = 
command.createLocalObjectResponse(EmptyIterators.unfilteredPartition(metadata), 
rdi);
+
+        try (DataOutputBuffer out = new DataOutputBuffer())
+        {
+            ReadResponse.serializer.serialize(response, out, 
MessagingService.current_version);
+        }
+        catch (IOException e)
+        {
+            fail("Unexpected IOException: " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void inMemoryResponseWithOverflowMatchesLocalDataResponse()
+    {
+        // 5 rows, only 2 fit in memory — 3 overflow into the serialized buffer
+        testMultipleRows(2, 5);
+    }
+
+    @Test
+    public void inMemoryResponseAllRowsInMemoryWhenUnderLimit()
+    {
+        // 3 rows, limit is 10 — all fit in memory with no overflow
+        testMultipleRows(10, 3);
+    }
+
+    @Test
+    public void inMemoryResponseWithZeroMaxRowsUsesOnlyOverflow()
+    {
+        // all rows go directly into the overflow buffer
+        testMultipleRows(0, 3);
+    }

Review Comment:
   thank you for highlighting the issue!



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

Reply via email to