Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
45d0cc11
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,发现更多精彩内容 >>
未验证
提交
45d0cc11
编写于
8月 24, 2020
作者:
Y
Yanjie Zhou
提交者:
GitHub
8月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test cases (#7030)
* add test cases * add test cases * add test cases
上级
245c4072
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
617 addition
and
0 deletion
+617
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2BinaryProtocolValueTest.java
.../bind/protocol/PostgreSQLInt2BinaryProtocolValueTest.java
+47
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4BinaryProtocolValueTest.java
.../bind/protocol/PostgreSQLInt4BinaryProtocolValueTest.java
+47
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8BinaryProtocolValueTest.java
.../bind/protocol/PostgreSQLInt8BinaryProtocolValueTest.java
+47
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringBinaryProtocolValueTest.java
...ind/protocol/PostgreSQLStringBinaryProtocolValueTest.java
+66
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLTimeBinaryProtocolValueTest.java
.../bind/protocol/PostgreSQLTimeBinaryProtocolValueTest.java
+50
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacketTest.java
...uery/binary/describe/PostgreSQLComDescribePacketTest.java
+45
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/execute/PostgreSQLComExecutePacketTest.java
.../query/binary/execute/PostgreSQLComExecutePacketTest.java
+45
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacketTest.java
...mand/query/binary/parse/PostgreSQLComParsePacketTest.java
+59
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacketTest.java
...query/binary/parse/PostgreSQLParseCompletePacketTest.java
+35
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/sync/PostgreSQLComSyncPacketTest.java
...ommand/query/binary/sync/PostgreSQLComSyncPacketTest.java
+43
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacketTest.java
...cket/command/query/text/PostgreSQLComQueryPacketTest.java
+47
-0
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacketTest.java
...acket/command/query/text/PostgreSQLDataRowPacketTest.java
+86
-0
未找到文件。
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2BinaryProtocolValueTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLInt2BinaryProtocolValueTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLInt2BinaryProtocolValue
actual
=
new
PostgreSQLInt2BinaryProtocolValue
();
assertThat
(
actual
.
getColumnLength
(
null
),
equalTo
(
2
));
when
(
payload
.
readInt2
()).
thenReturn
(
1
);
assertThat
(
actual
.
read
(
payload
),
is
(
1
));
actual
.
write
(
payload
,
1
);
verify
(
payload
).
writeInt2
(
1
);
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4BinaryProtocolValueTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLInt4BinaryProtocolValueTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLInt4BinaryProtocolValue
actual
=
new
PostgreSQLInt4BinaryProtocolValue
();
assertThat
(
actual
.
getColumnLength
(
null
),
equalTo
(
4
));
when
(
payload
.
readInt4
()).
thenReturn
(
1
);
assertThat
(
actual
.
read
(
payload
),
is
(
1
));
actual
.
write
(
payload
,
1
);
verify
(
payload
).
writeInt4
(
1
);
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8BinaryProtocolValueTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLInt8BinaryProtocolValueTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLInt8BinaryProtocolValue
actual
=
new
PostgreSQLInt8BinaryProtocolValue
();
assertThat
(
actual
.
getColumnLength
(
null
),
equalTo
(
8
));
when
(
payload
.
readInt8
()).
thenReturn
(
1L
);
assertThat
(
actual
.
read
(
payload
),
is
(
1L
));
actual
.
write
(
payload
,
1L
);
verify
(
payload
).
writeInt8
(
1L
);
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringBinaryProtocolValueTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol
;
import
io.netty.buffer.ByteBuf
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.stubbing.Answer
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLStringBinaryProtocolValueTest
{
@InjectMocks
private
PostgreSQLPacketPayload
payload
;
@Mock
private
ByteBuf
byteBuf
;
@Test
public
void
assertNewInstance
()
{
when
(
byteBuf
.
readerIndex
()).
thenReturn
(
8
);
doAnswer
(
new
Answer
<
ByteBuf
>()
{
@Override
public
ByteBuf
answer
(
final
InvocationOnMock
invocation
)
throws
Throwable
{
((
byte
[])
invocation
.
getArguments
()[
0
])[
0
]
=
97
;
return
byteBuf
;
}
}).
when
(
byteBuf
).
readBytes
(
any
(
byte
[].
class
));
PostgreSQLStringBinaryProtocolValue
actual
=
new
PostgreSQLStringBinaryProtocolValue
();
assertThat
(
actual
.
getColumnLength
(
"str"
),
equalTo
(
"str"
.
length
()));
when
(
payload
.
readInt4
()).
thenReturn
(
1
);
assertThat
(
actual
.
read
(
payload
),
equalTo
(
"a"
));
verify
(
byteBuf
).
readerIndex
(
4
);
actual
.
write
(
payload
,
"a"
);
verify
(
byteBuf
).
writeBytes
(
"a"
.
getBytes
());
actual
.
write
(
payload
,
new
byte
[
1
]);
verify
(
byteBuf
).
writeBytes
(
new
byte
[
1
]);
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLTimeBinaryProtocolValueTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.sql.Timestamp
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLTimeBinaryProtocolValueTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLTimeBinaryProtocolValue
actual
=
new
PostgreSQLTimeBinaryProtocolValue
();
assertThat
(
actual
.
getColumnLength
(
null
),
equalTo
(
8
));
when
(
payload
.
readInt8
()).
thenReturn
(
1L
);
assertThat
(
actual
.
read
(
payload
),
is
(
1L
));
Timestamp
timestamp
=
new
Timestamp
(
System
.
currentTimeMillis
());
actual
.
write
(
payload
,
timestamp
);
verify
(
payload
).
writeInt8
(
timestamp
.
getTime
());
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.describe
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLComDescribePacketTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLComDescribePacket
actual
=
new
PostgreSQLComDescribePacket
(
payload
);
actual
.
write
(
payload
);
assertThat
(
actual
.
getMessageType
(),
is
(
'D'
));
verify
(
payload
).
readInt4
();
verify
(
payload
).
readInt1
();
verify
(
payload
).
readStringNul
();
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/execute/PostgreSQLComExecutePacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.execute
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
atLeast
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLComExecutePacketTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLComExecutePacket
actual
=
new
PostgreSQLComExecutePacket
(
payload
);
verify
(
payload
,
atLeast
(
2
)).
readInt4
();
verify
(
payload
).
readStringNul
();
actual
.
write
(
payload
);
assertThat
(
actual
.
getMessageType
(),
is
(
'E'
));
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.parse
;
import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLColumnType
;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.PostgreSQLBinaryStatementParameterType
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.util.List
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLComParsePacketTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
when
(
payload
.
readInt2
()).
thenReturn
(
1
);
when
(
payload
.
readInt4
()).
thenReturn
(
0
);
when
(
payload
.
readStringNul
()).
thenReturn
(
"sql"
);
PostgreSQLComParsePacket
actual
=
new
PostgreSQLComParsePacket
(
payload
);
actual
.
write
(
payload
);
assertThat
(
actual
.
getMessageType
(),
is
(
'P'
));
assertThat
(
actual
.
getSql
(),
is
(
"sql"
));
assertThat
(
actual
.
getStatementId
(),
is
(
"sql"
));
List
<
PostgreSQLBinaryStatementParameterType
>
types
=
actual
.
getBinaryStatementParameterTypes
();
assertNotNull
(
types
);
assertThat
(
types
.
size
(),
equalTo
(
1
));
assertThat
(
types
.
get
(
0
).
getColumnType
(),
is
(
PostgreSQLColumnType
.
POSTGRESQL_TYPE_UNSPECIFIED
));
assertTrue
(
actual
.
toString
().
startsWith
(
"PostgreSQLComParsePacket(statementId=sql, sql=sql, binaryStatementParameterTypes=["
));
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.parse
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
public
final
class
PostgreSQLParseCompletePacketTest
{
@Test
public
void
assertNewInstance
()
{
PostgreSQLParseCompletePacket
actual
=
new
PostgreSQLParseCompletePacket
();
actual
.
write
(
mock
(
PostgreSQLPacketPayload
.
class
));
assertThat
(
actual
.
getMessageType
(),
is
(
'1'
));
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/sync/PostgreSQLComSyncPacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.sync
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLComSyncPacketTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
PostgreSQLComSyncPacket
actual
=
new
PostgreSQLComSyncPacket
(
payload
);
actual
.
write
(
payload
);
verify
(
payload
).
readInt4
();
assertThat
(
actual
.
getMessageType
(),
is
(
'S'
));
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.text
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLComQueryPacketTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Test
public
void
assertNewInstance
()
{
when
(
payload
.
readStringNul
()).
thenReturn
(
"sql"
);
PostgreSQLComQueryPacket
actual
=
new
PostgreSQLComQueryPacket
(
payload
);
actual
.
write
(
payload
);
verify
(
payload
).
readInt4
();
assertThat
(
actual
.
getSql
(),
is
(
"sql"
));
assertThat
(
actual
.
getMessageType
(),
is
(
'Q'
));
assertThat
(
actual
.
toString
(),
is
(
"PostgreSQLComQueryPacket(sql=sql)"
));
}
}
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacketTest.java
0 → 100644
浏览文件 @
45d0cc11
/*
* 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
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.text
;
import
lombok.SneakyThrows
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.sql.SQLException
;
import
java.sql.SQLXML
;
import
java.util.Collections
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
PostgreSQLDataRowPacketTest
{
@Mock
private
PostgreSQLPacketPayload
payload
;
@Mock
private
SQLXML
sqlxml
;
@Test
public
void
assertWriteWithNull
()
{
PostgreSQLDataRowPacket
actual
=
new
PostgreSQLDataRowPacket
(
Collections
.
singletonList
(
null
));
actual
.
write
(
payload
);
verify
(
payload
).
writeInt4
(
0xFFFFFFFF
);
}
@Test
public
void
assertWriteWithBytes
()
{
PostgreSQLDataRowPacket
actual
=
new
PostgreSQLDataRowPacket
(
Collections
.
singletonList
(
new
byte
[]{
'a'
}));
actual
.
write
(
payload
);
verify
(
payload
).
writeInt4
(
new
byte
[]{
'a'
}.
length
);
verify
(
payload
).
writeBytes
(
new
byte
[]{
'a'
});
}
@Test
@SneakyThrows
public
void
assertWriteWithSQLXML
()
{
when
(
sqlxml
.
getString
()).
thenReturn
(
"string"
);
PostgreSQLDataRowPacket
actual
=
new
PostgreSQLDataRowPacket
(
Collections
.
singletonList
(
sqlxml
));
actual
.
write
(
payload
);
verify
(
payload
).
writeInt4
(
"string"
.
getBytes
().
length
);
verify
(
payload
).
writeStringEOF
(
"string"
);
}
@Test
public
void
assertWriteWithString
()
{
PostgreSQLDataRowPacket
actual
=
new
PostgreSQLDataRowPacket
(
Collections
.
singletonList
(
"str"
));
assertThat
(
actual
.
getData
(),
is
(
Collections
.
singletonList
(
"str"
)));
actual
.
write
(
payload
);
verify
(
payload
).
writeInt4
(
"str"
.
getBytes
().
length
);
verify
(
payload
).
writeStringEOF
(
"str"
);
}
@Test
@SneakyThrows
public
void
assertWriteWithSQLXML4Error
()
{
when
(
sqlxml
.
getString
()).
thenThrow
(
new
SQLException
(
"mock"
));
PostgreSQLDataRowPacket
actual
=
new
PostgreSQLDataRowPacket
(
Collections
.
singletonList
(
sqlxml
));
actual
.
write
(
payload
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录