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


##########
clients/src/test/java/org/apache/kafka/clients/consumer/ConsumerRecordsTest.java:
##########
@@ -145,6 +144,34 @@ public void testRecordsByTopic() {
         }
     }
 
+    @Test
+    public void testRecordsAreImmutable() {
+        String topic = "topic";
+        int recordSize = 3;
+        int partitionSize = 6;
+        int emptyPartitionIndex = 2;
+        TopicPartition topicFilter = new TopicPartition(topic, 0);
+        TopicPartition newPartition = new TopicPartition(topic, 0);
+        ConsumerRecord<Integer, String> newRecord = new 
ConsumerRecord<>(topic, 0, 0, 0L, TimestampType.CREATE_TIME,
+            0, 0, 0, "0", new RecordHeaders(), Optional.empty());
+        ConsumerRecords<Integer, String> records = 
buildTopicTestRecords(recordSize, partitionSize, emptyPartitionIndex, 
Collections.singleton(topic));
+        ConsumerRecords<Integer, String> emptyRecords = 
ConsumerRecords.empty();
+
+        // check records / partitions by add method
+        // check iterator by remove method
+        // check data count after all operations
+        assertThrows(UnsupportedOperationException.class, () -> 
records.records(topicFilter).add(newRecord));
+        assertThrows(UnsupportedOperationException.class, () -> 
records.partitions().add(newPartition));

Review Comment:
   Could you reuse the `topicFilter`?



##########
clients/src/test/java/org/apache/kafka/clients/consumer/ConsumerRecordsTest.java:
##########
@@ -145,6 +144,34 @@ public void testRecordsByTopic() {
         }
     }
 
+    @Test
+    public void testRecordsAreImmutable() {
+        String topic = "topic";
+        int recordSize = 3;
+        int partitionSize = 6;
+        int emptyPartitionIndex = 2;
+        TopicPartition topicFilter = new TopicPartition(topic, 0);
+        TopicPartition newPartition = new TopicPartition(topic, 0);
+        ConsumerRecord<Integer, String> newRecord = new 
ConsumerRecord<>(topic, 0, 0, 0L, TimestampType.CREATE_TIME,
+            0, 0, 0, "0", new RecordHeaders(), Optional.empty());
+        ConsumerRecords<Integer, String> records = 
buildTopicTestRecords(recordSize, partitionSize, emptyPartitionIndex, 
Collections.singleton(topic));
+        ConsumerRecords<Integer, String> emptyRecords = 
ConsumerRecords.empty();
+
+        // check records / partitions by add method
+        // check iterator by remove method
+        // check data count after all operations
+        assertThrows(UnsupportedOperationException.class, () -> 
records.records(topicFilter).add(newRecord));

Review Comment:
   Could you please add test for `records(String)`?



##########
clients/src/test/java/org/apache/kafka/clients/consumer/ConsumerRecordsTest.java:
##########
@@ -145,6 +144,34 @@ public void testRecordsByTopic() {
         }
     }
 
+    @Test
+    public void testRecordsAreImmutable() {
+        String topic = "topic";
+        int recordSize = 3;
+        int partitionSize = 6;
+        int emptyPartitionIndex = 2;
+        TopicPartition topicFilter = new TopicPartition(topic, 0);

Review Comment:
   maybe we can rename it to `topicPartition`? I don't get the point of "filter"



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