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


##########
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());

Review Comment:
   We could utilize `ConsumerRecords#empty()` here, it would be more concise.



##########
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))

Review Comment:
   nit:
   If `new TopicPartition(topic, 0)` is only used to filter partitions, we 
could store it in a variable and reuse it, WDYT ?



##########
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,

Review Comment:
   nit:
   `new ConsumerRecord(...)` has the same situation as `new 
TopicPartition(topic, 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