Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
cfbd2acb
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 搜索 >>
未验证
提交
cfbd2acb
编写于
6月 08, 2020
作者:
J
Juan Pan(Trista)
提交者:
GitHub
6月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CreateAutoTableRule (#5951)
上级
d8893752
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
7 deletion
+48
-7
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
...va/org/apache/shardingsphere/sharding/rule/TableRule.java
+2
-2
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
...rg/apache/shardingsphere/sharding/rule/TableRuleTest.java
+46
-5
未找到文件。
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
浏览文件 @
cfbd2acb
...
...
@@ -104,11 +104,11 @@ public final class TableRule {
}
public
TableRule
(
final
ShardingAutoTableRuleConfiguration
tableRuleConfig
,
final
Collection
<
String
>
dataSourceNames
,
final
String
defaultGenerateKeyColumn
)
{
Preconditions
.
checkArgument
(
null
==
tableRuleConfig
.
getShardingStrategy
()
||
tableRuleConfig
.
getShardingStrategy
()
instanceof
ShardingAutoTableAlgorithm
,
"ShardingAutoTableAlgorithm is required."
);
logicTable
=
tableRuleConfig
.
getLogicTable
().
toLowerCase
();
databaseShardingStrategy
=
null
;
tableShardingStrategy
=
null
==
tableRuleConfig
.
getShardingStrategy
()
?
null
:
ShardingStrategyFactory
.
newInstance
(
tableRuleConfig
.
getShardingStrategy
());
Preconditions
.
checkArgument
(
null
==
tableRuleConfig
.
getShardingStrategy
()
||
tableShardingStrategy
.
getShardingAlgorithm
()
instanceof
ShardingAutoTableAlgorithm
,
"ShardingAutoTableAlgorithm is required."
);
List
<
String
>
dataNodes
=
getDataNodes
(
tableRuleConfig
,
dataSourceNames
);
dataNodeIndexMap
=
new
HashMap
<>(
dataNodes
.
size
(),
1
);
actualDataNodes
=
isEmptyDataNodes
(
dataNodes
)
?
generateDataNodes
(
tableRuleConfig
.
getLogicTable
(),
dataSourceNames
)
:
generateDataNodes
(
dataNodes
,
dataSourceNames
);
...
...
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
浏览文件 @
cfbd2acb
...
...
@@ -18,17 +18,18 @@
package
org.apache.shardingsphere.sharding.rule
;
import
com.google.common.collect.Sets
;
import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException
;
import
org.apache.shardingsphere.infra.datanode.DataNode
;
import
org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader
;
import
org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry
;
import
org.apache.shardingsphere.sharding.api.config.KeyGeneratorConfiguration
;
import
org.apache.shardingsphere.sharding.api.config.ShardingAutoTableRuleConfiguration
;
import
org.apache.shardingsphere.sharding.api.config.ShardingTableRuleConfiguration
;
import
org.apache.shardingsphere.sharding.api.config.strategy.NoneShardingStrategyConfiguration
;
import
org.apache.shardingsphere.sharding.api.config.strategy.StandardShardingStrategyConfiguration
;
import
org.apache.shardingsphere.sharding.spi.keygen.KeyGenerateAlgorithm
;
import
org.apache.shardingsphere.sharding.strategy.algorithm.keygen.fixture.IncrementKeyGenerateAlgorithm
;
import
org.apache.shardingsphere.sharding.strategy.algorithm.sharding.inline.InlineShardingAlgorithm
;
import
org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader
;
import
org.apache.shardingsphere.sharding.spi.keygen.KeyGenerateAlgorithm
;
import
org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry
;
import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException
;
import
org.apache.shardingsphere.infra.datanode.DataNode
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
...
...
@@ -86,6 +87,46 @@ public final class TableRuleTest {
assertThat
(
actual
.
getGenerateKeyColumn
().
get
(),
is
(
"col_1"
));
assertThat
(
actual
.
getKeyGenerateAlgorithm
(),
instanceOf
(
IncrementKeyGenerateAlgorithm
.
class
));
}
@Test
public
void
assertCreateAutoTableRuleWithActualDataSources
()
{
ShardingSphereServiceLoader
.
register
(
KeyGenerateAlgorithm
.
class
);
ShardingAutoTableRuleConfiguration
tableRuleConfig
=
new
ShardingAutoTableRuleConfiguration
(
"LOGIC_TABLE"
,
"ds0,ds1"
);
InlineShardingAlgorithm
shardingAlgorithm
=
new
InlineShardingAlgorithm
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"algorithm.expression"
,
"ds${0..1}.logic_table_${0..1}"
);
shardingAlgorithm
.
setProperties
(
properties
);
tableRuleConfig
.
setShardingStrategy
(
new
StandardShardingStrategyConfiguration
(
"col_1"
,
shardingAlgorithm
));
TableRule
actual
=
new
TableRule
(
tableRuleConfig
,
Arrays
.
asList
(
"ds0"
,
"ds1"
,
"ds2"
),
null
);
assertThat
(
actual
.
getLogicTable
(),
is
(
"logic_table"
));
assertThat
(
actual
.
getActualDataNodes
().
size
(),
is
(
4
));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds0"
,
"logic_table_0"
)));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds1"
,
"logic_table_1"
)));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds0"
,
"logic_table_2"
)));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds1"
,
"logic_table_3"
)));
assertNull
(
actual
.
getDatabaseShardingStrategy
());
assertNotNull
(
actual
.
getTableShardingStrategy
());
}
@Test
public
void
assertCreateAutoTableRuleWithoutActualDataSources
()
{
ShardingSphereServiceLoader
.
register
(
KeyGenerateAlgorithm
.
class
);
ShardingAutoTableRuleConfiguration
tableRuleConfig
=
new
ShardingAutoTableRuleConfiguration
(
"LOGIC_TABLE"
,
null
);
InlineShardingAlgorithm
shardingAlgorithm
=
new
InlineShardingAlgorithm
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"algorithm.expression"
,
"ds${0..1}.logic_table_${0..1}"
);
shardingAlgorithm
.
setProperties
(
properties
);
tableRuleConfig
.
setShardingStrategy
(
new
StandardShardingStrategyConfiguration
(
"col_1"
,
shardingAlgorithm
));
TableRule
actual
=
new
TableRule
(
tableRuleConfig
,
Arrays
.
asList
(
"ds0"
,
"ds1"
,
"ds2"
),
null
);
assertThat
(
actual
.
getLogicTable
(),
is
(
"logic_table"
));
assertThat
(
actual
.
getActualDataNodes
().
size
(),
is
(
4
));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds0"
,
"logic_table_0"
)));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds1"
,
"logic_table_1"
)));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds2"
,
"logic_table_2"
)));
assertTrue
(
actual
.
getActualDataNodes
().
contains
(
new
DataNode
(
"ds0"
,
"logic_table_3"
)));
assertNull
(
actual
.
getDatabaseShardingStrategy
());
assertNotNull
(
actual
.
getTableShardingStrategy
());
}
@Test
public
void
assertGetActualDatasourceNames
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录