Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
5de1d593
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,发现更多精彩内容 >>
提交
5de1d593
编写于
11月 15, 2018
作者:
马
马晓光
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test case for spring boot start
上级
8616c093
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
0 deletion
+43
-0
sharding-jdbc/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/shardingjdbc/spring/boot/type/SpringBootShardingTest.java
...shardingjdbc/spring/boot/type/SpringBootShardingTest.java
+42
-0
sharding-jdbc/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties
...tarter/src/test/resources/application-sharding.properties
+1
-0
未找到文件。
sharding-jdbc/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/shardingjdbc/spring/boot/type/SpringBootShardingTest.java
浏览文件 @
5de1d593
...
...
@@ -20,6 +20,8 @@ package io.shardingsphere.shardingjdbc.spring.boot.type;
import
io.shardingsphere.api.ConfigMapContext
;
import
io.shardingsphere.core.constant.properties.ShardingProperties
;
import
io.shardingsphere.core.constant.properties.ShardingPropertiesConstant
;
import
io.shardingsphere.core.rule.ShardingRule
;
import
io.shardingsphere.core.rule.TableRule
;
import
io.shardingsphere.shardingjdbc.jdbc.core.ShardingContext
;
import
io.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource
;
import
lombok.SneakyThrows
;
...
...
@@ -35,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
java.lang.reflect.Field
;
import
java.util.LinkedList
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -73,6 +76,45 @@ public class SpringBootShardingTest {
assertThat
((
Integer
)
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_SIZE
),
is
(
100
));
}
@Test
public
void
assertWithShardingRule
()
{
ShardingContext
shardingContext
=
getFieldValue
(
"shardingContext"
,
ShardingDataSource
.
class
,
dataSource
);
ShardingRule
shardingRule
=
shardingContext
.
getShardingRule
();
assertThat
(
shardingRule
.
getShardingDataSourceNames
().
getDataSourceNames
().
size
(),
is
(
3
));
assertTrue
(
shardingRule
.
getShardingDataSourceNames
().
getDataSourceNames
().
contains
(
"ds"
));
assertTrue
(
shardingRule
.
getShardingDataSourceNames
().
getDataSourceNames
().
contains
(
"ds_0"
));
assertTrue
(
shardingRule
.
getShardingDataSourceNames
().
getDataSourceNames
().
contains
(
"ds_1"
));
assertThat
(
shardingRule
.
getTableRules
().
size
(),
is
(
2
));
TableRule
tableRule1
=
((
LinkedList
<
TableRule
>)
shardingRule
.
getTableRules
()).
get
(
0
);
assertThat
(
tableRule1
.
getLogicTable
(),
is
(
"t_order"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
size
(),
is
(
4
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
0
).
getDataSourceName
(),
is
(
"ds_0"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
0
).
getTableName
(),
is
(
"t_order_0"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
1
).
getDataSourceName
(),
is
(
"ds_0"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
1
).
getTableName
(),
is
(
"t_order_1"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
2
).
getDataSourceName
(),
is
(
"ds_1"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
2
).
getTableName
(),
is
(
"t_order_0"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
3
).
getDataSourceName
(),
is
(
"ds_1"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
get
(
3
).
getTableName
(),
is
(
"t_order_1"
));
assertThat
(
tableRule1
.
getGenerateKeyColumn
(),
is
(
"order_id"
));
TableRule
tableRule2
=
((
LinkedList
<
TableRule
>)
shardingRule
.
getTableRules
()).
get
(
1
);
assertThat
(
tableRule2
.
getLogicTable
(),
is
(
"t_order_item"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
size
(),
is
(
4
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
0
).
getDataSourceName
(),
is
(
"ds_0"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
0
).
getTableName
(),
is
(
"t_order_item_0"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
1
).
getDataSourceName
(),
is
(
"ds_0"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
1
).
getTableName
(),
is
(
"t_order_item_1"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
2
).
getDataSourceName
(),
is
(
"ds_1"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
2
).
getTableName
(),
is
(
"t_order_item_0"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
3
).
getDataSourceName
(),
is
(
"ds_1"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
get
(
3
).
getTableName
(),
is
(
"t_order_item_1"
));
assertThat
(
tableRule2
.
getGenerateKeyColumn
(),
is
(
"order_item_id"
));
assertThat
(
shardingRule
.
getBindingTableRules
().
size
(),
is
(
0
));
assertThat
(
shardingRule
.
getBroadcastTables
().
size
(),
is
(
1
));
assertThat
(
shardingRule
.
getBroadcastTables
().
iterator
().
next
(),
is
(
"t_config"
));
}
@SuppressWarnings
(
"unchecked"
)
@SneakyThrows
private
<
T
>
T
getFieldValue
(
final
String
fieldName
,
final
Class
<?>
fieldClass
,
final
Object
target
)
{
...
...
sharding-jdbc/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties
浏览文件 @
5de1d593
...
...
@@ -31,6 +31,7 @@ sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_${0..1}.t
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding-column
=
order_id
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression
=
t_order_item_${order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name
=
order_item_id
sharding.jdbc.config.sharding.broadcast-tables
=
t_config
sharding.jdbc.config.props.sql.show
=
true
sharding.jdbc.config.props.executor.size
=
100
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录