Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
09d3d241
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
09d3d241
编写于
9月 27, 2019
作者:
K
KomachiSion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unit test for MySQLCommandPacketDecoder
上级
1998cc16
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
129 addition
and
33 deletion
+129
-33
src/main/java/info/avalon566/shardingscaling/sync/mysql/binlog/codec/MySQLBinlogEventPacketDecoder.java
...ync/mysql/binlog/codec/MySQLBinlogEventPacketDecoder.java
+2
-2
src/main/java/info/avalon566/shardingscaling/sync/postgresql/PostgreSQLReader.java
...566/shardingscaling/sync/postgresql/PostgreSQLReader.java
+0
-31
src/test/java/info/avalon566/shardingscaling/sync/mysql/binlog/codec/MySQLCommandPacketDecoderTest.java
...ync/mysql/binlog/codec/MySQLCommandPacketDecoderTest.java
+127
-0
未找到文件。
src/main/java/info/avalon566/shardingscaling/sync/mysql/binlog/codec/MySQLBinlogEventPacketDecoder.java
浏览文件 @
09d3d241
...
...
@@ -39,8 +39,8 @@ public final class MySQLBinlogEventPacketDecoder extends ByteToMessageDecoder {
in
.
readByte
();
BinlogEventHeader
eventHeader
=
new
BinlogEventHeader
();
eventHeader
.
fromBytes
(
in
);
log
.
info
(
Byte
.
toString
(
eventHeader
.
getTypeCode
()));
log
.
info
(
Short
.
toString
(
eventHeader
.
getTypeCode
()));
log
.
info
(
"readable:{},length:{}"
,
in
.
readableBytes
(),
eventHeader
.
getEventLength
()
-
19
);
in
.
readBytes
(
eventHeader
.
getEventLength
()
-
19
);
//
in.readBytes(eventHeader.getEventLength() - 19);
}
}
src/main/java/info/avalon566/shardingscaling/sync/postgresql/PostgreSQLReader.java
已删除
100755 → 0
浏览文件 @
1998cc16
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
info.avalon566.shardingscaling.sync.postgresql
;
import
info.avalon566.shardingscaling.sync.core.RdbmsConfiguration
;
import
info.avalon566.shardingscaling.sync.jdbc.AbstractJdbcReader
;
/**
* @author avalon566
*/
public
class
PostgreSQLReader
extends
AbstractJdbcReader
{
public
PostgreSQLReader
(
RdbmsConfiguration
rdbmsConfiguration
)
{
super
(
rdbmsConfiguration
);
}
}
\ No newline at end of file
src/test/java/info/avalon566/shardingscaling/sync/mysql/binlog/codec/MySQLCommandPacketDecoderTest.java
0 → 100644
浏览文件 @
09d3d241
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
info.avalon566.shardingscaling.sync.mysql.binlog.codec
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
info.avalon566.shardingscaling.sync.mysql.binlog.packet.auth.HandshakeInitializationPacket
;
import
info.avalon566.shardingscaling.sync.mysql.binlog.packet.response.ErrorPacket
;
import
info.avalon566.shardingscaling.sync.mysql.binlog.packet.response.InternalResultSet
;
import
info.avalon566.shardingscaling.sync.mysql.binlog.packet.response.OkPacket
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBufUtil
;
import
io.netty.buffer.Unpooled
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MySQLCommandPacketDecoderTest
{
@Mock
private
ByteBuf
byteBuf
;
@Test
(
expected
=
UnsupportedOperationException
.
class
)
public
void
assertDecodeUnsupportedProtocolVersion
()
{
MySQLCommandPacketDecoder
commandPacketDecoder
=
new
MySQLCommandPacketDecoder
();
commandPacketDecoder
.
decode
(
null
,
byteBuf
,
null
);
}
@Test
(
expected
=
UnsupportedOperationException
.
class
)
public
void
assertDecodeUnsupportedAuthenticationMethod
()
{
MySQLCommandPacketDecoder
commandPacketDecoder
=
new
MySQLCommandPacketDecoder
();
when
(
byteBuf
.
readUnsignedByte
()).
thenReturn
((
short
)
PacketConstants
.
PROTOCOL_VERSION
);
commandPacketDecoder
.
decode
(
null
,
byteBuf
,
null
);
}
@Test
public
void
assertDecode
()
{
MySQLCommandPacketDecoder
commandPacketDecoder
=
new
MySQLCommandPacketDecoder
();
List
<
Object
>
actual
=
new
ArrayList
<>();
commandPacketDecoder
.
decode
(
null
,
mockHandshakePacket
(),
actual
);
assertInitial
(
actual
);
actual
.
clear
();
commandPacketDecoder
.
decode
(
null
,
mockOkPacket
(),
actual
);
assertPacketByType
(
actual
,
OkPacket
.
class
);
actual
.
clear
();
commandPacketDecoder
.
decode
(
null
,
mockErrPacket
(),
actual
);
assertPacketByType
(
actual
,
ErrorPacket
.
class
);
actual
.
clear
();
commandPacketDecoder
.
decode
(
null
,
mockResultSetPacket
(),
actual
);
commandPacketDecoder
.
decode
(
null
,
mockResultSetPacket
(),
actual
);
commandPacketDecoder
.
decode
(
null
,
mockEofPacket
(),
actual
);
commandPacketDecoder
.
decode
(
null
,
mockResultSetPacket
(),
actual
);
commandPacketDecoder
.
decode
(
null
,
mockEofPacket
(),
actual
);
assertPacketByType
(
actual
,
InternalResultSet
.
class
);
}
private
ByteBuf
mockHandshakePacket
()
{
String
handshakePacket
=
"0a352e372e32312d6c6f6700090000004a592a1f725a0d0900fff7210200ff8115000000000000000000001a437b30323a4d2b514b5870006d"
+
"7973716c5f6e61746976655f70617373776f72640000000002000000"
;
byte
[]
handshakePacketBytes
=
ByteBufUtil
.
decodeHexDump
(
handshakePacket
);
ByteBuf
result
=
Unpooled
.
buffer
(
handshakePacketBytes
.
length
);
result
.
writeBytes
(
handshakePacketBytes
);
return
result
;
}
private
void
assertInitial
(
final
List
<
Object
>
actual
)
{
assertThat
(
actual
.
size
(),
is
(
1
));
assertThat
(
actual
.
get
(
0
),
instanceOf
(
HandshakeInitializationPacket
.
class
));
HandshakeInitializationPacket
actualPacket
=
(
HandshakeInitializationPacket
)
actual
.
get
(
0
);
assertThat
(
actualPacket
.
getProtocolVersion
(),
is
((
short
)
0x0a
));
assertThat
(
actualPacket
.
getServerVersion
(),
is
(
"5.7.21-log"
));
assertThat
(
actualPacket
.
getThreadId
(),
is
(
9L
));
assertThat
(
actualPacket
.
getServerCharsetSet
(),
is
((
short
)
33
));
assertThat
(
actualPacket
.
getServerStatus
(),
is
(
2
));
assertThat
(
actualPacket
.
getServerCapabilities
(),
is
(
63487
));
assertThat
(
actualPacket
.
getServerCapabilities2
(),
is
(
33279
));
assertThat
(
actualPacket
.
getAuthPluginName
(),
is
(
"mysql_native_password"
));
}
private
ByteBuf
mockOkPacket
()
{
when
(
byteBuf
.
getByte
(
0
)).
thenReturn
(
PacketConstants
.
OK_PACKET_MARK
);
return
byteBuf
;
}
private
ByteBuf
mockErrPacket
()
{
when
(
byteBuf
.
getByte
(
0
)).
thenReturn
(
PacketConstants
.
ERR_PACKET_MARK
);
return
byteBuf
;
}
private
ByteBuf
mockResultSetPacket
()
{
when
(
byteBuf
.
getByte
(
0
)).
thenReturn
((
byte
)
1
);
return
byteBuf
;
}
private
ByteBuf
mockEofPacket
()
{
when
(
byteBuf
.
getByte
(
0
)).
thenReturn
(
PacketConstants
.
EOF_PACKET_MARK
);
return
byteBuf
;
}
private
void
assertPacketByType
(
final
List
<
Object
>
actual
,
final
Class
clazz
)
{
assertThat
(
actual
.
size
(),
is
(
1
));
assertThat
(
actual
.
get
(
0
),
instanceOf
(
clazz
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录