sreejasahithi commented on code in PR #10211:
URL: https://github.com/apache/ozone/pull/10211#discussion_r3206787775


##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSequenceIdType.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.hadoop.hdds.scm.ha;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link SequenceIdType}.
+ */
+public class TestSequenceIdType {
+
+  @Test
+  @SuppressWarnings("deprecation")
+  public void testStringSyncWithEnumConstants() {
+    // Even though we changed to an Enum, these underlying strings are
+    // persisted in RocksDB. Do not change them.
+    assertEquals("localId", SequenceIdType.LOCAL_ID.getDbKey());
+    assertEquals("delTxnId", SequenceIdType.DEL_TXN_ID.getDbKey());
+    assertEquals("containerId", SequenceIdType.CONTAINER_ID.getDbKey());
+    assertEquals("CertificateId", SequenceIdType.CERTIFICATE_ID.getDbKey());
+    assertEquals("rootCertificateId", 
SequenceIdType.ROOT_CERTIFICATE_ID.getDbKey());
+  }
+
+  @Test
+  @SuppressWarnings("deprecation")
+  public void testDeprecatedStringSyncWithEnumConstants() {
+    assertEquals(SequenceIdType.ROOT_CERTIFICATE_ID.getDbKey(),
+        SequenceIdGenerator.ROOT_CERTIFICATE_ID);
+  }
+
+  @Test
+  public void testNumberOfEnumConstants() {
+    // If a new SequenceIdType is added, this test will fail.
+    // This serves as a reminder to the developer to verify RocksDB backward
+    // compatibility and update this test class accordingly.
+    assertEquals(5, SequenceIdType.values().length);
+  }

Review Comment:
   Here testNumberOfEnumConstants (assertEquals(5, 
SequenceIdType.values().length)) is fully subsumed by 
testIfNewEnumConstantGetsAdded. Every failure scenario that 
testNumberOfEnumConstants catches is also caught by 
testIfNewEnumConstantGetsAdded, which additionally catches renames (count stays 
5 but a name changes), and provides a far more descriptive failure message with 
the "ACTION REQUIRED" instruction.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to