yuxian0908 commented on code in PR #8503:
URL: https://github.com/apache/ozone/pull/8503#discussion_r2117137171


##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmSnapshotDiffJobCodec.java:
##########
@@ -0,0 +1,57 @@
+package org.apache.hadoop.ozone.om.helpers;
+
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus;
+import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.SubStatus;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+/**
+ * Testing serialization of SnapshotDiffJobCodec objects to/from RocksDB.
+ */
+public class TestOmSnapshotDiffJobCodec {
+  private final OldSnapshotDiffJobCodecForTesting oldCodec
+      = new OldSnapshotDiffJobCodecForTesting();
+  private final Codec<SnapshotDiffJob> newCodec = SnapshotDiffJob.getCodec();
+
+  @Test
+  public void testOldJsonSerializedDataCanBeReadByNewCodec() throws Exception {
+    // Step 1: Construct a SnapshotDiffJob instance
+    SnapshotDiffJob original = new SnapshotDiffJob(
+        123456789L,
+        "job-001",
+        JobStatus.IN_PROGRESS,
+        "volA",
+        "buckB",
+        "snap1",
+        "snap2",
+        true,
+        false,
+        100L,
+        SubStatus.SST_FILE_DELTA_DAG_WALK,
+        0.0
+    );
+
+    // Step 2: Serialize using the old Jackson-based codec
+    byte[] oldFormatData = oldCodec.toPersistedFormatImpl(original);
+
+    // Step 3: Deserialize using the new default codec (with Protobuf + JSON 
fallback)
+    SnapshotDiffJob parsed = newCodec.fromPersistedFormatImpl(oldFormatData);

Review Comment:
   Thank you very much for pointing this out!
   
   Just to clarify, the new codec is based on Protobuf (with optional JSON 
fallback), whereas the old codec uses Jackson-based JSON serialization. As a 
result, the byte outputs produced by the two codecs are not expected to be 
identical.
   
   Given this difference in serialization format, directly asserting 
assertArrayEquals(oldFormatData, newFormatData) might not yield meaningful 
results. Instead, we verify backward compatibility by confirming that data 
encoded using the old format can still be successfully decoded by the new 
codec, and that the key fields remain intact.
   
   Please kindly correct me if I have misunderstood anything.



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