Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
西红柿炒蛋不加盐
guide-rpc-framework
提交
0fe5de38
G
guide-rpc-framework
项目概览
西红柿炒蛋不加盐
/
guide-rpc-framework
与 Fork 源项目一致
Fork自
嗝屁小孩纸 / guide-rpc-framework
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
guide-rpc-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0fe5de38
编写于
3月 29, 2021
作者:
G
Guide哥
提交者:
GitHub
3月 29, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into enhancement-1
上级
f7b8d619
3aefe7b9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
11 deletion
+70
-11
rpc-framework-simple/src/main/java/github/javaguide/compress/gzip/GzipCompress.java
...ain/java/github/javaguide/compress/gzip/GzipCompress.java
+5
-6
rpc-framework-simple/src/main/java/github/javaguide/remoting/transport/netty/client/NettyRpcClient.java
...guide/remoting/transport/netty/client/NettyRpcClient.java
+4
-5
rpc-framework-simple/src/test/java/github/javaguide/compress/gzip/GzipCompressTest.java
...java/github/javaguide/compress/gzip/GzipCompressTest.java
+32
-0
rpc-framework-simple/src/test/java/github/javaguide/serialize/kyro/KryoSerializerTest.java
...a/github/javaguide/serialize/kyro/KryoSerializerTest.java
+29
-0
未找到文件。
rpc-framework-simple/src/main/java/github/javaguide/compress/gzip/GzipCompress.java
浏览文件 @
0fe5de38
...
...
@@ -13,7 +13,7 @@ import java.util.zip.GZIPOutputStream;
* @createTime on 2020/10/3
*/
public
class
GzipCompress
implements
Compress
{
public
class
GzipCompress
implements
Compress
{
private
static
final
int
BUFFER_SIZE
=
1024
*
4
;
...
...
@@ -23,8 +23,8 @@ public class GzipCompress implements Compress {
if
(
bytes
==
null
)
{
throw
new
NullPointerException
(
"bytes is null"
);
}
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
try
(
GZIPOutputStream
gzip
=
new
GZIPOutputStream
(
out
))
{
try
(
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
GZIPOutputStream
gzip
=
new
GZIPOutputStream
(
out
))
{
gzip
.
write
(
bytes
);
gzip
.
flush
();
gzip
.
finish
();
...
...
@@ -39,9 +39,8 @@ public class GzipCompress implements Compress {
if
(
bytes
==
null
)
{
throw
new
NullPointerException
(
"bytes is null"
);
}
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
try
(
GZIPInputStream
gunzip
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
bytes
)))
{
try
(
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
GZIPInputStream
gunzip
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
bytes
)))
{
byte
[]
buffer
=
new
byte
[
BUFFER_SIZE
];
int
n
;
while
((
n
=
gunzip
.
read
(
buffer
))
>
-
1
)
{
...
...
rpc-framework-simple/src/main/java/github/javaguide/remoting/transport/netty/client/NettyRpcClient.java
浏览文件 @
0fe5de38
...
...
@@ -106,11 +106,10 @@ public final class NettyRpcClient implements RpcRequestTransport {
if
(
channel
.
isActive
())
{
// put unprocessed request
unprocessedRequests
.
put
(
rpcRequest
.
getRequestId
(),
resultFuture
);
RpcMessage
rpcMessage
=
new
RpcMessage
();
rpcMessage
.
setData
(
rpcRequest
);
rpcMessage
.
setCodec
(
SerializationTypeEnum
.
PROTOSTUFF
.
getCode
());
rpcMessage
.
setCompress
(
CompressTypeEnum
.
GZIP
.
getCode
());
rpcMessage
.
setMessageType
(
RpcConstants
.
REQUEST_TYPE
);
RpcMessage
rpcMessage
=
RpcMessage
.
builder
().
data
(
rpcRequest
)
.
codec
(
SerializationTypeEnum
.
PROTOSTUFF
.
getCode
())
.
compress
(
CompressTypeEnum
.
GZIP
.
getCode
())
.
messageType
(
RpcConstants
.
REQUEST_TYPE
).
build
();
channel
.
writeAndFlush
(
rpcMessage
).
addListener
((
ChannelFutureListener
)
future
->
{
if
(
future
.
isSuccess
())
{
log
.
info
(
"client send message: [{}]"
,
rpcMessage
);
...
...
rpc-framework-simple/src/test/java/github/javaguide/compress/gzip/GzipCompressTest.java
0 → 100644
浏览文件 @
0fe5de38
package
github.javaguide.compress.gzip
;
import
github.javaguide.compress.Compress
;
import
github.javaguide.remoting.dto.RpcRequest
;
import
github.javaguide.serialize.kyro.KryoSerializer
;
import
org.junit.jupiter.api.Test
;
import
java.util.UUID
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
class
GzipCompressTest
{
@Test
void
gzipCompressTest
()
{
Compress
gzipCompress
=
new
GzipCompress
();
RpcRequest
rpcRequest
=
RpcRequest
.
builder
().
methodName
(
"hello"
)
.
parameters
(
new
Object
[]{
"sayhelooloo"
,
"sayhelooloosayhelooloo"
})
.
interfaceName
(
"github.javaguide.HelloService"
)
.
paramTypes
(
new
Class
<?>[]{
String
.
class
,
String
.
class
})
.
requestId
(
UUID
.
randomUUID
().
toString
())
.
group
(
"group1"
)
.
version
(
"version1"
)
.
build
();
KryoSerializer
kryoSerializer
=
new
KryoSerializer
();
byte
[]
rpcRequestBytes
=
kryoSerializer
.
serialize
(
rpcRequest
);
byte
[]
compressRpcRequestBytes
=
gzipCompress
.
compress
(
rpcRequestBytes
);
byte
[]
decompressRpcRequestBytes
=
gzipCompress
.
decompress
(
compressRpcRequestBytes
);
assertEquals
(
rpcRequestBytes
.
length
,
decompressRpcRequestBytes
.
length
);
}
}
\ No newline at end of file
rpc-framework-simple/src/test/java/github/javaguide/serialize/kyro/KryoSerializerTest.java
0 → 100644
浏览文件 @
0fe5de38
package
github.javaguide.serialize.kyro
;
import
github.javaguide.remoting.dto.RpcRequest
;
import
org.junit.jupiter.api.Test
;
import
java.util.UUID
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
class
KryoSerializerTest
{
@Test
void
kryoSerializerTest
()
{
RpcRequest
target
=
RpcRequest
.
builder
().
methodName
(
"hello"
)
.
parameters
(
new
Object
[]{
"sayhelooloo"
,
"sayhelooloosayhelooloo"
})
.
interfaceName
(
"github.javaguide.HelloService"
)
.
paramTypes
(
new
Class
<?>[]{
String
.
class
,
String
.
class
})
.
requestId
(
UUID
.
randomUUID
().
toString
())
.
group
(
"group1"
)
.
version
(
"version1"
)
.
build
();
KryoSerializer
kryoSerializer
=
new
KryoSerializer
();
byte
[]
bytes
=
kryoSerializer
.
serialize
(
target
);
RpcRequest
actual
=
kryoSerializer
.
deserialize
(
bytes
,
RpcRequest
.
class
);
assertEquals
(
target
.
getGroup
(),
actual
.
getGroup
());
assertEquals
(
target
.
getVersion
(),
actual
.
getVersion
());
assertEquals
(
target
.
getRequestId
(),
actual
.
getRequestId
());
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录