From bbcae91ec3330c8d05bb8f92569288e29fab1df4 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 22 Sep 2023 10:27:10 +0800 Subject: [PATCH] del[protocol]: remove fury test, record not support --- protocol/pom.xml | 26 ++-- .../com/zfoo/protocol/BenchmarkTesting.java | 143 ++++++++---------- .../com/zfoo/protocol/packet/ObjectA.java | 49 +----- .../com/zfoo/protocol/packet/ObjectB.java | 27 +--- 4 files changed, 87 insertions(+), 158 deletions(-) diff --git a/protocol/pom.xml b/protocol/pom.xml index 3f601c17..0ca3fb38 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -124,22 +124,22 @@ com.esotericsoftware kryo - 5.3.0 + 5.5.0 test - - org.furyio - fury-core - 0.1.0 - test - - - slf4j-api - org.slf4j - - - + + + + + + + + + + + + junit diff --git a/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java b/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java index b02952f9..0eeaa62e 100644 --- a/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java +++ b/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java @@ -24,11 +24,6 @@ import com.zfoo.protocol.collection.ArrayUtils; import com.zfoo.protocol.generate.GenerateOperation; import com.zfoo.protocol.packet.*; import com.zfoo.protocol.util.StringUtils; -import io.fury.Fury; -import io.fury.Language; -import io.fury.ThreadLocalFury; -import io.fury.ThreadSafeFury; -import io.fury.memory.MemoryBuffer; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.UnpooledHeapByteBuf; @@ -68,7 +63,7 @@ public class BenchmarkTesting { System.out.println(StringUtils.format("[单线程性能测试-->[benchmark:{}]]", benchmark)); zfooTest(); - furyTest(); +// furyTest(); protobufTest(); kryoTest(); @@ -90,7 +85,7 @@ public class BenchmarkTesting { System.out.println(StringUtils.format("[多线程性能测试-->[benchmark:{}]]", benchmark)); zfooMultipleThreadTest(); - furyMultipleThreadTest(); +// furyMultipleThreadTest(); protobufMultipleThreadTest(); kryoMultipleThreadTest(); @@ -142,41 +137,41 @@ public class BenchmarkTesting { System.out.println(StringUtils.format("[zfoo] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); } - @Test - public void furyTest() { - var buffer = MemoryBuffer.newHeapBuffer(1_0000); - // 序列化和反序列化简单对象 - long startTime = System.currentTimeMillis(); - for (int i = 0; i < benchmark; i++) { - buffer.writerIndex(0); - buffer.readerIndex(0); - fury.serialize(buffer, simpleObject); - var obj = fury.deserialize(buffer); - } - - System.out.println(StringUtils.format("[fury] [简单对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); - - // 序列化和反序列化常规对象 - startTime = System.currentTimeMillis(); - for (int i = 0; i < benchmark; i++) { - buffer.writerIndex(0); - buffer.readerIndex(0); - fury.serialize(buffer, normalObject); - var obj = fury.deserialize(buffer); - } - - System.out.println(StringUtils.format("[fury] [常规对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); - - // 序列化和反序列化复杂对象 - startTime = System.currentTimeMillis(); - for (int i = 0; i < benchmark; i++) { - buffer.writerIndex(0); - buffer.readerIndex(0); - fury.serialize(buffer, complexObject); - var obj = fury.deserialize(buffer); - } - System.out.println(StringUtils.format("[fury] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); - } +// @Test +// public void furyTest() { +// var buffer = MemoryBuffer.newHeapBuffer(1_0000); +// // 序列化和反序列化简单对象 +// long startTime = System.currentTimeMillis(); +// for (int i = 0; i < benchmark; i++) { +// buffer.writerIndex(0); +// buffer.readerIndex(0); +// fury.serialize(buffer, simpleObject); +// var obj = fury.deserialize(buffer); +// } +// +// System.out.println(StringUtils.format("[fury] [简单对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); +// +// // 序列化和反序列化常规对象 +// startTime = System.currentTimeMillis(); +// for (int i = 0; i < benchmark; i++) { +// buffer.writerIndex(0); +// buffer.readerIndex(0); +// fury.serialize(buffer, normalObject); +// var obj = fury.deserialize(buffer); +// } +// +// System.out.println(StringUtils.format("[fury] [常规对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); +// +// // 序列化和反序列化复杂对象 +// startTime = System.currentTimeMillis(); +// for (int i = 0; i < benchmark; i++) { +// buffer.writerIndex(0); +// buffer.readerIndex(0); +// fury.serialize(buffer, complexObject); +// var obj = fury.deserialize(buffer); +// } +// System.out.println(StringUtils.format("[fury] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), buffer.writerIndex(), System.currentTimeMillis() - startTime)); +// } @Test public void kryoTest() { @@ -278,17 +273,17 @@ public class BenchmarkTesting { countdown.await(); } - @Test - public void furyMultipleThreadTest() throws InterruptedException { - var countdown = new CountDownLatch(threadNum); - for (var i = 0; i < threadNum; i++) { - executors[i].execute(() -> { - furyTest(); - countdown.countDown(); - }); - } - countdown.await(); - } +// @Test +// public void furyMultipleThreadTest() throws InterruptedException { +// var countdown = new CountDownLatch(threadNum); +// for (var i = 0; i < threadNum; i++) { +// executors[i].execute(() -> { +// furyTest(); +// countdown.countDown(); +// }); +// } +// countdown.await(); +// } @Test public void kryoMultipleThreadTest() throws InterruptedException { @@ -364,21 +359,21 @@ public class BenchmarkTesting { } } - private static ThreadSafeFury fury; - - static { - fury = new ThreadLocalFury(classLoader -> { - Fury f = Fury.builder().withLanguage(Language.JAVA) - .build(); - f.register(ComplexObject.class); - f.register(NormalObject.class); - f.register(SimpleObject.class); - f.register(VeryBigObject.class); - f.register(ObjectA.class); - f.register(ObjectB.class); - return f; - }); - } +// private static ThreadSafeFury fury; +// +// static { +// fury = new ThreadLocalFury(classLoader -> { +// Fury f = Fury.builder().withLanguage(Language.JAVA) +// .build(); +// f.register(ComplexObject.class); +// f.register(NormalObject.class); +// f.register(SimpleObject.class); +// f.register(VeryBigObject.class); +// f.register(ObjectA.class); +// f.register(ObjectB.class); +// return f; +// }); +// } // -------------------------------------------以下为测试用例--------------------------------------------------------------- // 简单类型 @@ -404,10 +399,10 @@ public class BenchmarkTesting { public static final double[] doubleArray = new double[]{Double.MIN_VALUE, -99999999.9F, -99.9D, 0D, 99.9D, 99999999.9F, Double.MAX_VALUE}; public static final char[] charArray = new char[]{'a', 'b', 'c', 'd', 'e'}; public static final String[] stringArray = new String[]{"a", "b", "c", "d", "e"}; - - public static final ObjectA objectA = new ObjectA(); - public static final ObjectB objectB = new ObjectB(); public static final Map mapWithInteger = new HashMap<>(Map.of(Integer.MIN_VALUE, "a", -99, "b", 0, "c", 99, "d", Integer.MAX_VALUE, "e")); + + public static final ObjectB objectB = new ObjectB(true); + public static final ObjectA objectA = new ObjectA(Integer.MAX_VALUE, mapWithInteger, objectB); public static final List listWithInteger = new ArrayList<>(ArrayUtils.toList(intArray)); public static final List listWithInteger1 = new ArrayList<>(ArrayUtils.toList(intArray1)); public static final List listWithInteger2 = new ArrayList<>(ArrayUtils.toList(intArray2)); @@ -445,12 +440,6 @@ public class BenchmarkTesting { public static ProtobufObject.ProtobufNormalObject protobufNormalObject = null; public static ProtobufObject.ProtobufSimpleObject protobufSimpleObject = null; - static { - objectA.setA(Integer.MAX_VALUE); - objectA.setM(mapWithInteger); - objectA.setObjectB(objectB); - objectB.setFlag(false); - } static { complexObject.setA(byteValue); diff --git a/protocol/src/test/java/com/zfoo/protocol/packet/ObjectA.java b/protocol/src/test/java/com/zfoo/protocol/packet/ObjectA.java index accc0b3b..1f2f82f3 100644 --- a/protocol/src/test/java/com/zfoo/protocol/packet/ObjectA.java +++ b/protocol/src/test/java/com/zfoo/protocol/packet/ObjectA.java @@ -17,56 +17,17 @@ package com.zfoo.protocol.packet; import com.zfoo.protocol.anno.Protocol; import java.util.Map; -import java.util.Objects; /** * @author godotg */ @Protocol(id = 102) -public class ObjectA { +public record ObjectA( - private int a; + int a, - private Map m; + Map m, - private ObjectB objectB; - - public int getA() { - return a; - } - - public void setA(int a) { - this.a = a; - } - - public Map getM() { - return m; - } - - public void setM(Map m) { - this.m = m; - } - - public ObjectB getObjectB() { - return objectB; - } - - public void setObjectB(ObjectB objectB) { - this.objectB = objectB; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ObjectA objectA = (ObjectA) o; - return a == objectA.a && - Objects.equals(m, objectA.m) && - Objects.equals(objectB, objectA.objectB); - } - - @Override - public int hashCode() { - return Objects.hash(a, m, objectB); - } + ObjectB objectB +) { } diff --git a/protocol/src/test/java/com/zfoo/protocol/packet/ObjectB.java b/protocol/src/test/java/com/zfoo/protocol/packet/ObjectB.java index c2d8e754..6e4c6bef 100644 --- a/protocol/src/test/java/com/zfoo/protocol/packet/ObjectB.java +++ b/protocol/src/test/java/com/zfoo/protocol/packet/ObjectB.java @@ -16,35 +16,14 @@ package com.zfoo.protocol.packet; import com.zfoo.protocol.anno.Protocol; -import java.util.Objects; - /** * @author godotg */ @Protocol(id = 103) -public class ObjectB { +public record ObjectB( - private boolean flag; + boolean flag - public boolean isFlag() { - return flag; - } - - public void setFlag(boolean flag) { - this.flag = flag; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ObjectB objectB = (ObjectB) o; - return flag == objectB.flag; - } - - @Override - public int hashCode() { - return Objects.hash(flag); - } +) { }