PatrickRen commented on a change in pull request #18863:
URL: https://github.com/apache/flink/pull/18863#discussion_r812617505



##########
File path: 
flink-connectors/flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/partitioner/FlinkRoundRobinPartitioner.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.kafka.partitioner;
+
+import org.apache.flink.util.Preconditions;
+
+import org.apache.kafka.common.utils.Utils;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A "Round-Robin" partitioner that can be used when user wants to distribute 
the writes to all partitions equally.
+ *
+ * <p>This is the behaviour regardless of record key hash.
+ */
+public class FlinkRoundRobinPartitioner<T> extends FlinkKafkaPartitioner<T> {
+
+    private ConcurrentMap<String, AtomicInteger> topicCounterMap;
+
+    @Override
+    public void open(int parallelInstanceId, int parallelInstances) {
+        Preconditions.checkArgument(
+            parallelInstanceId >= 0, "Id of this subtask cannot be negative.");
+        Preconditions.checkArgument(
+            parallelInstances > 0, "Number of subtasks must be larger than 
0.");
+
+        this.topicCounterMap = new ConcurrentHashMap();
+    }
+
+    @Override
+    public int partition(T record, byte[] key, byte[] value, String 
targetTopic, int[] partitions) {

Review comment:
       What about just reuse Kafka's 
`org.apache.kafka.clients.producer.RoundRobinPartitioner` instead of implement 
one?

##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/FlinkRoundRobinPartitionerTest.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.kafka;
+
+import 
org.apache.flink.streaming.connectors.kafka.partitioner.FlinkRoundRobinPartitioner;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/** Tests for the {@link FlinkRoundRobinPartitioner}. */
+public class FlinkRoundRobinPartitionerTest {
+
+    @Test
+    public void testRoundRobin() {
+        FlinkRoundRobinPartitioner<String> part = new 
FlinkRoundRobinPartitioner<>();
+
+        int[] partitions = new int[] {0, 1, 2, 3, 4};
+        String topic = "topic1";
+        part.open(0, 2);
+        Assert.assertEquals(0, part.partition("abc1", null, null, topic, 
partitions));

Review comment:
       Currently the community suggests to use AssertJ for assertions. Here's 
an example: 
https://github.com/apache/flink/blob/9a8f068fd207e178f1d29876130c81ab8a96baa2/flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/source/reader/KafkaSourceReaderTest.java#L171

##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/FlinkRoundRobinPartitionerTest.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.kafka;
+
+import 
org.apache.flink.streaming.connectors.kafka.partitioner.FlinkRoundRobinPartitioner;
+
+import org.junit.Assert;
+import org.junit.Test;

Review comment:
       Could we use JUnit 5 (`org.junit.jupiter.api.Test`) instead? 




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