Skip to content

Commit

Permalink
del[protocol]: remove fury test, record not support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Sep 22, 2023
1 parent ce9cc21 commit bbcae91
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 158 deletions.
26 changes: 13 additions & 13 deletions protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>5.3.0</version>
<version>5.5.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.furyio</groupId>
<artifactId>fury-core</artifactId>
<version>0.1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.furyio</groupId>-->
<!-- <artifactId>fury-core</artifactId>-->
<!-- <version>0.1.0</version>-->
<!-- <scope>test</scope>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <artifactId>slf4j-api</artifactId>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->

<dependency>
<groupId>junit</groupId>
Expand Down
143 changes: 66 additions & 77 deletions protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
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;
Expand Down Expand Up @@ -68,7 +63,7 @@ public void singleThreadBenchmarks() {
System.out.println(StringUtils.format("[单线程性能测试-->[benchmark:{}]]", benchmark));

zfooTest();
furyTest();
// furyTest();
protobufTest();
kryoTest();

Expand All @@ -90,7 +85,7 @@ public void multipleThreadBenchmarks() throws InterruptedException {
System.out.println(StringUtils.format("[多线程性能测试-->[benchmark:{}]]", benchmark));

zfooMultipleThreadTest();
furyMultipleThreadTest();
// furyMultipleThreadTest();
protobufMultipleThreadTest();
kryoMultipleThreadTest();

Expand Down Expand Up @@ -142,41 +137,41 @@ public void zfooTest() {
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() {
Expand Down Expand Up @@ -278,17 +273,17 @@ public void zfooMultipleThreadTest() throws InterruptedException {
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 {
Expand Down Expand Up @@ -364,21 +359,21 @@ protected Kryo initialValue() {
}
}

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;
// });
// }

// -------------------------------------------以下为测试用例---------------------------------------------------------------
// 简单类型
Expand All @@ -404,10 +399,10 @@ protected Kryo initialValue() {
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<Integer, String> 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<Integer> listWithInteger = new ArrayList<>(ArrayUtils.toList(intArray));
public static final List<Integer> listWithInteger1 = new ArrayList<>(ArrayUtils.toList(intArray1));
public static final List<Integer> listWithInteger2 = new ArrayList<>(ArrayUtils.toList(intArray2));
Expand Down Expand Up @@ -445,12 +440,6 @@ protected Kryo initialValue() {
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);
Expand Down
49 changes: 5 additions & 44 deletions protocol/src/test/java/com/zfoo/protocol/packet/ObjectA.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,17 @@
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<Integer, String> m;
Map<Integer, String> m,

private ObjectB objectB;

public int getA() {
return a;
}

public void setA(int a) {
this.a = a;
}

public Map<Integer, String> getM() {
return m;
}

public void setM(Map<Integer, String> 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
) {
}
27 changes: 3 additions & 24 deletions protocol/src/test/java/com/zfoo/protocol/packet/ObjectB.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,14 @@

import com.zfoo.protocol.anno.Protocol;

import java.util.Objects;

/**
* @author godotg
*/
@Protocol(id = 103)
public class ObjectB {

private boolean flag;

public boolean isFlag() {
return flag;
}

public void setFlag(boolean flag) {
this.flag = flag;
}
public record ObjectB(

@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;
}
boolean flag

@Override
public int hashCode() {
return Objects.hash(flag);
}
) {
}

0 comments on commit bbcae91

Please sign in to comment.