Skip to content

Commit

Permalink
test[protocol]: compatible test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Sep 26, 2023
1 parent 792cdfb commit ac7a4c4
Showing 1 changed file with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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"));
Expand Down Expand Up @@ -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));
}
}

0 comments on commit ac7a4c4

Please sign in to comment.