mjsax commented on code in PR #17858:
URL: https://github.com/apache/kafka/pull/17858#discussion_r1850941705


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -1294,19 +1294,19 @@ private void resetOffsets(final Set<TopicPartition> 
partitions, final Exception
         final Set<TopicPartition> notReset = new HashSet<>();
 
         for (final TopicPartition partition : partitions) {
-            final OffsetResetStrategy offsetResetStrategy = 
topologyMetadata.offsetResetStrategy(partition.topic());
+            final AutoOffsetResetStrategy offsetResetStrategy = 
topologyMetadata.offsetResetStrategy(partition.topic());
 
             // This may be null if the task we are currently processing was 
apart of a named topology that was just removed.
             // TODO KAFKA-13713: keep the StreamThreads and TopologyMetadata 
view of named topologies in sync until final thread has acked
             if (offsetResetStrategy != null) {
-                switch (offsetResetStrategy) {
-                    case EARLIEST:
+                switch (offsetResetStrategy.name()) {

Review Comment:
   Why do we need to switch to `name()` here and do a string comparison? Can't 
we keep an enum comparison?



##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AutoOffsetResetStrategy.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.ConfigException;
+
+import java.util.Objects;
+
+public class AutoOffsetResetStrategy {
+    public static final String EARLIEST_STRATEGY_NAME = "earliest";
+    public static final String LATEST_STRATEGY_NAME = "latest";
+    public static final String NONE_STRATEGY_NAME = "none";
+
+    public static final AutoOffsetResetStrategy EARLIEST = new 
AutoOffsetResetStrategy(EARLIEST_STRATEGY_NAME);
+    public static final AutoOffsetResetStrategy LATEST = new 
AutoOffsetResetStrategy(LATEST_STRATEGY_NAME);
+    public static final AutoOffsetResetStrategy NONE = new 
AutoOffsetResetStrategy(NONE_STRATEGY_NAME);

Review Comment:
   If we use an `enum` we don't need this boiler plate objects?



##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AutoOffsetResetStrategyTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.common.config.ConfigException;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class AutoOffsetResetStrategyTest {
+
+    @Test
+    public void testIsValid() {
+        assertTrue(AutoOffsetResetStrategy.isValid("earliest"));
+        assertTrue(AutoOffsetResetStrategy.isValid("latest"));
+        assertTrue(AutoOffsetResetStrategy.isValid("none"));
+        assertFalse(AutoOffsetResetStrategy.isValid("invalid"));
+        assertFalse(AutoOffsetResetStrategy.isValid("LATEST"));
+        assertFalse(AutoOffsetResetStrategy.isValid(""));

Review Comment:
   Should we add a test case for `null` ?



##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AutoOffsetResetStrategy.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.ConfigException;
+
+import java.util.Objects;
+
+public class AutoOffsetResetStrategy {
+    public static final String EARLIEST_STRATEGY_NAME = "earliest";
+    public static final String LATEST_STRATEGY_NAME = "latest";
+    public static final String NONE_STRATEGY_NAME = "none";

Review Comment:
   Should we still have an internal `enum` for the different strategies, to 
avoid doing string comparisons?



##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AutoOffsetResetStrategyTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.common.config.ConfigException;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class AutoOffsetResetStrategyTest {
+
+    @Test
+    public void testIsValid() {
+        assertTrue(AutoOffsetResetStrategy.isValid("earliest"));
+        assertTrue(AutoOffsetResetStrategy.isValid("latest"));
+        assertTrue(AutoOffsetResetStrategy.isValid("none"));
+        assertFalse(AutoOffsetResetStrategy.isValid("invalid"));
+        assertFalse(AutoOffsetResetStrategy.isValid("LATEST"));
+        assertFalse(AutoOffsetResetStrategy.isValid(""));
+    }
+
+    @Test
+    public void testValueOf() {
+        assertEquals(AutoOffsetResetStrategy.EARLIEST, 
AutoOffsetResetStrategy.valueOf("earliest"));
+        assertEquals(AutoOffsetResetStrategy.LATEST, 
AutoOffsetResetStrategy.valueOf("latest"));
+        assertEquals(AutoOffsetResetStrategy.NONE, 
AutoOffsetResetStrategy.valueOf("none"));
+        assertThrows(IllegalArgumentException.class, () -> 
AutoOffsetResetStrategy.valueOf("invalid"));
+        assertThrows(IllegalArgumentException.class, () -> 
AutoOffsetResetStrategy.valueOf("LATEST"));
+        assertThrows(IllegalArgumentException.class, () -> 
AutoOffsetResetStrategy.valueOf(""));
+    }
+
+    @Test
+    public void testValidator() {
+        AutoOffsetResetStrategy.Validator validator = new 
AutoOffsetResetStrategy.Validator();
+        assertDoesNotThrow(() -> validator.ensureValid("test", "earliest"));
+        assertDoesNotThrow(() -> validator.ensureValid("test", "latest"));
+        assertDoesNotThrow(() -> validator.ensureValid("test", "none"));
+        assertThrows(ConfigException.class, () -> 
validator.ensureValid("test", "invalid"));
+        assertThrows(ConfigException.class, () -> 
validator.ensureValid("test", "LATEST"));
+        assertThrows(ConfigException.class, () -> 
validator.ensureValid("test", ""));

Review Comment:
   `null` ?



##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AutoOffsetResetStrategyTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.common.config.ConfigException;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class AutoOffsetResetStrategyTest {
+
+    @Test
+    public void testIsValid() {
+        assertTrue(AutoOffsetResetStrategy.isValid("earliest"));
+        assertTrue(AutoOffsetResetStrategy.isValid("latest"));
+        assertTrue(AutoOffsetResetStrategy.isValid("none"));
+        assertFalse(AutoOffsetResetStrategy.isValid("invalid"));
+        assertFalse(AutoOffsetResetStrategy.isValid("LATEST"));
+        assertFalse(AutoOffsetResetStrategy.isValid(""));
+    }
+
+    @Test
+    public void testValueOf() {
+        assertEquals(AutoOffsetResetStrategy.EARLIEST, 
AutoOffsetResetStrategy.valueOf("earliest"));
+        assertEquals(AutoOffsetResetStrategy.LATEST, 
AutoOffsetResetStrategy.valueOf("latest"));
+        assertEquals(AutoOffsetResetStrategy.NONE, 
AutoOffsetResetStrategy.valueOf("none"));
+        assertThrows(IllegalArgumentException.class, () -> 
AutoOffsetResetStrategy.valueOf("invalid"));
+        assertThrows(IllegalArgumentException.class, () -> 
AutoOffsetResetStrategy.valueOf("LATEST"));
+        assertThrows(IllegalArgumentException.class, () -> 
AutoOffsetResetStrategy.valueOf(""));

Review Comment:
   Should we add a test case for `null`?



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