m1a2st commented on code in PR #16588:
URL: https://github.com/apache/kafka/pull/16588#discussion_r1676825468


##########
clients/src/test/java/org/apache/kafka/clients/consumer/ConsumerRecordsTest.java:
##########
@@ -145,6 +144,26 @@ public void testRecordsByTopic() {
         }
     }
 
+    @Test
+    public void testRecordsAreImmutable() {
+        String topic = "topic";
+        int recordSize = 3;
+        int partitionSize = 6;
+        int emptyPartitionIndex = 2;
+
+        ConsumerRecords<Integer, String> records = 
buildTopicTestRecords(recordSize, partitionSize, emptyPartitionIndex, 
Collections.singleton(topic));
+        ConsumerRecords<Integer, String> emptyRecords = new 
ConsumerRecords<>(Collections.emptyMap());
+
+        assertThrows(UnsupportedOperationException.class, () -> 
records.records(new TopicPartition(topic, 0))
+            .add(new ConsumerRecord<>(topic, 0, 0, 0L, 
TimestampType.CREATE_TIME,
+                0, 0, 0, String.valueOf(0), new RecordHeaders(), 
Optional.empty())));
+        assertThrows(UnsupportedOperationException.class, () -> 
emptyRecords.records(new TopicPartition(topic, 0))
+            .add(new ConsumerRecord<>(topic, 0, 0, 0L, 
TimestampType.CREATE_TIME,
+                0, 0, 0, String.valueOf(0), new RecordHeaders(), 
Optional.empty())));

Review Comment:
   nit:
   I think `String.valueOf(0)` can change to `"0"`.



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

Reply via email to