From ac7a4c4d9d60f13d49df9057bc1dd368cdab7aae Mon Sep 17 00:00:00 2001
From: sun <jaysunxiao@gmail.com>
Date: Tue, 26 Sep 2023 13:33:22 +0800
Subject: [PATCH] test[protocol]: compatible test

---
 .../CompatibleTesting.java}                   | 37 ++++++++++++++++---
 1 file changed, 31 insertions(+), 6 deletions(-)
 rename protocol/src/test/java/com/zfoo/protocol/{compatiblity/CompatibilityTesting.java => compatible/CompatibleTesting.java} (75%)

diff --git a/protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatibilityTesting.java b/protocol/src/test/java/com/zfoo/protocol/compatible/CompatibleTesting.java
similarity index 75%
rename from protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatibilityTesting.java
rename to protocol/src/test/java/com/zfoo/protocol/compatible/CompatibleTesting.java
index 118325dd4..dfcc2e000 100644
--- a/protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatibilityTesting.java
+++ b/protocol/src/test/java/com/zfoo/protocol/compatible/CompatibleTesting.java
@@ -10,14 +10,12 @@
  * See the License for the specific language governing permissions and limitations under the License.
  */
 
-package com.zfoo.protocol.compatiblity;
+package com.zfoo.protocol.compatible;
 
 import com.zfoo.protocol.ProtocolManager;
 import com.zfoo.protocol.generate.GenerateOperation;
 import com.zfoo.protocol.packet.*;
-import com.zfoo.protocol.util.ClassUtils;
-import com.zfoo.protocol.util.IOUtils;
-import com.zfoo.protocol.util.StringUtils;
+import com.zfoo.protocol.util.*;
 import io.netty.buffer.ByteBufAllocator;
 import io.netty.buffer.UnpooledHeapByteBuf;
 import org.junit.Ignore;
@@ -33,7 +31,7 @@
  * @author godotg
  */
 @Ignore
-public class CompatibilityTesting {
+public class CompatibleTesting {
 
     /**
      * EN: The order of the bytecode-enhanced Map traversal order will be different, so the order of the serialized content will change.
@@ -42,7 +40,7 @@ public class CompatibilityTesting {
      * CN: 字节码增强的Map遍历顺序会出现不一样,所以序列化的内容顺序会改变,可以看到不相同的字节并不是连续的
      */
     @Test
-    public void compatiblityTest() throws IOException {
+    public void compatibleTest() throws IOException {
         ProtocolManager.initProtocolAuto(Set.of(ComplexObject.class, NormalObject.class, SimpleObject.class, EmptyObject.class, VeryBigObject.class), GenerateOperation.NO_OPERATION);
 
         var bytes = IOUtils.toByteArray(ClassUtils.getFileFromClassPath("ComplexObject.bytes"));
@@ -89,4 +87,31 @@ public void enhanceNormalTest() {
 
         buffer.clear();
     }
+
+    @Test
+    public void normalTest() {
+        var buffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 1_0000);
+        ProtocolManager.write(buffer, normalObject);
+        var packet = ProtocolManager.read(buffer);
+
+
+        var newBuffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 1_0000);
+        ProtocolManager.write(newBuffer, packet);
+
+        buffer.resetReaderIndex();
+        newBuffer.resetReaderIndex();
+
+        var equal = 0;
+        var notEqual = 0;
+        for (int i = 0; i < buffer.writerIndex(); i++) {
+            var a = buffer.readByte();
+            var b = newBuffer.readByte();
+            if (a == b) {
+                equal++;
+            } else {
+                notEqual++;
+            }
+        }
+        System.out.println(StringUtils.format("equal [{}], not equal [{}]", equal, notEqual));
+    }
 }