Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
c0047eb1
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,发现更多精彩内容 >>
提交
c0047eb1
编写于
11月 16, 2018
作者:
马
马晓光
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add spring boot start orchestration test case for broadcast table
上级
6a0d686d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
133 addition
and
0 deletion
+133
-0
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/io/shardingsphere/shardingjdbc/spring/boot/type/OrchestrationSpringBootShardingTest.java
...spring/boot/type/OrchestrationSpringBootShardingTest.java
+82
-0
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties
...tarter/src/test/resources/application-sharding.properties
+2
-0
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingNamespaceTest.java
...hestration/spring/OrchestrationShardingNamespaceTest.java
+16
-0
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/namespace/shardingDataSourceNamespace.xml
...es/META-INF/rdb/namespace/shardingDataSourceNamespace.xml
+31
-0
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/shardingOrchestration.xml
...src/test/resources/META-INF/rdb/shardingOrchestration.xml
+2
-0
未找到文件。
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/io/shardingsphere/shardingjdbc/spring/boot/type/OrchestrationSpringBootShardingTest.java
浏览文件 @
c0047eb1
...
@@ -20,6 +20,10 @@ package io.shardingsphere.shardingjdbc.spring.boot.type;
...
@@ -20,6 +20,10 @@ package io.shardingsphere.shardingjdbc.spring.boot.type;
import
io.shardingsphere.api.ConfigMapContext
;
import
io.shardingsphere.api.ConfigMapContext
;
import
io.shardingsphere.core.constant.properties.ShardingProperties
;
import
io.shardingsphere.core.constant.properties.ShardingProperties
;
import
io.shardingsphere.core.constant.properties.ShardingPropertiesConstant
;
import
io.shardingsphere.core.constant.properties.ShardingPropertiesConstant
;
import
io.shardingsphere.core.routing.strategy.inline.InlineShardingStrategy
;
import
io.shardingsphere.core.rule.DataNode
;
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.ShardingContext
;
import
io.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource
;
import
io.shardingsphere.shardingjdbc.jdbc.core.datasource.ShardingDataSource
;
import
io.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationShardingDataSource
;
import
io.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationShardingDataSource
;
...
@@ -37,9 +41,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
...
@@ -37,9 +41,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.util.LinkedList
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
@@ -76,6 +82,82 @@ public class OrchestrationSpringBootShardingTest {
...
@@ -76,6 +82,82 @@ public class OrchestrationSpringBootShardingTest {
assertThat
((
Integer
)
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_SIZE
),
is
(
100
));
assertThat
((
Integer
)
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_SIZE
),
is
(
100
));
}
}
@Test
public
void
assertWithShardingDataSourceNames
()
{
ShardingDataSource
shardingDataSource
=
getFieldValue
(
"dataSource"
,
OrchestrationShardingDataSource
.
class
,
dataSource
);
ShardingContext
shardingContext
=
getFieldValue
(
"shardingContext"
,
ShardingDataSource
.
class
,
shardingDataSource
);
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"
));
}
@Test
public
void
assertWithTableRules
()
{
ShardingDataSource
shardingDataSource
=
getFieldValue
(
"dataSource"
,
OrchestrationShardingDataSource
.
class
,
dataSource
);
ShardingContext
shardingContext
=
getFieldValue
(
"shardingContext"
,
ShardingDataSource
.
class
,
shardingDataSource
);
ShardingRule
shardingRule
=
shardingContext
.
getShardingRule
();
assertThat
(
shardingRule
.
getTableRules
().
size
(),
is
(
2
));
TableRule
tableRule1
=
((
LinkedList
<
TableRule
>)
shardingRule
.
getTableRules
()).
get
(
0
);
assertThat
(
tableRule1
.
getLogicTable
(),
is
(
"t_order_item"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
size
(),
is
(
4
));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_item_0"
)));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_item_1"
)));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_item_0"
)));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_item_1"
)));
assertThat
(
tableRule1
.
getTableShardingStrategy
(),
instanceOf
(
InlineShardingStrategy
.
class
));
assertThat
(
tableRule1
.
getTableShardingStrategy
().
getShardingColumns
().
iterator
().
next
(),
is
(
"order_id"
));
assertThat
(
tableRule1
.
getGenerateKeyColumn
(),
is
(
"order_item_id"
));
TableRule
tableRule2
=
((
LinkedList
<
TableRule
>)
shardingRule
.
getTableRules
()).
get
(
1
);
assertThat
(
tableRule2
.
getLogicTable
(),
is
(
"t_order"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
size
(),
is
(
4
));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_0"
)));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_1"
)));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_0"
)));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_1"
)));
assertThat
(
tableRule1
.
getTableShardingStrategy
(),
instanceOf
(
InlineShardingStrategy
.
class
));
assertThat
(
tableRule1
.
getTableShardingStrategy
().
getShardingColumns
().
iterator
().
next
(),
is
(
"order_id"
));
assertThat
(
tableRule2
.
getGenerateKeyColumn
(),
is
(
"order_id"
));
}
@Test
public
void
assertWithBindingTableRules
()
{
ShardingDataSource
shardingDataSource
=
getFieldValue
(
"dataSource"
,
OrchestrationShardingDataSource
.
class
,
dataSource
);
ShardingContext
shardingContext
=
getFieldValue
(
"shardingContext"
,
ShardingDataSource
.
class
,
shardingDataSource
);
ShardingRule
shardingRule
=
shardingContext
.
getShardingRule
();
assertThat
(
shardingRule
.
getBindingTableRules
().
size
(),
is
(
2
));
TableRule
tableRule1
=
((
LinkedList
<
TableRule
>)
shardingRule
.
getTableRules
()).
get
(
0
);
assertThat
(
tableRule1
.
getLogicTable
(),
is
(
"t_order_item"
));
assertThat
(
tableRule1
.
getActualDataNodes
().
size
(),
is
(
4
));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_item_0"
)));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_item_1"
)));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_item_0"
)));
assertTrue
(
tableRule1
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_item_1"
)));
assertThat
(
tableRule1
.
getTableShardingStrategy
(),
instanceOf
(
InlineShardingStrategy
.
class
));
assertThat
(
tableRule1
.
getTableShardingStrategy
().
getShardingColumns
().
iterator
().
next
(),
is
(
"order_id"
));
assertThat
(
tableRule1
.
getGenerateKeyColumn
(),
is
(
"order_item_id"
));
TableRule
tableRule2
=
((
LinkedList
<
TableRule
>)
shardingRule
.
getTableRules
()).
get
(
1
);
assertThat
(
tableRule2
.
getLogicTable
(),
is
(
"t_order"
));
assertThat
(
tableRule2
.
getActualDataNodes
().
size
(),
is
(
4
));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_0"
)));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_0"
,
"t_order_1"
)));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_0"
)));
assertTrue
(
tableRule2
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds_1"
,
"t_order_1"
)));
assertThat
(
tableRule1
.
getTableShardingStrategy
(),
instanceOf
(
InlineShardingStrategy
.
class
));
assertThat
(
tableRule1
.
getTableShardingStrategy
().
getShardingColumns
().
iterator
().
next
(),
is
(
"order_id"
));
assertThat
(
tableRule2
.
getGenerateKeyColumn
(),
is
(
"order_id"
));
}
@Test
public
void
assertWithBroadcastTables
()
{
ShardingDataSource
shardingDataSource
=
getFieldValue
(
"dataSource"
,
OrchestrationShardingDataSource
.
class
,
dataSource
);
ShardingContext
shardingContext
=
getFieldValue
(
"shardingContext"
,
ShardingDataSource
.
class
,
shardingDataSource
);
ShardingRule
shardingRule
=
shardingContext
.
getShardingRule
();
assertThat
(
shardingRule
.
getBroadcastTables
().
size
(),
is
(
1
));
assertThat
(
shardingRule
.
getBroadcastTables
().
iterator
().
next
(),
is
(
"t_config"
));
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@SneakyThrows
@SneakyThrows
private
<
T
>
T
getFieldValue
(
final
String
fieldName
,
final
Class
<?>
fieldClass
,
final
Object
target
)
{
private
<
T
>
T
getFieldValue
(
final
String
fieldName
,
final
Class
<?>
fieldClass
,
final
Object
target
)
{
...
...
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/resources/application-sharding.properties
浏览文件 @
c0047eb1
...
@@ -31,6 +31,8 @@ sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_${0..1}.t
...
@@ -31,6 +31,8 @@ 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.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.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.tables.t_order_item.key-generator-column-name
=
order_item_id
sharding.jdbc.config.sharding.binding-tables
=
t_order,t_order_item
sharding.jdbc.config.sharding.broadcast-tables
=
t_config
sharding.jdbc.config.config-map.key1
=
value1
sharding.jdbc.config.config-map.key1
=
value1
...
...
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/shardingjdbc/orchestration/spring/OrchestrationShardingNamespaceTest.java
浏览文件 @
c0047eb1
...
@@ -41,6 +41,7 @@ import javax.sql.DataSource;
...
@@ -41,6 +41,7 @@ import javax.sql.DataSource;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.Map
;
import
java.util.Map
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
...
@@ -135,6 +136,21 @@ public class OrchestrationShardingNamespaceTest extends AbstractJUnit4SpringCont
...
@@ -135,6 +136,21 @@ public class OrchestrationShardingNamespaceTest extends AbstractJUnit4SpringCont
assertThat
(
userRule
.
getBindingActualTable
(
"dbtbl_1"
,
"t_user"
,
"t_user_detail"
),
is
(
"t_user"
));
assertThat
(
userRule
.
getBindingActualTable
(
"dbtbl_1"
,
"t_user"
,
"t_user_detail"
),
is
(
"t_user"
));
}
}
@Test
public
void
assertBroadcastTableRuleDatasource
()
{
ShardingRule
shardingRule
=
getShardingRule
(
"broadcastTableRuleDatasourceOrchestration"
);
assertThat
(
shardingRule
.
getBroadcastTables
().
size
(),
is
(
1
));
assertThat
(
shardingRule
.
getBroadcastTables
().
iterator
().
next
(),
is
(
"t_config"
));
}
@Test
public
void
assertMultiBroadcastTableRulesDatasource
()
{
ShardingRule
shardingRule
=
getShardingRule
(
"multiBroadcastTableRulesDatasourceOrchestration"
);
assertThat
(
shardingRule
.
getBroadcastTables
().
size
(),
is
(
2
));
assertThat
(((
LinkedList
<
String
>)
shardingRule
.
getBroadcastTables
()).
get
(
0
),
is
(
"t_config1"
));
assertThat
(((
LinkedList
<
String
>)
shardingRule
.
getBroadcastTables
()).
get
(
1
),
is
(
"t_config2"
));
}
@Test
@Test
public
void
assertPropsDataSource
()
{
public
void
assertPropsDataSource
()
{
OrchestrationSpringShardingDataSource
shardingDataSource
=
applicationContext
.
getBean
(
"propsDataSourceOrchestration"
,
OrchestrationSpringShardingDataSource
.
class
);
OrchestrationSpringShardingDataSource
shardingDataSource
=
applicationContext
.
getBean
(
"propsDataSourceOrchestration"
,
OrchestrationSpringShardingDataSource
.
class
);
...
...
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/namespace/shardingDataSourceNamespace.xml
浏览文件 @
c0047eb1
...
@@ -89,6 +89,37 @@
...
@@ -89,6 +89,37 @@
</sharding:sharding-rule>
</sharding:sharding-rule>
</sharding:data-source>
</sharding:data-source>
<sharding:data-source
id=
"broadcastTableRuleDatasource"
>
<sharding:sharding-rule
data-source-names=
"dbtbl_0,dbtbl_1"
>
<sharding:table-rules>
<sharding:table-rule
logic-table=
"t_order"
/>
<sharding:table-rule
logic-table=
"t_order_item"
/>
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule
logic-tables=
"t_order, t_order_item"
/>
</sharding:binding-table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule
tables=
"t_config"
/>
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
<sharding:data-source
id=
"multiBroadcastTableRulesDatasource"
>
<sharding:sharding-rule
data-source-names=
"dbtbl_0,dbtbl_1"
>
<sharding:table-rules>
<sharding:table-rule
logic-table=
"t_order"
/>
<sharding:table-rule
logic-table=
"t_order_item"
/>
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule
logic-tables=
"t_order, t_order_item"
/>
</sharding:binding-table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule
tables=
"t_config1"
/>
<sharding:broadcast-table-rule
tables=
"t_config2"
/>
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
<sharding:data-source
id=
"propsDataSource"
>
<sharding:data-source
id=
"propsDataSource"
>
<sharding:sharding-rule
data-source-names=
"dbtbl_0,dbtbl_1"
>
<sharding:sharding-rule
data-source-names=
"dbtbl_0,dbtbl_1"
>
<sharding:table-rules>
<sharding:table-rules>
...
...
sharding-jdbc/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/shardingOrchestration.xml
浏览文件 @
c0047eb1
...
@@ -17,4 +17,6 @@
...
@@ -17,4 +17,6 @@
<orchestraion:sharding-data-source
id=
"tableRuleWithAttributesDataSourceOrchestration"
data-source-ref=
"tableRuleWithAttributesDataSource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"tableRuleWithAttributesDataSourceOrchestration"
data-source-ref=
"tableRuleWithAttributesDataSource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"bindingTableRuleDatasourceOrchestration"
data-source-ref=
"bindingTableRuleDatasource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"bindingTableRuleDatasourceOrchestration"
data-source-ref=
"bindingTableRuleDatasource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"multiBindingTableRulesDatasourceOrchestration"
data-source-ref=
"multiBindingTableRulesDatasource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"multiBindingTableRulesDatasourceOrchestration"
data-source-ref=
"multiBindingTableRulesDatasource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"broadcastTableRuleDatasourceOrchestration"
data-source-ref=
"broadcastTableRuleDatasource"
registry-center-ref=
"regCenter"
/>
<orchestraion:sharding-data-source
id=
"multiBroadcastTableRulesDatasourceOrchestration"
data-source-ref=
"multiBroadcastTableRulesDatasource"
registry-center-ref=
"regCenter"
/>
</beans>
</beans>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录