szetszwo commented on code in PR #8503:
URL: https://github.com/apache/ozone/pull/8503#discussion_r2108087674
##########
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:
We should test the other direction -- encode using the new codec and then
verify the bytes, i.e.
```java
byte[] newFormatData = newCodec.toPersistedFormatImpl(original);
assertArrayEquals(oldFormatData, newFormatData);
```
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/OldSnapshotDiffJobCodecForTesting.java:
##########
@@ -0,0 +1,37 @@
+package org.apache.hadoop.ozone.om.helpers;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import java.io.IOException;
+
+
+public class OldSnapshotDiffJobCodecForTesting
Review Comment:
`OldSnapshotDiffJobCodecForTesting` is better since this class is for
testing only.
--
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]