Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
19d0002d
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,发现更多精彩内容 >>
提交
19d0002d
编写于
4月 02, 2018
作者:
T
tuohai666
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test cases for ShowCreateTableMergedResult and MergeEngineFactory, 99% lines covered in merge
上级
5adf3c67
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
203 addition
and
2 deletion
+203
-2
sharding-core/src/test/java/io/shardingjdbc/core/merger/AllMergerTests.java
...test/java/io/shardingjdbc/core/merger/AllMergerTests.java
+12
-1
sharding-core/src/test/java/io/shardingjdbc/core/merger/MergeEngineFactoryTest.java
...a/io/shardingjdbc/core/merger/MergeEngineFactoryTest.java
+75
-0
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResultTest.java
...core/merger/dal/show/ShowCreateTableMergedResultTest.java
+116
-0
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowTablesMergedResultTest.java
...jdbc/core/merger/dal/show/ShowTablesMergedResultTest.java
+0
-1
未找到文件。
sharding-core/src/test/java/io/shardingjdbc/core/merger/AllMergerTests.java
浏览文件 @
19d0002d
...
@@ -17,6 +17,11 @@
...
@@ -17,6 +17,11 @@
package
io.shardingjdbc.core.merger
;
package
io.shardingjdbc.core.merger
;
import
io.shardingjdbc.core.merger.dal.DALMergeEngineTest
;
import
io.shardingjdbc.core.merger.dal.show.ShowCreateTableMergedResultTest
;
import
io.shardingjdbc.core.merger.dal.show.ShowDatabasesMergedResultTest
;
import
io.shardingjdbc.core.merger.dal.show.ShowOtherMergedResultTest
;
import
io.shardingjdbc.core.merger.dal.show.ShowTablesMergedResultTest
;
import
io.shardingjdbc.core.merger.dql.DQLMergeEngineTest
;
import
io.shardingjdbc.core.merger.dql.DQLMergeEngineTest
;
import
io.shardingjdbc.core.merger.dql.common.DecoratorMergedResultTest
;
import
io.shardingjdbc.core.merger.dql.common.DecoratorMergedResultTest
;
import
io.shardingjdbc.core.merger.dql.common.MemoryMergedResultTest
;
import
io.shardingjdbc.core.merger.dql.common.MemoryMergedResultTest
;
...
@@ -55,7 +60,13 @@ import org.junit.runners.Suite;
...
@@ -55,7 +60,13 @@ import org.junit.runners.Suite;
AllAggregationTests
.
class
,
AllAggregationTests
.
class
,
LimitDecoratorMergedResultTest
.
class
,
LimitDecoratorMergedResultTest
.
class
,
RowNumberDecoratorMergedResultTest
.
class
,
RowNumberDecoratorMergedResultTest
.
class
,
TopAndRowNumberDecoratorMergedResultTest
.
class
TopAndRowNumberDecoratorMergedResultTest
.
class
,
DALMergeEngineTest
.
class
,
ShowCreateTableMergedResultTest
.
class
,
ShowDatabasesMergedResultTest
.
class
,
ShowOtherMergedResultTest
.
class
,
ShowTablesMergedResultTest
.
class
,
MergeEngineFactoryTest
.
class
})
})
public
class
AllMergerTests
{
public
class
AllMergerTests
{
}
}
sharding-core/src/test/java/io/shardingjdbc/core/merger/MergeEngineFactoryTest.java
0 → 100644
浏览文件 @
19d0002d
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed 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.
* </p>
*/
package
io.shardingjdbc.core.merger
;
import
com.google.common.collect.Lists
;
import
io.shardingjdbc.core.merger.dal.DALMergeEngine
;
import
io.shardingjdbc.core.merger.dql.DQLMergeEngine
;
import
io.shardingjdbc.core.merger.fixture.TestQueryResult
;
import
io.shardingjdbc.core.parsing.parser.sql.SQLStatement
;
import
io.shardingjdbc.core.parsing.parser.sql.dal.DALStatement
;
import
io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement
;
import
io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
final
class
MergeEngineFactoryTest
{
private
List
<
QueryResult
>
queryResults
;
@Before
public
void
setUp
()
throws
SQLException
{
ResultSet
resultSet
=
mock
(
ResultSet
.
class
);
ResultSetMetaData
resultSetMetaData
=
mock
(
ResultSetMetaData
.
class
);
when
(
resultSet
.
getMetaData
()).
thenReturn
(
resultSetMetaData
);
when
(
resultSetMetaData
.
getColumnCount
()).
thenReturn
(
1
);
when
(
resultSetMetaData
.
getColumnLabel
(
1
)).
thenReturn
(
"label"
);
List
<
ResultSet
>
resultSets
=
Lists
.
newArrayList
(
resultSet
);
queryResults
=
new
ArrayList
<>(
resultSets
.
size
());
queryResults
.
add
(
new
TestQueryResult
(
resultSets
.
get
(
0
)));
}
@Test
public
void
assertNewInstanceWithSelectStatement
()
throws
SQLException
{
SQLStatement
selectStatement
=
new
SelectStatement
();
assertThat
(
MergeEngineFactory
.
newInstance
(
null
,
queryResults
,
selectStatement
),
instanceOf
(
DQLMergeEngine
.
class
));
}
@Test
public
void
assertNewInstanceWithDALStatement
()
throws
SQLException
{
SQLStatement
dalStatement
=
new
DALStatement
();
assertThat
(
MergeEngineFactory
.
newInstance
(
null
,
queryResults
,
dalStatement
),
instanceOf
(
DALMergeEngine
.
class
));
}
@Test
(
expected
=
UnsupportedOperationException
.
class
)
public
void
assertNewInstanceWithOtherStatement
()
throws
SQLException
{
SQLStatement
insertStatement
=
new
InsertStatement
();
MergeEngineFactory
.
newInstance
(
null
,
queryResults
,
insertStatement
);
}
}
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowCreateTableMergedResultTest.java
0 → 100644
浏览文件 @
19d0002d
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed 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.
* </p>
*/
package
io.shardingjdbc.core.merger.dal.show
;
import
com.google.common.collect.Lists
;
import
io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm
;
import
io.shardingjdbc.core.api.config.ShardingRuleConfiguration
;
import
io.shardingjdbc.core.api.config.TableRuleConfiguration
;
import
io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration
;
import
io.shardingjdbc.core.merger.QueryResult
;
import
io.shardingjdbc.core.merger.fixture.TestQueryResult
;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
final
class
ShowCreateTableMergedResultTest
{
private
ShardingRule
shardingRule
;
private
List
<
QueryResult
>
queryResults
;
private
ResultSet
resultSet
;
@Before
public
void
setUp
()
throws
SQLException
{
TableRuleConfiguration
tableRuleConfig
=
new
TableRuleConfiguration
();
tableRuleConfig
.
setLogicTable
(
"table"
);
tableRuleConfig
.
setActualDataNodes
(
"ds.table_${0..2}"
);
tableRuleConfig
.
setTableShardingStrategyConfig
(
new
ComplexShardingStrategyConfiguration
(
"field1, field2, field3"
,
new
TestComplexKeysShardingAlgorithm
()));
ShardingRuleConfiguration
shardingRuleConfig
=
new
ShardingRuleConfiguration
();
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
tableRuleConfig
);
shardingRule
=
new
ShardingRule
(
shardingRuleConfig
,
Lists
.
newArrayList
(
"ds"
));
resultSet
=
mock
(
ResultSet
.
class
);
ResultSetMetaData
resultSetMetaData
=
mock
(
ResultSetMetaData
.
class
);
when
(
resultSet
.
getMetaData
()).
thenReturn
(
resultSetMetaData
);
when
(
resultSetMetaData
.
getColumnCount
()).
thenReturn
(
2
);
List
<
ResultSet
>
resultSets
=
Lists
.
newArrayList
(
resultSet
);
for
(
ResultSet
each
:
resultSets
)
{
when
(
each
.
next
()).
thenReturn
(
true
,
false
);
}
queryResults
=
new
ArrayList
<>(
resultSets
.
size
());
for
(
ResultSet
each
:
resultSets
)
{
queryResults
.
add
(
new
TestQueryResult
(
each
));
}
}
@Test
public
void
assertNextForEmptyQueryResult
()
throws
SQLException
{
ShowCreateTableMergedResult
showCreateTableMergedResult
=
new
ShowCreateTableMergedResult
(
shardingRule
,
new
ArrayList
<
QueryResult
>());
assertFalse
(
showCreateTableMergedResult
.
next
());
}
@Test
public
void
assertNextForTableRuleIsPresentForBackQuotes
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"table_0"
);
when
(
resultSet
.
getObject
(
2
)).
thenReturn
(
"CREATE TABLE `t_order` (\n"
+
" `id` int(11) NOT NULL AUTO_INCREMENT,\n"
+
" `order_id` int(11) NOT NULL COMMENT,\n"
+
" `user_id` int(11) NOT NULL COMMENT,\n"
+
" `status` tinyint(4) NOT NULL DEFAULT '1',\n"
+
" `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n"
+
" PRIMARY KEY (`id`)\n"
+
") ENGINE=InnoDB AUTO_INCREMENT=121 DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
);
ShowCreateTableMergedResult
showCreateTableMergedResult
=
new
ShowCreateTableMergedResult
(
shardingRule
,
queryResults
);
assertTrue
(
showCreateTableMergedResult
.
next
());
}
@Test
public
void
assertNextForTableRuleIsPresentForNoBackQuotes
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"table_0"
);
when
(
resultSet
.
getObject
(
2
)).
thenReturn
(
"CREATE TABLE t_order (\n"
+
" `id` int(11) NOT NULL AUTO_INCREMENT,\n"
+
" `order_id` int(11) NOT NULL COMMENT,\n"
+
" `user_id` int(11) NOT NULL COMMENT,\n"
+
" `status` tinyint(4) NOT NULL DEFAULT '1',\n"
+
" `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n"
+
" PRIMARY KEY (`id`)\n"
+
") ENGINE=InnoDB AUTO_INCREMENT=121 DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
);
ShowCreateTableMergedResult
showCreateTableMergedResult
=
new
ShowCreateTableMergedResult
(
shardingRule
,
queryResults
);
assertTrue
(
showCreateTableMergedResult
.
next
());
}
@Test
public
void
assertNextForTableRuleIsNotPresent
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"table_3"
);
ShowCreateTableMergedResult
showCreateTableMergedResult
=
new
ShowCreateTableMergedResult
(
shardingRule
,
queryResults
);
assertFalse
(
showCreateTableMergedResult
.
next
());
}
}
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowTablesMergedResultTest.java
浏览文件 @
19d0002d
...
@@ -62,7 +62,6 @@ public final class ShowTablesMergedResultTest {
...
@@ -62,7 +62,6 @@ public final class ShowTablesMergedResultTest {
when
(
resultSet
.
getMetaData
()).
thenReturn
(
resultSetMetaData
);
when
(
resultSet
.
getMetaData
()).
thenReturn
(
resultSetMetaData
);
when
(
resultSetMetaData
.
getColumnCount
()).
thenReturn
(
1
);
when
(
resultSetMetaData
.
getColumnCount
()).
thenReturn
(
1
);
List
<
ResultSet
>
resultSets
=
Lists
.
newArrayList
(
resultSet
);
List
<
ResultSet
>
resultSets
=
Lists
.
newArrayList
(
resultSet
);
when
(
resultSets
.
get
(
0
).
next
()).
thenReturn
(
true
);
for
(
ResultSet
each
:
resultSets
)
{
for
(
ResultSet
each
:
resultSets
)
{
when
(
each
.
next
()).
thenReturn
(
true
,
false
);
when
(
each
.
next
()).
thenReturn
(
true
,
false
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录