-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
219 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package grpc; /** | ||
* @author: 風楪 | ||
* @date: 2024/9/19 22:20 | ||
*/ | ||
|
||
/** | ||
* @author: FengYe | ||
* @date: 2024/9/19 22:20 | ||
* @description: grpc.GrpcTest | ||
*/ | ||
public class GrpcTest { | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
arthas-grpc-server/src/test/java/protobuf/ProtoBufTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package protobuf; /** | ||
* @author: 風楪 | ||
* @date: 2024/9/19 22:35 | ||
*/ | ||
|
||
import com.taobao.arthas.grpc.server.protobuf.ProtobufCodec; | ||
import com.taobao.arthas.grpc.server.protobuf.ProtobufProxy; | ||
import com.taobao.arthas.grpc.server.service.req.ArthasSampleRequest; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author: FengYe | ||
* @date: 2024/9/19 22:35 | ||
* @description: protobuf.ProtoBufTest | ||
*/ | ||
public class ProtoBufTest { | ||
@Test | ||
public void testEncodeAndDecode() { | ||
ProtoBufTestReq protoBufTestReq = new ProtoBufTestReq(); | ||
protoBufTestReq.setName("test"); | ||
protoBufTestReq.setAge(18); | ||
protoBufTestReq.setPrice(100L); | ||
protoBufTestReq.setStatus(ArthasSampleRequest.StatusEnum.START); | ||
List<ProtoBufTestReq.TestClass> list = new ArrayList<>(); | ||
list.add(new ProtoBufTestReq.TestClass("test1")); | ||
list.add(new ProtoBufTestReq.TestClass("test2")); | ||
list.add(new ProtoBufTestReq.TestClass("test3")); | ||
Map<String,String> map = new HashMap<>(); | ||
map.put("key1","value1"); | ||
map.put("key2","value2"); | ||
map.put("key3","value3"); | ||
protoBufTestReq.setTestList(list); | ||
protoBufTestReq.setTestMap(map); | ||
|
||
try { | ||
ProtobufCodec<ProtoBufTestReq> protobufCodec = ProtobufProxy.getCodecCacheSide(ProtoBufTestReq.class); | ||
byte[] encode = protobufCodec.encode(protoBufTestReq); | ||
ProtoBufTestReq decode = protobufCodec.decode(encode); | ||
Assert.assertEquals(protoBufTestReq.toString(), decode.toString()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
arthas-grpc-server/src/test/java/protobuf/ProtoBufTestReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package protobuf;/** | ||
* @author: 風楪 | ||
* @date: 2024/9/19 22:38 | ||
*/ | ||
|
||
import com.taobao.arthas.grpc.server.protobuf.annotation.ProtobufClass; | ||
import com.taobao.arthas.grpc.server.service.req.ArthasSampleRequest; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author: FengYe | ||
* @date: 2024/9/19 22:38 | ||
* @description: ProtoBufTestReq | ||
*/ | ||
@ProtobufClass | ||
public class ProtoBufTestReq { | ||
private String name; | ||
private double age; | ||
private long price; | ||
private ArthasSampleRequest.StatusEnum status; | ||
private List<TestClass> testList; | ||
private Map<String, String> testMap; | ||
|
||
@ProtobufClass | ||
public enum StatusEnum { | ||
START(1, "开始"), | ||
STOP(2, "结束"); | ||
|
||
StatusEnum(int code, String desc) { | ||
this.code = code; | ||
this.desc = desc; | ||
} | ||
|
||
private int code; | ||
private String desc; | ||
} | ||
|
||
@ProtobufClass | ||
public static class TestClass { | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
// 注意被 @ProtobufClass 注解的 class 必须添加无参构造函数 | ||
public TestClass() { | ||
} | ||
|
||
public TestClass(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TestClass{" + | ||
"name='" + name + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
public List<TestClass> getTestList() { | ||
return testList; | ||
} | ||
|
||
public void setTestList(List<TestClass> testList) { | ||
this.testList = testList; | ||
} | ||
|
||
public ArthasSampleRequest.StatusEnum getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(ArthasSampleRequest.StatusEnum status) { | ||
this.status = status; | ||
} | ||
|
||
public long getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(long price) { | ||
this.price = price; | ||
} | ||
|
||
public double getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(double age) { | ||
this.age = age; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Map<String, String> getTestMap() { | ||
return testMap; | ||
} | ||
|
||
public void setTestMap(Map<String, String> testMap) { | ||
this.testMap = testMap; | ||
} | ||
|
||
@Override | ||
public java.lang.String toString() { | ||
return "ProtoBufTestReq{" + | ||
"name='" + name + '\'' + | ||
", age=" + age + | ||
", price=" + price + | ||
", status=" + status + | ||
", testList=" + testList + | ||
", testMap=" + testMap + | ||
'}'; | ||
} | ||
} | ||
|