Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
55a36ec7
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,发现更多精彩内容 >>
提交
55a36ec7
编写于
4月 10, 2018
作者:
L
liu ze jian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ddl test modification completed(ddl测试修改完成)
上级
abe619fb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
176 addition
and
58 deletion
+176
-58
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
...-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
+4
-11
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java
...est/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java
+26
-10
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDDLDefinition.java
.../shardingjdbc/dbtest/config/bean/AssertDDLDefinition.java
+5
-2
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java
...st/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java
+138
-33
sharding-jdbc-core/src/test/resources/asserts/assert-test-data/assert-test.xml
...c/test/resources/asserts/assert-test-data/assert-test.xml
+3
-2
未找到文件。
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
浏览文件 @
55a36ec7
...
...
@@ -80,15 +80,6 @@ public class StartTest {
return
getString
(
"assert.path"
,
null
);
}
/**
* initialized.
*
* @return initialized
*/
public
static
boolean
isInitialized
()
{
return
Boolean
.
valueOf
(
getString
(
"initialized"
,
"false"
));
}
@Parameters
public
static
Collection
<
String
[]>
getParameters
()
{
...
...
@@ -136,9 +127,10 @@ public class StartTest {
@BeforeClass
public
static
void
beforeClass
()
{
if
(
isInitialized
())
{
if
(
AssertEngine
.
isInitialized
())
{
InItCreateSchema
.
createDatabase
();
InItCreateSchema
.
createTable
();
AssertEngine
.
setInitialized
(
false
);
}
}
...
...
@@ -149,8 +141,9 @@ public class StartTest {
@AfterClass
public
static
void
afterClass
()
{
if
(
isInitialized
())
{
if
(
AssertEngine
.
isClean
())
{
InItCreateSchema
.
dropDatabase
();
AssertEngine
.
setClean
(
false
);
}
}
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java
浏览文件 @
55a36ec7
...
...
@@ -30,11 +30,14 @@ import javax.xml.parsers.ParserConfigurationException;
import
javax.xml.xpath.XPathExpressionException
;
import
io.shardingjdbc.core.api.ShardingDataSourceFactory
;
import
io.shardingjdbc.dbtest.StartTest
;
import
io.shardingjdbc.dbtest.config.bean.AssertDDLDefinition
;
import
io.shardingjdbc.dbtest.config.bean.AssertDMLDefinition
;
import
io.shardingjdbc.dbtest.config.bean.ColumnDefinition
;
import
io.shardingjdbc.dbtest.init.InItCreateSchema
;
import
io.shardingjdbc.test.sql.SQLCasesLoader
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.junit.Assert
;
import
org.xml.sax.SAXException
;
...
...
@@ -54,6 +57,19 @@ public class AssertEngine {
public
static
final
Map
<
String
,
AssertsDefinition
>
ASSERTDEFINITIONMAPS
=
new
HashMap
<>();
@Getter
@Setter
private
static
volatile
boolean
initialized
;
@Getter
@Setter
private
static
volatile
boolean
clean
;
static
{
initialized
=
Boolean
.
valueOf
(
StartTest
.
getString
(
"initialized"
,
"false"
));
clean
=
Boolean
.
valueOf
(
StartTest
.
getString
(
"initialized"
,
"false"
));
}
/**
* add check use cases.
*
...
...
@@ -216,8 +232,8 @@ public class AssertEngine {
private
static
void
doUpdateUsePreparedStatementToExecuteDDL
(
final
String
rootPath
,
final
DataSource
dataSource
,
final
AssertDDLDefinition
anAssert
,
final
String
rootsql
,
final
String
msg
)
throws
SQLException
,
ParseException
,
IOException
,
SAXException
,
ParserConfigurationException
,
XPathExpressionException
{
try
{
try
(
Connection
con
=
dataSource
.
getConnection
())
{
InItCreateSchema
.
dropTable
();
InItCreateSchema
.
createTable
();
//
InItCreateSchema.dropTable();
//
InItCreateSchema.createTable();
DatabaseUtil
.
updateUsePreparedStatementToExecute
(
con
,
rootsql
,
anAssert
.
getParameters
());
String
expectedDataFile
=
PathUtil
.
getPath
(
anAssert
.
getExpectedDataFile
(),
rootPath
);
...
...
@@ -258,8 +274,8 @@ public class AssertEngine {
private
static
void
doUpdateUsePreparedStatementToExecuteUpdateDDL
(
final
String
rootPath
,
final
DataSource
dataSource
,
final
AssertDDLDefinition
anAssert
,
final
String
rootsql
,
final
String
msg
)
throws
SQLException
,
ParseException
,
IOException
,
SAXException
,
ParserConfigurationException
,
XPathExpressionException
{
try
{
try
(
Connection
con
=
dataSource
.
getConnection
())
{
InItCreateSchema
.
dropTable
();
InItCreateSchema
.
createTable
();
//
InItCreateSchema.dropTable();
//
InItCreateSchema.createTable();
DatabaseUtil
.
updateUsePreparedStatementToExecuteUpdate
(
con
,
rootsql
,
anAssert
.
getParameters
());
String
expectedDataFile
=
PathUtil
.
getPath
(
anAssert
.
getExpectedDataFile
(),
rootPath
);
...
...
@@ -301,8 +317,8 @@ public class AssertEngine {
private
static
void
doUpdateUseStatementToExecuteDDL
(
final
String
rootPath
,
final
DataSource
dataSource
,
final
AssertDDLDefinition
anAssert
,
final
String
rootsql
,
final
String
msg
)
throws
SQLException
,
ParseException
,
IOException
,
SAXException
,
ParserConfigurationException
,
XPathExpressionException
{
try
{
try
(
Connection
con
=
dataSource
.
getConnection
())
{
InItCreateSchema
.
dropTable
();
InItCreateSchema
.
createTable
();
//
InItCreateSchema.dropTable();
//
InItCreateSchema.createTable();
DatabaseUtil
.
updateUseStatementToExecute
(
con
,
rootsql
,
anAssert
.
getParameters
());
String
expectedDataFile
=
PathUtil
.
getPath
(
anAssert
.
getExpectedDataFile
(),
rootPath
);
...
...
@@ -343,8 +359,8 @@ public class AssertEngine {
private
static
void
doUpdateUseStatementToExecuteUpdateDDL
(
final
String
rootPath
,
final
DataSource
dataSource
,
final
AssertDDLDefinition
anAssert
,
final
String
rootsql
,
final
String
msg
)
throws
SQLException
,
ParseException
,
IOException
,
SAXException
,
ParserConfigurationException
,
XPathExpressionException
{
try
{
try
(
Connection
con
=
dataSource
.
getConnection
())
{
InItCreateSchema
.
dropTable
(
);
InItCreateSchema
.
createTable
(
);
//InItCreateSchema.dropTable(anAssert.getCleanSql()
);
//InItCreateSchema.createTable(anAssert.getInitSql()
);
DatabaseUtil
.
updateUseStatementToExecuteUpdate
(
con
,
rootsql
,
anAssert
.
getParameters
());
String
expectedDataFile
=
PathUtil
.
getPath
(
anAssert
.
getExpectedDataFile
(),
rootPath
);
DatasetDefinition
checkDataset
=
AnalyzeDataset
.
analyze
(
new
File
(
expectedDataFile
));
...
...
@@ -354,8 +370,8 @@ public class AssertEngine {
DatabaseUtil
.
assertConfigs
(
checkDataset
,
columnDefinitions
,
table
,
msg
);
}
}
finally
{
InItCreateSchema
.
dropTable
();
InItCreateSchema
.
createTable
();
InItCreateSchema
.
dropTable
(
anAssert
.
getCleanSql
()
);
InItCreateSchema
.
createTable
(
anAssert
.
getInitSql
()
);
}
}
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDDLDefinition.java
浏览文件 @
55a36ec7
...
...
@@ -31,8 +31,11 @@ public class AssertDDLDefinition implements AssertDefinition {
@XmlAttribute
(
name
=
"id"
)
private
String
id
;
@XmlAttribute
(
name
=
"init-data-file"
)
private
String
initDataFile
;
@XmlAttribute
(
name
=
"init-sql"
)
private
String
initSql
;
@XmlAttribute
(
name
=
"clean-sql"
)
private
String
cleanSql
;
@XmlAttribute
(
name
=
"expected-data-file"
)
private
String
expectedDataFile
;
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java
浏览文件 @
55a36ec7
...
...
@@ -92,6 +92,15 @@ public class InItCreateSchema {
}
}
/**
* Initialize the database table.
*/
public
static
synchronized
void
createTable
(
final
String
sqlId
)
{
for
(
DatabaseType
db
:
DATABASE_SCHEMAS
)
{
createSchema
(
db
,
sqlId
);
}
}
/**
* Initialize the database table.
*/
...
...
@@ -101,6 +110,15 @@ public class InItCreateSchema {
}
}
/**
* Initialize the database table.
*/
public
static
synchronized
void
dropTable
(
final
String
sqlId
)
{
for
(
DatabaseType
db
:
DATABASE_SCHEMAS
)
{
dropSchema
(
db
,
sqlId
);
}
}
/**
* Create a database.
*/
...
...
@@ -205,33 +223,38 @@ public class InItCreateSchema {
createShardingSchema
(
dbType
);
}
private
static
void
createSchema
(
final
DatabaseType
dbType
,
final
String
sqlId
)
{
createShardingSchema
(
dbType
,
sqlId
);
}
private
static
void
dropSchema
(
final
DatabaseType
dbType
)
{
dropShardingSchema
(
dbType
);
}
private
static
void
dropSchema
(
final
DatabaseType
dbType
,
final
String
sqlId
)
{
dropShardingSchema
(
dbType
,
sqlId
);
}
private
static
void
createShardingSchema
(
final
DatabaseType
dbType
)
{
Connection
conn
=
null
;
ResultSet
resultSet
=
null
;
StringReader
sr
=
null
;
try
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
String
each
:
DATABASES
)
{
List
<
String
>
databases
=
AnalyzeDatabase
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/database.xml"
);
for
(
String
database
:
databases
)
{
conn
=
initialConnection
(
database
,
dbType
);
List
<
String
>
tableSqlIds
=
AnalyzeSql
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/table/create-table.xml"
);
List
<
String
>
tableSqls
=
new
ArrayList
<>();
for
(
String
tableSqlId
:
tableSqlIds
)
{
tableSqls
.
add
(
SQLCasesLoader
.
getInstance
().
getSchemaSQLCaseMap
(
tableSqlId
));
}
sr
=
new
StringReader
(
StringUtils
.
join
(
tableSqls
,
";\n"
));
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
for
(
String
each
:
DATABASES
)
{
List
<
String
>
databases
=
AnalyzeDatabase
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/database.xml"
);
for
(
String
database
:
databases
)
{
conn
=
initialConnection
(
database
,
dbType
);
List
<
String
>
tableSqlIds
=
AnalyzeSql
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/table/create-table.xml"
);
List
<
String
>
tableSqls
=
new
ArrayList
<>();
for
(
String
tableSqlId
:
tableSqlIds
)
{
tableSqls
.
add
(
SQLCasesLoader
.
getInstance
().
getSchemaSQLCaseMap
(
tableSqlId
));
}
sr
=
new
StringReader
(
StringUtils
.
join
(
tableSqls
,
";\n"
));
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
}
}
...
...
@@ -258,31 +281,113 @@ public class InItCreateSchema {
}
}
private
static
void
createShardingSchema
(
final
DatabaseType
dbType
,
final
String
sqlId
)
{
Connection
conn
=
null
;
ResultSet
resultSet
=
null
;
StringReader
sr
=
null
;
try
{
for
(
String
each
:
DATABASES
)
{
List
<
String
>
databases
=
AnalyzeDatabase
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/database.xml"
);
for
(
String
database
:
databases
)
{
conn
=
initialConnection
(
database
,
dbType
);
List
<
String
>
tableSqls
=
new
ArrayList
<>();
tableSqls
.
add
(
SQLCasesLoader
.
getInstance
().
getSchemaSQLCaseMap
(
sqlId
));
sr
=
new
StringReader
(
StringUtils
.
join
(
tableSqls
,
";\n"
));
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
}
}
}
catch
(
SQLException
|
ParserConfigurationException
|
IOException
|
XPathExpressionException
|
SAXException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
sr
!=
null
)
{
sr
.
close
();
}
if
(
resultSet
!=
null
)
{
try
{
resultSet
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
if
(
conn
!=
null
)
{
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
}
private
static
void
dropShardingSchema
(
final
DatabaseType
dbType
)
{
Connection
conn
=
null
;
ResultSet
resultSet
=
null
;
StringReader
sr
=
null
;
try
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
String
each
:
DATABASES
)
{
List
<
String
>
databases
=
AnalyzeDatabase
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/database.xml"
);
for
(
String
database
:
databases
)
{
conn
=
initialConnection
(
database
,
dbType
);
List
<
String
>
tableSqlIds
=
AnalyzeSql
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/table/drop-table.xml"
);
List
<
String
>
tableSqls
=
new
ArrayList
<>();
for
(
String
tableSqlId
:
tableSqlIds
)
{
tableSqls
.
add
(
SQLCasesLoader
.
getInstance
().
getSchemaSQLCaseMap
(
tableSqlId
));
}
sr
=
new
StringReader
(
StringUtils
.
join
(
tableSqls
,
";\n"
));
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
for
(
String
each
:
DATABASES
)
{
List
<
String
>
databases
=
AnalyzeDatabase
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/database.xml"
);
for
(
String
database
:
databases
)
{
conn
=
initialConnection
(
database
,
dbType
);
List
<
String
>
tableSqlIds
=
AnalyzeSql
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/table/drop-table.xml"
);
List
<
String
>
tableSqls
=
new
ArrayList
<>();
for
(
String
tableSqlId
:
tableSqlIds
)
{
tableSqls
.
add
(
SQLCasesLoader
.
getInstance
().
getSchemaSQLCaseMap
(
tableSqlId
));
}
sr
=
new
StringReader
(
StringUtils
.
join
(
tableSqls
,
";\n"
));
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
}
}
}
catch
(
SQLException
|
ParserConfigurationException
|
IOException
|
XPathExpressionException
|
SAXException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
sr
!=
null
)
{
sr
.
close
();
}
if
(
resultSet
!=
null
)
{
try
{
resultSet
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
if
(
conn
!=
null
)
{
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
}
private
static
void
dropShardingSchema
(
final
DatabaseType
dbType
,
final
String
sqlId
)
{
Connection
conn
=
null
;
ResultSet
resultSet
=
null
;
StringReader
sr
=
null
;
try
{
for
(
String
each
:
DATABASES
)
{
List
<
String
>
databases
=
AnalyzeDatabase
.
analyze
(
InItCreateSchema
.
class
.
getClassLoader
()
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
each
+
"/database.xml"
);
for
(
String
database
:
databases
)
{
conn
=
initialConnection
(
database
,
dbType
);
List
<
String
>
tableSqls
=
new
ArrayList
<>();
tableSqls
.
add
(
SQLCasesLoader
.
getInstance
().
getSchemaSQLCaseMap
(
sqlId
));
sr
=
new
StringReader
(
StringUtils
.
join
(
tableSqls
,
";\n"
));
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
}
}
}
catch
(
SQLException
|
ParserConfigurationException
|
IOException
|
XPathExpressionException
|
SAXException
e
)
{
e
.
printStackTrace
();
}
finally
{
...
...
sharding-jdbc-core/src/test/resources/asserts/assert-test-data/assert-test.xml
浏览文件 @
55a36ec7
...
...
@@ -9,7 +9,8 @@
</assertDQL>
<assertDML
id=
"test2"
init-data-file=
"./init"
expected-update=
"1"
sql=
"assertUpdateWithoutAlias"
expected-sql=
"assertSelectEqualsWithSingleTable"
expected-data-file=
"./asserts/dml/update.xml"
>
expected-data-file=
"./asserts/dml/update.xml"
>
<parameters>
<parameter
value=
"update"
/>
<parameter
value=
"1000"
type=
"int"
/>
...
...
@@ -20,7 +21,7 @@
<parameter
value=
"1000"
type=
"int"
/>
</expected-parameters>
</assertDML>
<assertDDL
id=
"test3"
init-
data-file=
"./init
"
expected-update=
"1"
sql=
"assertAlterTableTOrder"
<assertDDL
id=
"test3"
init-
sql=
"dbCreateTOrder"
clean-sql=
"dbDropTOrder
"
expected-update=
"1"
sql=
"assertAlterTableTOrder"
table=
"t_order"
expected-data-file=
"./asserts/ddl/update.xml"
>
</assertDDL>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录