diff --git a/protocol/pom.xml b/protocol/pom.xml
index 82f8de32..7289a03e 100644
--- a/protocol/pom.xml
+++ b/protocol/pom.xml
@@ -197,6 +197,9 @@
8
-Dfile.encoding=${file.encoding}
+
+ */*Test.java
+
diff --git a/protocol/src/test/java/com/zfoo/protocol/SpeedTest.java b/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java
similarity index 99%
rename from protocol/src/test/java/com/zfoo/protocol/SpeedTest.java
rename to protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java
index e2b71e17..f90d4a58 100644
--- a/protocol/src/test/java/com/zfoo/protocol/SpeedTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java
@@ -45,7 +45,7 @@ import java.util.concurrent.Executors;
* @version 3.0
*/
@Ignore
-public class SpeedTest {
+public class BenchmarkTesting {
public static int benchmark = 10_0000;
diff --git a/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTest.java b/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTest.java
index cb8687a7..3df3d76e 100644
--- a/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTest.java
@@ -13,20 +13,11 @@
package com.zfoo.protocol.buffer;
-import com.zfoo.protocol.ProtocolManager;
-import com.zfoo.protocol.buffer.model.BigPacket;
-import com.zfoo.protocol.util.StringUtils;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
-import io.netty.buffer.UnpooledHeapByteBuf;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Set;
-
/**
* @author godotg
* @version 3.0
@@ -123,69 +114,4 @@ public class ByteBufUtilsTest {
Assert.assertEquals(ByteBufUtils.readCharBox(byteBuf), Character.valueOf(Character.MIN_VALUE));
}
- @Ignore
- @Test
- public void readLongSpeedTest() {
- var startTime = System.currentTimeMillis();
- long[] values = new long[]{Long.MIN_VALUE, -9999999999999999L, -9999999999999999L, -99999999, -9999, -100, -2, -1
- , 0, 1, 2, 100, 9999, 99999999, 9999999999999999L, Long.MAX_VALUE};
- ByteBuf buffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 1_0000);
- for (int i = 0; i < Integer.MAX_VALUE; i++) {
- buffer.clear();
- for (long value : values) {
- ByteBufUtils.writeLong(buffer, value);
- ByteBufUtils.readLong(buffer);
- }
- }
- System.out.println(System.currentTimeMillis() - startTime);
- }
-
-
- /**
- * 测试所有int值,运行时间太长,放弃测试
- */
- @Ignore
- @Test
- public void readIntTest() {
- ByteBuf byteBuf = Unpooled.buffer();
- for (int value = Integer.MIN_VALUE; value < Integer.MAX_VALUE; value++) {
- byteBuf.clear();
- ByteBufUtils.writeInt(byteBuf, value);
- int result = ByteBufUtils.readInt(byteBuf);
- Assert.assertEquals(result, value);
- }
- }
-
-
- @Ignore
- @Test
- public void readLongTest() {
- ByteBuf byteBuf = Unpooled.buffer();
- for (long value = Long.MIN_VALUE; value < Long.MAX_VALUE; value++) {
- byteBuf.clear();
- ByteBufUtils.writeLong(byteBuf, value);
- Assert.assertEquals(ByteBufUtils.readLong(byteBuf), value);
- }
- }
-
- @Ignore
- @Test
- public void bigDataTest() {
- ProtocolManager.initProtocol(Set.of(BigPacket.class));
-
- var bigPact = new BigPacket();
- Arrays.fill(bigPact.a, 99);
-
- var buffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 100_0000);
-
- long startTime = System.currentTimeMillis();
- for (int i = 0; i < 10_0000; i++) {
- buffer.clear();
- ProtocolManager.write(buffer, bigPact);
- var newPacket = ProtocolManager.read(buffer);
- }
-
- System.out.println(StringUtils.format("[zfoo][size:{}] [time:{}]", buffer.writerIndex(), System.currentTimeMillis() - startTime));
- }
-
}
diff --git a/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTesting.java b/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTesting.java
new file mode 100644
index 00000000..8eb05512
--- /dev/null
+++ b/protocol/src/test/java/com/zfoo/protocol/buffer/ByteBufUtilsTesting.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2020 The zfoo Authors
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ */
+
+package com.zfoo.protocol.buffer;
+
+import com.zfoo.protocol.ProtocolManager;
+import com.zfoo.protocol.buffer.model.BigPacket;
+import com.zfoo.protocol.util.StringUtils;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.buffer.Unpooled;
+import io.netty.buffer.UnpooledHeapByteBuf;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Set;
+
+/**
+ * @author godotg
+ * @version 3.0
+ */
+@Ignore
+public class ByteBufUtilsTesting {
+
+ @Ignore
+ @Test
+ public void readLongSpeedTest() {
+ var startTime = System.currentTimeMillis();
+ long[] values = new long[]{Long.MIN_VALUE, -9999999999999999L, -9999999999999999L, -99999999, -9999, -100, -2, -1
+ , 0, 1, 2, 100, 9999, 99999999, 9999999999999999L, Long.MAX_VALUE};
+ ByteBuf buffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 1_0000);
+ for (int i = 0; i < Integer.MAX_VALUE; i++) {
+ buffer.clear();
+ for (long value : values) {
+ ByteBufUtils.writeLong(buffer, value);
+ ByteBufUtils.readLong(buffer);
+ }
+ }
+ System.out.println(System.currentTimeMillis() - startTime);
+ }
+
+
+ /**
+ * 测试所有int值,运行时间太长,放弃测试
+ */
+ @Ignore
+ @Test
+ public void readIntTest() {
+ ByteBuf byteBuf = Unpooled.buffer();
+ for (int value = Integer.MIN_VALUE; value < Integer.MAX_VALUE; value++) {
+ byteBuf.clear();
+ ByteBufUtils.writeInt(byteBuf, value);
+ int result = ByteBufUtils.readInt(byteBuf);
+ Assert.assertEquals(result, value);
+ }
+ }
+
+
+ @Ignore
+ @Test
+ public void readLongTest() {
+ ByteBuf byteBuf = Unpooled.buffer();
+ for (long value = Long.MIN_VALUE; value < Long.MAX_VALUE; value++) {
+ byteBuf.clear();
+ ByteBufUtils.writeLong(byteBuf, value);
+ Assert.assertEquals(ByteBufUtils.readLong(byteBuf), value);
+ }
+ }
+
+ @Ignore
+ @Test
+ public void bigDataTest() {
+ ProtocolManager.initProtocol(Set.of(BigPacket.class));
+
+ var bigPact = new BigPacket();
+ Arrays.fill(bigPact.a, 99);
+
+ var buffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 100_0000);
+
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < 10_0000; i++) {
+ buffer.clear();
+ ProtocolManager.write(buffer, bigPact);
+ var newPacket = ProtocolManager.read(buffer);
+ }
+
+ System.out.println(StringUtils.format("[zfoo][size:{}] [time:{}]", buffer.writerIndex(), System.currentTimeMillis() - startTime));
+ }
+
+}
diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java
similarity index 99%
rename from protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTest.java
rename to protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java
index 205f6b81..02fe8bfd 100644
--- a/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/collection/ConcurrentTesting.java
@@ -25,7 +25,7 @@ import java.util.concurrent.CountDownLatch;
* @version 3.0
*/
@Ignore
-public class ConcurrentTest {
+public class ConcurrentTesting {
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentFileChannelMapTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentFileChannelMapTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentFileChannelMapTest.java
rename to protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentFileChannelMapTesting.java
index 67c0aead..e7548cef 100644
--- a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentFileChannelMapTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentFileChannelMapTesting.java
@@ -28,7 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* @version 3.0
*/
@Ignore
-public class ConcurrentFileChannelMapTest {
+public class ConcurrentFileChannelMapTesting {
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentHeapMapTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentHeapMapTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentHeapMapTest.java
rename to protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentHeapMapTesting.java
index e690dfba..79b02218 100644
--- a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentHeapMapTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/ConcurrentHeapMapTesting.java
@@ -28,7 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* @version 3.0
*/
@Ignore
-public class ConcurrentHeapMapTest {
+public class ConcurrentHeapMapTesting {
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileChannelMapTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileChannelMapTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileChannelMapTest.java
rename to protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileChannelMapTesting.java
index d93f6b0a..e6f4ad47 100644
--- a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileChannelMapTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileChannelMapTesting.java
@@ -26,7 +26,7 @@ import java.util.Set;
* @version 3.0
*/
@Ignore
-public class FileChannelMapTest {
+public class FileChannelMapTesting {
@Test
public void test() {
diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileHeapMapTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileHeapMapTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileHeapMapTest.java
rename to protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileHeapMapTesting.java
index d9d309a4..a143b971 100644
--- a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileHeapMapTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/FileHeapMapTesting.java
@@ -25,7 +25,7 @@ import java.util.Set;
* @version 3.0
*/
@Ignore
-public class FileHeapMapTest {
+public class FileHeapMapTesting {
@Test
public void test() {
diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/HeapMapTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/HeapMapTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/collection/lpmap/HeapMapTest.java
rename to protocol/src/test/java/com/zfoo/protocol/collection/lpmap/HeapMapTesting.java
index 15cdfcaf..bc71e3eb 100644
--- a/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/HeapMapTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/collection/lpmap/HeapMapTesting.java
@@ -22,7 +22,7 @@ import org.junit.Test;
* @version 3.0
*/
@Ignore
-public class HeapMapTest {
+public class HeapMapTesting {
@Test
public void test() {
diff --git a/protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatiblityTest.java b/protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatibilityTesting.java
similarity index 95%
rename from protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatiblityTest.java
rename to protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatibilityTesting.java
index 474090eb..118325dd 100644
--- a/protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatiblityTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/compatiblity/CompatibilityTesting.java
@@ -26,13 +26,14 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Set;
-import static com.zfoo.protocol.SpeedTest.complexObject;
-import static com.zfoo.protocol.SpeedTest.normalObject;
+import static com.zfoo.protocol.BenchmarkTesting.complexObject;
+import static com.zfoo.protocol.BenchmarkTesting.normalObject;
/**
* @author godotg
*/
-public class CompatiblityTest {
+@Ignore
+public class CompatibilityTesting {
/**
* EN: The order of the bytecode-enhanced Map traversal order will be different, so the order of the serialized content will change.
@@ -40,7 +41,6 @@ public class CompatiblityTest {
*
* CN: 字节码增强的Map遍历顺序会出现不一样,所以序列化的内容顺序会改变,可以看到不相同的字节并不是连续的
*/
- @Ignore
@Test
public void compatiblityTest() throws IOException {
ProtocolManager.initProtocolAuto(Set.of(ComplexObject.class, NormalObject.class, SimpleObject.class, EmptyObject.class, VeryBigObject.class), GenerateOperation.NO_OPERATION);
diff --git a/protocol/src/test/java/com/zfoo/protocol/field/FieldSpeedTest.java b/protocol/src/test/java/com/zfoo/protocol/field/FieldSpeedTesting.java
similarity index 99%
rename from protocol/src/test/java/com/zfoo/protocol/field/FieldSpeedTest.java
rename to protocol/src/test/java/com/zfoo/protocol/field/FieldSpeedTesting.java
index a5e8258b..e5f33c3c 100644
--- a/protocol/src/test/java/com/zfoo/protocol/field/FieldSpeedTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/field/FieldSpeedTesting.java
@@ -26,7 +26,7 @@ import java.util.*;
* 细致比较性能
*/
@Ignore
-public class FieldSpeedTest {
+public class FieldSpeedTesting {
public static int benchmark = 100000;
public static IntObject intObject = new IntObject();
public static IntegerObject integerObject = new IntegerObject();
diff --git a/protocol/src/test/java/com/zfoo/protocol/generate/GenerateTest.java b/protocol/src/test/java/com/zfoo/protocol/generate/GenerateTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/generate/GenerateTest.java
rename to protocol/src/test/java/com/zfoo/protocol/generate/GenerateTesting.java
index 91b0bcbb..6365311d 100644
--- a/protocol/src/test/java/com/zfoo/protocol/generate/GenerateTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/generate/GenerateTesting.java
@@ -24,7 +24,7 @@ import java.util.Set;
* @author godotg
*/
@Ignore
-public class GenerateTest {
+public class GenerateTesting {
@Test
public void generateAllProtocols() {
diff --git a/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTest.java b/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTest.java
index 8f10db1f..134783db 100644
--- a/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTest.java
@@ -20,101 +20,13 @@ import org.junit.Test;
import java.lang.reflect.Modifier;
import java.lang.reflect.*;
-/*
- 测试javassist生成的类和普通用new关键字创建出来的类之间的区别
- 测试发现两者从访问方法和访问变量的速度几乎没有什么区别,可以用javassist代理其它的类,不会影响速度
- */
-
public class JavassistTest {
-
-
public static final int INTERVAL_TIME = 1000;
public static final int A_CONSTANT = 99999;
public static final int B_CONSTANT = 888888888;
public static final int C_CONSTANT = 7777777;
- public static final int INT_CONSTANT = 999999;
-
-
- /**
- * 直接访问public的访问速度
- */
- public void testA() {
- A a = new A();
-
- long start = System.currentTimeMillis();
- long count = 0;
- while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
- a.a = A_CONSTANT;
- a.b = B_CONSTANT;
- a.c = C_CONSTANT;
- count++;
- }
-
- System.out.println(count);
- }
-
- /**
- * 用get和set方法访问成员变量的速度
- */
- public void testB() {
- B b = new B();
-
- long start = System.currentTimeMillis();
- long count = 0;
- while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
- b.setA(A_CONSTANT);
- b.setB(B_CONSTANT);
- b.setC(C_CONSTANT);
- count++;
- }
-
- System.out.println(count);
- }
-
- /*
- 通过反射直接操作属性访问变量的速度
- */
- public void testC() throws NoSuchFieldException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
- Field aField = C.class.getDeclaredField("a");
- aField.setAccessible(true);
- Field bField = C.class.getDeclaredField("b");
- bField.setAccessible(true);
- Field cField = C.class.getDeclaredField("c");
- cField.setAccessible(true);
-
- Method aSetMethod = C.class.getDeclaredMethod("setA", int.class);
- aSetMethod.setAccessible(true);
- Method bSetMethod = C.class.getDeclaredMethod("setB", int.class);
- bSetMethod.setAccessible(true);
- Method cSetMethod = C.class.getDeclaredMethod("setC", int.class);
- cSetMethod.setAccessible(true);
-
- Constructor> constructor = C.class.getDeclaredConstructor(null);
- constructor.setAccessible(true);
- C c = (C) constructor.newInstance(null);
-
- long start = System.currentTimeMillis();
- long count = 0;
- while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
- //C c = C.class.newInstance();
- aField.set(c, A_CONSTANT);
- bField.set(c, B_CONSTANT);
- cField.set(c, C_CONSTANT);
- // aSetMethod.invoke(c, A_CONSTANT);
- // bSetMethod.invoke(c, B_CONSTANT);
- // cSetMethod.invoke(c, C_CONSTANT);
- count++;
- }
-
- System.out.println(count);
- }
-
- /*
- 通过javassist访问成员变量的速度
- */
- @Ignore
@Test
public void testD() throws NotFoundException, CannotCompileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
ClassPool classPool = ClassPool.getDefault();
@@ -182,38 +94,15 @@ public class JavassistTest {
ctClass.addMethod(cSetMethod);
Class> clazz = ctClass.toClass(IDGet.class);
- Constructor> constructor = clazz.getConstructor(null);
- IDGet d = (IDGet) constructor.newInstance(null);
+ Constructor> constructor = clazz.getConstructor();
+ IDGet d = (IDGet) constructor.newInstance();
- long start = System.currentTimeMillis();
- long count = 0;
- while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
- d.setA(A_CONSTANT);
- d.setB(B_CONSTANT);
- d.setC(C_CONSTANT);
- count++;
- }
-
- System.out.println(count);
-
- // d.setA(A_CONSTANT);
- // System.out.println(d.getA());
- // d.setB(B_CONSTANT);
- // System.out.println(d.getB());
- // d.setC(C_CONSTANT);
- // System.out.println(d.getC());
+ d.setA(A_CONSTANT);
+ d.setB(B_CONSTANT);
+ d.setC(C_CONSTANT);
}
- @Ignore
- @Test
- public void testAll() throws NoSuchMethodException, IllegalAccessException, InstantiationException, CannotCompileException, NotFoundException, InvocationTargetException, NoSuchFieldException {
- testA();
- testB();
- testC();
- testD();
- }
-
}
diff --git a/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTesting.java b/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTesting.java
new file mode 100644
index 00000000..d3e0a743
--- /dev/null
+++ b/protocol/src/test/java/com/zfoo/protocol/javassist/JavassistTesting.java
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2020 The zfoo Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ */
+
+package com.zfoo.protocol.javassist;
+
+import javassist.*;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.*;
+
+/*
+ 测试javassist生成的类和普通用new关键字创建出来的类之间的区别
+ 测试发现两者从访问方法和访问变量的速度几乎没有什么区别,可以用javassist代理其它的类,不会影响速度
+ */
+@Ignore
+public class JavassistTesting {
+
+
+ public static final int INTERVAL_TIME = 1000;
+
+ public static final int A_CONSTANT = 99999;
+ public static final int B_CONSTANT = 888888888;
+ public static final int C_CONSTANT = 7777777;
+
+
+
+ /**
+ * 直接访问public的访问速度
+ */
+ public void testA() {
+ A a = new A();
+
+ long start = System.currentTimeMillis();
+ long count = 0;
+ while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
+ a.a = A_CONSTANT;
+ a.b = B_CONSTANT;
+ a.c = C_CONSTANT;
+ count++;
+ }
+
+ System.out.println(count);
+ }
+
+ /**
+ * 用get和set方法访问成员变量的速度
+ */
+ public void testB() {
+ B b = new B();
+
+ long start = System.currentTimeMillis();
+ long count = 0;
+ while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
+ b.setA(A_CONSTANT);
+ b.setB(B_CONSTANT);
+ b.setC(C_CONSTANT);
+ count++;
+ }
+
+ System.out.println(count);
+ }
+
+ /*
+ 通过反射直接操作属性访问变量的速度
+ */
+ public void testC() throws NoSuchFieldException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
+ Field aField = C.class.getDeclaredField("a");
+ aField.setAccessible(true);
+ Field bField = C.class.getDeclaredField("b");
+ bField.setAccessible(true);
+ Field cField = C.class.getDeclaredField("c");
+ cField.setAccessible(true);
+
+ Method aSetMethod = C.class.getDeclaredMethod("setA", int.class);
+ aSetMethod.setAccessible(true);
+ Method bSetMethod = C.class.getDeclaredMethod("setB", int.class);
+ bSetMethod.setAccessible(true);
+ Method cSetMethod = C.class.getDeclaredMethod("setC", int.class);
+ cSetMethod.setAccessible(true);
+
+ Constructor> constructor = C.class.getDeclaredConstructor();
+ constructor.setAccessible(true);
+ C c = (C) constructor.newInstance();
+
+ long start = System.currentTimeMillis();
+ long count = 0;
+ while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
+ //C c = C.class.newInstance();
+ aField.set(c, A_CONSTANT);
+ bField.set(c, B_CONSTANT);
+ cField.set(c, C_CONSTANT);
+ // aSetMethod.invoke(c, A_CONSTANT);
+ // bSetMethod.invoke(c, B_CONSTANT);
+ // cSetMethod.invoke(c, C_CONSTANT);
+ count++;
+ }
+
+ System.out.println(count);
+ }
+
+ /*
+ 通过javassist访问成员变量的速度
+ */
+ @Test
+ public void testD() throws NotFoundException, CannotCompileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
+ ClassPool classPool = ClassPool.getDefault();
+
+ CtClass ctClass = classPool.makeClass("com.zfoo.protocol.javassist.DGetClass");
+
+ ctClass.addInterface(classPool.get(IDGet.class.getCanonicalName()));
+
+ CtField a = new CtField(classPool.get(int.class.getCanonicalName()), "a", ctClass);
+ a.setModifiers(Modifier.PRIVATE);
+ ctClass.addField(a);
+
+ CtField b = new CtField(classPool.get(int.class.getCanonicalName()), "b", ctClass);
+ b.setModifiers(Modifier.PRIVATE);
+ ctClass.addField(b);
+
+ CtField c = new CtField(classPool.get(int.class.getCanonicalName()), "c", ctClass);
+ c.setModifiers(Modifier.PRIVATE);
+ ctClass.addField(c);
+
+ CtConstructor ctConstructor = new CtConstructor(null, ctClass);
+ ctConstructor.setBody("{}");
+ ctClass.addConstructor(ctConstructor);
+
+ CtMethod aGetMethod = new CtMethod(classPool.get(int.class.getCanonicalName()), "getA", null, ctClass);
+ aGetMethod.setModifiers(Modifier.PUBLIC);
+ StringBuilder aGetBuilder = new StringBuilder();
+ aGetBuilder.append("{return this.a;}");
+ aGetMethod.setBody(aGetBuilder.toString());
+ ctClass.addMethod(aGetMethod);
+
+ CtMethod aSetMethod = new CtMethod(classPool.get(void.class.getCanonicalName()), "setA", classPool.get(new String[]{int.class.getCanonicalName()}), ctClass);
+ aGetMethod.setModifiers(Modifier.PUBLIC);
+ StringBuilder aSetBuilder = new StringBuilder();
+ aSetBuilder.append("{this.a=$1;}");
+ aSetMethod.setBody(aSetBuilder.toString());
+ ctClass.addMethod(aSetMethod);
+
+ CtMethod bGetMethod = new CtMethod(classPool.get(int.class.getCanonicalName()), "getB", null, ctClass);
+ bGetMethod.setModifiers(Modifier.PUBLIC);
+ StringBuilder bGetBuilder = new StringBuilder();
+ bGetBuilder.append("{return this.b;}");
+ bGetMethod.setBody(bGetBuilder.toString());
+ ctClass.addMethod(bGetMethod);
+
+ CtMethod bSetMethod = new CtMethod(classPool.get(void.class.getCanonicalName()), "setB", classPool.get(new String[]{int.class.getCanonicalName()}), ctClass);
+ aGetMethod.setModifiers(Modifier.PUBLIC);
+ StringBuilder bSetBuilder = new StringBuilder();
+ bSetBuilder.append("{this.b=$1;}");
+ bSetMethod.setBody(bSetBuilder.toString());
+ ctClass.addMethod(bSetMethod);
+
+ CtMethod cGetMethod = new CtMethod(classPool.get(int.class.getCanonicalName()), "getC", null, ctClass);
+ cGetMethod.setModifiers(Modifier.PUBLIC);
+ StringBuilder cGetBuilder = new StringBuilder();
+ cGetBuilder.append("{return this.c;}");
+ cGetMethod.setBody(cGetBuilder.toString());
+ ctClass.addMethod(cGetMethod);
+
+ CtMethod cSetMethod = new CtMethod(classPool.get(void.class.getCanonicalName()), "setC", classPool.get(new String[]{int.class.getCanonicalName()}), ctClass);
+ aGetMethod.setModifiers(Modifier.PUBLIC);
+ StringBuilder cSetBuilder = new StringBuilder();
+ cSetBuilder.append("{this.c=$1;}");
+ cSetMethod.setBody(cSetBuilder.toString());
+ ctClass.addMethod(cSetMethod);
+
+ Class> clazz = ctClass.toClass(IDGet.class);
+ Constructor> constructor = clazz.getConstructor();
+ IDGet d = (IDGet) constructor.newInstance();
+
+ long start = System.currentTimeMillis();
+ long count = 0;
+ while (System.currentTimeMillis() - start <= INTERVAL_TIME) {
+ d.setA(A_CONSTANT);
+ d.setB(B_CONSTANT);
+ d.setC(C_CONSTANT);
+ count++;
+ }
+
+ System.out.println(count);
+
+ // d.setA(A_CONSTANT);
+ // System.out.println(d.getA());
+ // d.setB(B_CONSTANT);
+ // System.out.println(d.getB());
+ // d.setC(C_CONSTANT);
+ // System.out.println(d.getC());
+ }
+
+
+ @Test
+ public void testAll() throws NoSuchMethodException, IllegalAccessException, InstantiationException, CannotCompileException, NotFoundException, InvocationTargetException, NoSuchFieldException {
+ testA();
+ testB();
+ testC();
+ testD();
+ }
+
+}
+
diff --git a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/JProtobufTest.java b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/JProtobufTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/jprotobuf/JProtobufTest.java
rename to protocol/src/test/java/com/zfoo/protocol/jprotobuf/JProtobufTesting.java
index d07d25f7..43634a4b 100644
--- a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/JProtobufTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/JProtobufTesting.java
@@ -31,7 +31,7 @@ import java.util.Set;
* @version 3.0
*/
@Ignore
-public class JProtobufTest {
+public class JProtobufTesting {
private static final Map mapWithInteger = new HashMap<>(Map.of(Integer.MIN_VALUE, "a", -99, "b", 0, "c", 99, "d", Integer.MAX_VALUE, "e"));
diff --git a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java
rename to protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTesting.java
index 881a179f..3aa8b1d6 100644
--- a/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/jprotobuf/ProtobufTagTesting.java
@@ -26,7 +26,7 @@ import java.io.IOException;
* @version 3.0
*/
@Ignore
-public class ProtobufTagTest {
+public class ProtobufTagTesting {
@Test
public void test() throws IOException {
diff --git a/protocol/src/test/java/com/zfoo/protocol/packet/VeryBigObject.java b/protocol/src/test/java/com/zfoo/protocol/packet/VeryBigObject.java
index 292131f0..a882b5b6 100644
--- a/protocol/src/test/java/com/zfoo/protocol/packet/VeryBigObject.java
+++ b/protocol/src/test/java/com/zfoo/protocol/packet/VeryBigObject.java
@@ -27,7 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static com.zfoo.protocol.SpeedTest.*;
+import static com.zfoo.protocol.BenchmarkTesting.*;
/**
* 主要来测试极端大的对象序列化和反序列化情况,极端大的对象指的是字段多,对象大,方法大
diff --git a/protocol/src/test/java/com/zfoo/protocol/util/ClassUtilsTest.java b/protocol/src/test/java/com/zfoo/protocol/util/ClassUtilsTesting.java
similarity index 96%
rename from protocol/src/test/java/com/zfoo/protocol/util/ClassUtilsTest.java
rename to protocol/src/test/java/com/zfoo/protocol/util/ClassUtilsTesting.java
index 7430c322..8fddb406 100644
--- a/protocol/src/test/java/com/zfoo/protocol/util/ClassUtilsTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/util/ClassUtilsTesting.java
@@ -24,11 +24,11 @@ import java.io.IOException;
* @version 3.0
*/
@Ignore
-public class ClassUtilsTest {
+public class ClassUtilsTesting {
@Test
public void getClassPath() {
- System.out.println(ClassUtils.getClassAbsPath(ClassUtilsTest.class));
+ System.out.println(ClassUtils.getClassAbsPath(ClassUtilsTesting.class));
}
@Test
diff --git a/protocol/src/test/java/com/zfoo/protocol/util/FileUtilTest.java b/protocol/src/test/java/com/zfoo/protocol/util/FileUtilTesting.java
similarity index 98%
rename from protocol/src/test/java/com/zfoo/protocol/util/FileUtilTest.java
rename to protocol/src/test/java/com/zfoo/protocol/util/FileUtilTesting.java
index e0e84250..56d83b6f 100644
--- a/protocol/src/test/java/com/zfoo/protocol/util/FileUtilTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/util/FileUtilTesting.java
@@ -25,7 +25,7 @@ import java.util.List;
* @version 3.0
*/
@Ignore
-public class FileUtilTest {
+public class FileUtilTesting {
@Test
public void absPathTest() {
diff --git a/protocol/src/test/java/com/zfoo/protocol/util/ReflectUtilTest.java b/protocol/src/test/java/com/zfoo/protocol/util/ReflectUtilTesting.java
similarity index 97%
rename from protocol/src/test/java/com/zfoo/protocol/util/ReflectUtilTest.java
rename to protocol/src/test/java/com/zfoo/protocol/util/ReflectUtilTesting.java
index 785e1c2d..0a91fee6 100644
--- a/protocol/src/test/java/com/zfoo/protocol/util/ReflectUtilTest.java
+++ b/protocol/src/test/java/com/zfoo/protocol/util/ReflectUtilTesting.java
@@ -29,7 +29,7 @@ import java.util.function.Predicate;
@Ignore
-public class ReflectUtilTest {
+public class ReflectUtilTesting {
@Test
public void testGetFieldsByAnnotation() {