diff --git a/WORKSPACE b/WORKSPACE
index e0ebfce7809..328c43995c0 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -41,7 +41,7 @@ maven_install(
artifacts = [
"junit:junit:4.13.2",
"com.alibaba:fastjson:1.2.76",
- "com.alibaba.fastjson2:fastjson2:2.0.43",
+ "com.alibaba.fastjson2:fastjson2:2.0.59",
"org.hamcrest:hamcrest-library:1.3",
"io.netty:netty-all:4.1.65.Final",
"org.assertj:assertj-core:3.22.0",
@@ -112,7 +112,7 @@ maven_install(
"com.alipay.sofa:hessian:3.3.6",
"io.netty:netty-tcnative-boringssl-static:2.0.48.Final",
"org.mockito:mockito-junit-jupiter:4.11.0",
- "com.alibaba.fastjson2:fastjson2:2.0.43",
+ "com.alibaba.fastjson2:fastjson2:2.0.59",
"org.junit.jupiter:junit-jupiter-api:5.9.1",
],
fetch_sources = True,
diff --git a/pom.xml b/pom.xml
index 37cff546cdd..f28beaf9e1a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,7 +105,7 @@
2.0.53.Final
1.83
1.2.83
- 2.0.43
+ 2.0.59
3.20.0-GA
4.2.2
3.20.0
diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/DataVersionTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/DataVersionTest.java
index dccedde491c..5cf69ae54f5 100644
--- a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/DataVersionTest.java
+++ b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/DataVersionTest.java
@@ -17,10 +17,16 @@
package org.apache.rocketmq.remoting.protocol;
-import java.util.concurrent.atomic.AtomicLong;
-import org.junit.Assert;
+import com.alibaba.fastjson2.JSON;
import org.junit.Test;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
public class DataVersionTest {
@Test
@@ -28,7 +34,7 @@ public void testEquals() {
DataVersion dataVersion = new DataVersion();
DataVersion other = new DataVersion();
other.setTimestamp(dataVersion.getTimestamp());
- Assert.assertTrue(dataVersion.equals(other));
+ assertEquals(dataVersion, other);
}
@Test
@@ -37,7 +43,7 @@ public void testEquals_falseWhenCounterDifferent() {
DataVersion other = new DataVersion();
other.setCounter(new AtomicLong(1L));
other.setTimestamp(dataVersion.getTimestamp());
- Assert.assertFalse(dataVersion.equals(other));
+ assertNotEquals(dataVersion, other);
}
@Test
@@ -46,7 +52,7 @@ public void testEquals_falseWhenCounterDifferent2() {
DataVersion other = new DataVersion();
other.setCounter(null);
other.setTimestamp(dataVersion.getTimestamp());
- Assert.assertFalse(dataVersion.equals(other));
+ assertNotEquals(dataVersion, other);
}
@Test
@@ -55,7 +61,7 @@ public void testEquals_falseWhenCounterDifferent3() {
dataVersion.setCounter(null);
DataVersion other = new DataVersion();
other.setTimestamp(dataVersion.getTimestamp());
- Assert.assertFalse(dataVersion.equals(other));
+ assertNotEquals(dataVersion, other);
}
@Test
@@ -65,13 +71,25 @@ public void testEquals_trueWhenCountersBothNull() {
DataVersion other = new DataVersion();
other.setCounter(null);
other.setTimestamp(dataVersion.getTimestamp());
- Assert.assertTrue(dataVersion.equals(other));
+ assertEquals(dataVersion, other);
}
@Test
public void testEncode() {
DataVersion dataVersion = new DataVersion();
- Assert.assertTrue(dataVersion.encode().length > 0);
- Assert.assertNotNull(dataVersion.toJson());
+ assertTrue(dataVersion.encode().length > 0);
+ assertNotNull(dataVersion.toJson());
+ }
+
+ @Test
+ public void testJsonSerializationAndDeserialization() {
+ DataVersion expected = new DataVersion();
+ expected.setCounter(new AtomicLong(Long.MAX_VALUE));
+ expected.setTimestamp(expected.getTimestamp());
+ String jsonStr = expected.toJson();
+ assertNotNull(jsonStr);
+ DataVersion actual = JSON.parseObject(jsonStr, DataVersion.class);
+ assertNotNull(actual);
+ assertEquals(expected.getTimestamp(), actual.getTimestamp());
}
}