Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
三久
DolphinScheduler
提交
1c7c4967
DolphinScheduler
项目概览
三久
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1c7c4967
编写于
4月 25, 2021
作者:
S
Shiwen Cheng
提交者:
GitHub
4月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "[Improvement][DAO] CreateDolphinScheduler (#5357) (#5358)"
This reverts commit
b108ac43
.
上级
e6d8da48
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
137 addition
and
236 deletion
+137
-236
dolphinscheduler-dao/pom.xml
dolphinscheduler-dao/pom.xml
+0
-17
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/DolphinSchedulerManager.java
...dolphinscheduler/dao/upgrade/DolphinSchedulerManager.java
+3
-8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
...a/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
+100
-37
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/shell/CreateDolphinScheduler.java
...inscheduler/dao/upgrade/shell/CreateDolphinScheduler.java
+17
-17
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/shell/InitDolphinScheduler.java
...phinscheduler/dao/upgrade/shell/InitDolphinScheduler.java
+9
-14
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDaoTest.java
...g/apache/dolphinscheduler/dao/upgrade/UpgradeDaoTest.java
+8
-61
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/shell/CreateDolphinSchedulerTest.java
...heduler/dao/upgrade/shell/CreateDolphinSchedulerTest.java
+0
-40
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/shell/InitDolphinSchedulerTest.java
...scheduler/dao/upgrade/shell/InitDolphinSchedulerTest.java
+0
-40
pom.xml
pom.xml
+0
-2
未找到文件。
dolphinscheduler-dao/pom.xml
浏览文件 @
1c7c4967
...
@@ -151,22 +151,5 @@
...
@@ -151,22 +151,5 @@
<groupId>
org.yaml
</groupId>
<groupId>
org.yaml
</groupId>
<artifactId>
snakeyaml
</artifactId>
<artifactId>
snakeyaml
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.powermock
</groupId>
<artifactId>
powermock-module-junit4
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.powermock
</groupId>
<artifactId>
powermock-api-mockito2
</artifactId>
<scope>
test
</scope>
<exclusions>
<exclusion>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/DolphinSchedulerManager.java
浏览文件 @
1c7c4967
...
@@ -14,19 +14,14 @@
...
@@ -14,19 +14,14 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.dolphinscheduler.dao.upgrade
;
package
org.apache.dolphinscheduler.dao.upgrade
;
import
org.apache.dolphinscheduler.common.enums.DbType
;
import
org.apache.dolphinscheduler.common.enums.DbType
;
import
org.apache.dolphinscheduler.common.utils.SchemaUtils
;
import
org.apache.dolphinscheduler.common.utils.SchemaUtils
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
/**
* upgrade manager
* upgrade manager
...
@@ -65,7 +60,7 @@ public class DolphinSchedulerManager {
...
@@ -65,7 +60,7 @@ public class DolphinSchedulerManager {
/**
/**
* init DolphinScheduler
* init DolphinScheduler
*/
*/
public
void
initDolphinScheduler
()
throws
SQLException
,
IOException
{
public
void
initDolphinScheduler
()
{
// Determines whether the dolphinscheduler table structure has been init
// Determines whether the dolphinscheduler table structure has been init
if
(
upgradeDao
.
isExistsTable
(
"t_escheduler_version"
)
||
if
(
upgradeDao
.
isExistsTable
(
"t_escheduler_version"
)
||
upgradeDao
.
isExistsTable
(
"t_ds_version"
)
||
upgradeDao
.
isExistsTable
(
"t_ds_version"
)
||
...
@@ -79,7 +74,7 @@ public class DolphinSchedulerManager {
...
@@ -79,7 +74,7 @@ public class DolphinSchedulerManager {
/**
/**
* init DolphinScheduler Schema
* init DolphinScheduler Schema
*/
*/
public
void
initDolphinSchedulerSchema
()
throws
SQLException
,
IOException
{
public
void
initDolphinSchedulerSchema
()
{
logger
.
info
(
"Start initializing the DolphinScheduler manager table structure"
);
logger
.
info
(
"Start initializing the DolphinScheduler manager table structure"
);
upgradeDao
.
initSchema
();
upgradeDao
.
initSchema
();
...
...
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
浏览文件 @
1c7c4967
...
@@ -14,25 +14,20 @@
...
@@ -14,25 +14,20 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.dolphinscheduler.dao.upgrade
;
package
org.apache.dolphinscheduler.dao.upgrade
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.dolphinscheduler.common.enums.DbType
;
import
org.apache.dolphinscheduler.common.enums.DbType
;
import
org.apache.dolphinscheduler.common.process.ResourceInfo
;
import
org.apache.dolphinscheduler.common.process.ResourceInfo
;
import
org.apache.dolphinscheduler.common.utils.CollectionUtils
;
import
org.apache.dolphinscheduler.common.utils.*
;
import
org.apache.dolphinscheduler.common.utils.ConnectionUtils
;
import
org.apache.dolphinscheduler.common.utils.JSONUtils
;
import
org.apache.dolphinscheduler.common.utils.SchemaUtils
;
import
org.apache.dolphinscheduler.common.utils.ScriptRunner
;
import
org.apache.dolphinscheduler.common.utils.StringUtils
;
import
org.apache.dolphinscheduler.dao.AbstractBaseDao
;
import
org.apache.dolphinscheduler.dao.AbstractBaseDao
;
import
org.apache.dolphinscheduler.dao.datasource.ConnectionFactory
;
import
org.apache.dolphinscheduler.dao.datasource.ConnectionFactory
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
javax.sql.DataSource
;
import
java.io.FileNotFoundException
;
import
java.io.*
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
...
@@ -43,14 +38,6 @@ import java.util.List;
...
@@ -43,14 +38,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
javax.sql.DataSource
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
public
abstract
class
UpgradeDao
extends
AbstractBaseDao
{
public
abstract
class
UpgradeDao
extends
AbstractBaseDao
{
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UpgradeDao
.
class
);
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UpgradeDao
.
class
);
...
@@ -60,9 +47,6 @@ public abstract class UpgradeDao extends AbstractBaseDao {
...
@@ -60,9 +47,6 @@ public abstract class UpgradeDao extends AbstractBaseDao {
protected
static
final
DataSource
dataSource
=
getDataSource
();
protected
static
final
DataSource
dataSource
=
getDataSource
();
private
static
final
DbType
dbType
=
getCurrentDbType
();
private
static
final
DbType
dbType
=
getCurrentDbType
();
private
static
final
String
MYSQL_CREATE_SCRIPT
=
rootDir
+
"/sql/dolphinscheduler_mysql.sql"
;
private
static
final
String
POSTGRE_CREATE_SCRIPT
=
rootDir
+
"/sql/dolphinscheduler_postgre.sql"
;
@Override
@Override
protected
void
init
()
{
protected
void
init
()
{
...
@@ -106,40 +90,119 @@ public abstract class UpgradeDao extends AbstractBaseDao {
...
@@ -106,40 +90,119 @@ public abstract class UpgradeDao extends AbstractBaseDao {
/**
/**
* init schema
* init schema
*/
*/
public
void
initSchema
()
throws
SQLException
,
IOException
{
public
void
initSchema
()
{
DbType
dbType
=
getDbType
();
DbType
dbType
=
getDbType
();
String
initSqlPath
=
""
;
String
initSqlPath
=
""
;
if
(
dbType
!=
null
)
{
if
(
dbType
!=
null
)
{
switch
(
dbType
)
{
switch
(
dbType
)
{
case
MYSQL:
case
MYSQL:
initSqlPath
=
MYSQL_CREATE_SCRIPT
;
initSqlPath
=
"/sql/create/release-1.0.0_schema/mysql/"
;
initSchema
(
initSqlPath
);
break
;
break
;
case
POSTGRESQL:
case
POSTGRESQL:
initSqlPath
=
POSTGRE_CREATE_SCRIPT
;
initSqlPath
=
"/sql/create/release-1.2.0_schema/postgresql/"
;
initSchema
(
initSqlPath
);
break
;
break
;
default
:
default
:
logger
.
error
(
"not support sql type: {},can't upgrade"
,
dbType
);
logger
.
error
(
"not support sql type: {},can't upgrade"
,
dbType
);
throw
new
IllegalArgumentException
(
"not support sql type,can't upgrade"
);
throw
new
IllegalArgumentException
(
"not support sql type,can't upgrade"
);
}
}
}
}
}
/**
* init scheam
*
* @param initSqlPath initSqlPath
*/
public
void
initSchema
(
String
initSqlPath
)
{
// Execute the dolphinscheduler DDL, it cannot be rolled back
runInitDDL
(
initSqlPath
);
// Execute the dolphinscheduler DML, it can be rolled back
runInitDML
(
initSqlPath
);
}
/**
* run DML
*
* @param initSqlPath initSqlPath
*/
private
void
runInitDML
(
String
initSqlPath
)
{
Connection
conn
=
null
;
if
(
StringUtils
.
isEmpty
(
rootDir
))
{
if
(
StringUtils
.
isEmpty
(
rootDir
))
{
throw
new
RuntimeException
(
"Environment variable user.dir not found"
);
throw
new
RuntimeException
(
"Environment variable user.dir not found"
);
}
}
logger
.
info
(
"Init sql filePath: {}"
,
initSqlPath
);
String
mysqlSQLFilePath
=
rootDir
+
initSqlPath
+
"dolphinscheduler_dml.sql"
;
try
(
Connection
conn
=
dataSource
.
getConnection
())
{
try
{
conn
=
dataSource
.
getConnection
();
conn
.
setAutoCommit
(
false
);
// Execute the dolphinscheduler_dml.sql script to import related data of dolphinscheduler
ScriptRunner
initScriptRunner
=
new
ScriptRunner
(
conn
,
false
,
true
);
Reader
initSqlReader
=
new
FileReader
(
new
File
(
mysqlSQLFilePath
));
initScriptRunner
.
runScript
(
initSqlReader
);
conn
.
commit
();
}
catch
(
IOException
e
)
{
try
{
try
{
conn
.
setAutoCommit
(
false
);
ScriptRunner
initScriptRunner
=
new
ScriptRunner
(
conn
,
false
,
true
);
Reader
initSqlReader
=
new
FileReader
(
initSqlPath
);
initScriptRunner
.
runScript
(
initSqlReader
);
conn
.
commit
();
}
catch
(
IOException
|
SQLException
e
)
{
conn
.
rollback
();
conn
.
rollback
();
logger
.
error
(
"execute init script error."
,
e
);
}
catch
(
SQLException
e1
)
{
throw
e
;
logger
.
error
(
e1
.
getMessage
(),
e1
)
;
}
}
logger
.
error
(
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
try
{
if
(
null
!=
conn
)
{
conn
.
rollback
();
}
}
catch
(
SQLException
e1
)
{
logger
.
error
(
e1
.
getMessage
(),
e1
);
}
logger
.
error
(
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
// ignore
ConnectionUtils
.
releaseResource
(
conn
);
}
}
/**
* run DDL
*
* @param initSqlPath initSqlPath
*/
private
void
runInitDDL
(
String
initSqlPath
)
{
Connection
conn
=
null
;
if
(
StringUtils
.
isEmpty
(
rootDir
))
{
throw
new
RuntimeException
(
"Environment variable user.dir not found"
);
}
//String mysqlSQLFilePath = rootDir + "/sql/create/release-1.0.0_schema/mysql/dolphinscheduler_ddl.sql";
String
mysqlSQLFilePath
=
rootDir
+
initSqlPath
+
"dolphinscheduler_ddl.sql"
;
try
{
conn
=
dataSource
.
getConnection
();
// Execute the dolphinscheduler_ddl.sql script to create the table structure of dolphinscheduler
ScriptRunner
initScriptRunner
=
new
ScriptRunner
(
conn
,
true
,
true
);
Reader
initSqlReader
=
new
FileReader
(
new
File
(
mysqlSQLFilePath
));
initScriptRunner
.
runScript
(
initSqlReader
);
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
e
.
getMessage
(),
e
);
}
finally
{
ConnectionUtils
.
releaseResource
(
conn
);
}
}
}
}
...
...
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/shell/CreateDolphinScheduler.java
浏览文件 @
1c7c4967
...
@@ -14,35 +14,35 @@
...
@@ -14,35 +14,35 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.dolphinscheduler.dao.upgrade.shell
;
package
org.apache.dolphinscheduler.dao.upgrade.shell
;
import
org.apache.dolphinscheduler.dao.upgrade.DolphinSchedulerManager
;
import
org.apache.dolphinscheduler.dao.upgrade.DolphinSchedulerManager
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
/**
/**
* create DolphinScheduler
* create DolphinScheduler
*
*/
*/
public
class
CreateDolphinScheduler
{
public
class
CreateDolphinScheduler
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CreateDolphinScheduler
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CreateDolphinScheduler
.
class
);
/**
/**
* create dolphin scheduler db
* create dolphin scheduler db
*
* @param args args
* @param args args
*/
*/
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
DolphinSchedulerManager
dolphinSchedulerManager
=
new
DolphinSchedulerManager
();
DolphinSchedulerManager
dolphinSchedulerManager
=
new
DolphinSchedulerManager
();
try
{
try
{
dolphinSchedulerManager
.
initDolphinScheduler
();
logger
.
info
(
"create DolphinScheduler begin"
);
logger
.
info
(
"init DolphinScheduler finished"
);
dolphinSchedulerManager
.
initDolphinScheduler
();
dolphinSchedulerManager
.
upgradeDolphinScheduler
();
logger
.
info
(
"create DolphinScheduler success"
);
logger
.
info
(
"upgrade DolphinScheduler finished"
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"create DolphinScheduler success"
);
logger
.
error
(
"create DolphinScheduler failed"
,
e
);
}
catch
(
Exception
e
)
{
}
logger
.
error
(
"create DolphinScheduler failed"
,
e
);
}
}
}
}
}
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/shell/InitDolphinScheduler.java
浏览文件 @
1c7c4967
...
@@ -14,34 +14,29 @@
...
@@ -14,34 +14,29 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.dolphinscheduler.dao.upgrade.shell
;
package
org.apache.dolphinscheduler.dao.upgrade.shell
;
import
org.apache.dolphinscheduler.dao.upgrade.DolphinSchedulerManager
;
import
org.apache.dolphinscheduler.dao.upgrade.DolphinSchedulerManager
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
/**
/**
* init DolphinScheduler
* init DolphinScheduler
*
*/
*/
public
class
InitDolphinScheduler
{
public
class
InitDolphinScheduler
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
InitDolphinScheduler
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
InitDolphinScheduler
.
class
);
/**
/**
* init dolphin scheduler db
* init dolphin scheduler db
* @param args args
* @param args args
*/
*/
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Thread
.
currentThread
().
setName
(
"manager-InitDolphinScheduler"
);
Thread
.
currentThread
().
setName
(
"manager-InitDolphinScheduler"
);
DolphinSchedulerManager
dolphinSchedulerManager
=
new
DolphinSchedulerManager
();
DolphinSchedulerManager
dolphinSchedulerManager
=
new
DolphinSchedulerManager
();
try
{
dolphinSchedulerManager
.
initDolphinScheduler
();
dolphinSchedulerManager
.
initDolphinScheduler
();
logger
.
info
(
"init DolphinScheduler finished"
);
logger
.
info
(
"init DolphinScheduler finished"
);
}
catch
(
Exception
ex
)
{
}
logger
.
error
(
"init DolphinScheduler error"
,
ex
);
}
}
}
}
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDaoTest.java
浏览文件 @
1c7c4967
...
@@ -14,76 +14,23 @@
...
@@ -14,76 +14,23 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.dolphinscheduler.dao.upgrade
;
package
org.apache.dolphinscheduler.dao.upgrade
;
import
org.apache.dolphinscheduler.common.utils.ScriptRunner
;
import
org.junit.Test
;
import
org.apache.dolphinscheduler.dao.datasource.ConnectionFactory
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
java.util.Map
;
import
org.junit.Assert
;
import
static
org
.
apache
.
dolphinscheduler
.
dao
.
upgrade
.
UpgradeDao
.
getDataSource
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThanOrEqualTo
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
org.mockito.Mockito
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
@RunWith
(
PowerMockRunner
.
class
)
@PrepareForTest
({
ConnectionFactory
.
class
,
ScriptRunner
.
class
,
FileReader
.
class
})
public
class
UpgradeDaoTest
{
public
class
UpgradeDaoTest
{
PostgresqlUpgradeDao
postgresqlUpgradeDao
=
PostgresqlUpgradeDao
.
getInstance
();
@Test
@Test
public
void
testGetCurrentVersion
()
throws
SQLException
{
public
void
testQueryQueryAllOldWorkerGroup
()
throws
Exception
{
PowerMockito
.
mockStatic
(
ConnectionFactory
.
class
);
postgresqlUpgradeDao
.
updateProcessDefinitionJsonWorkerGroup
();
ConnectionFactory
mockConnectionFactory
=
PowerMockito
.
mock
(
ConnectionFactory
.
class
);
PowerMockito
.
when
(
ConnectionFactory
.
getInstance
()).
thenReturn
(
mockConnectionFactory
);
DataSource
mockDatasource
=
PowerMockito
.
mock
(
DataSource
.
class
);
PowerMockito
.
when
(
mockConnectionFactory
.
getDataSource
()).
thenReturn
(
mockDatasource
);
Connection
mockConnection
=
PowerMockito
.
mock
(
Connection
.
class
);
PowerMockito
.
when
(
mockDatasource
.
getConnection
()).
thenReturn
(
mockConnection
);
PreparedStatement
mockPrepareStatement
=
PowerMockito
.
mock
(
PreparedStatement
.
class
);
PowerMockito
.
when
(
mockConnection
.
prepareStatement
(
Mockito
.
any
())).
thenReturn
(
mockPrepareStatement
);
ResultSet
mockResultSet
=
PowerMockito
.
mock
(
ResultSet
.
class
);
PowerMockito
.
when
(
mockPrepareStatement
.
executeQuery
()).
thenReturn
(
mockResultSet
);
DatabaseMetaData
mockMetaData
=
PowerMockito
.
mock
(
DatabaseMetaData
.
class
);
PowerMockito
.
when
(
mockConnection
.
getMetaData
()).
thenReturn
(
mockMetaData
);
PowerMockito
.
when
(
mockMetaData
.
getDatabaseProductName
()).
thenReturn
(
"mysql"
);
UpgradeDao
upgradeDao
=
MysqlUpgradeDao
.
getInstance
();
upgradeDao
.
getCurrentVersion
(
"xx"
);
Assert
.
assertTrue
(
true
);
}
}
@Test
(
expected
=
IOException
.
class
)
public
void
testInitSchema
()
throws
Exception
{
PowerMockito
.
mockStatic
(
ConnectionFactory
.
class
);
ConnectionFactory
mockConnectionFactory
=
PowerMockito
.
mock
(
ConnectionFactory
.
class
);
PowerMockito
.
when
(
ConnectionFactory
.
getInstance
()).
thenReturn
(
mockConnectionFactory
);
DataSource
mockDatasource
=
PowerMockito
.
mock
(
DataSource
.
class
);
PowerMockito
.
when
(
mockConnectionFactory
.
getDataSource
()).
thenReturn
(
mockDatasource
);
Connection
mockConnection
=
PowerMockito
.
mock
(
Connection
.
class
);
PowerMockito
.
when
(
mockDatasource
.
getConnection
()).
thenReturn
(
mockConnection
);
DatabaseMetaData
mockMetaData
=
PowerMockito
.
mock
(
DatabaseMetaData
.
class
);
PowerMockito
.
when
(
mockConnection
.
getMetaData
()).
thenReturn
(
mockMetaData
);
PowerMockito
.
when
(
mockMetaData
.
getDatabaseProductName
()).
thenReturn
(
"mysql"
);
UpgradeDao
upgradeDao
=
MysqlUpgradeDao
.
getInstance
();
upgradeDao
.
initSchema
();
Assert
.
assertTrue
(
true
);
}
}
}
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/shell/CreateDolphinSchedulerTest.java
已删除
100644 → 0
浏览文件 @
e6d8da48
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.dolphinscheduler.dao.upgrade.shell
;
import
org.apache.dolphinscheduler.dao.upgrade.DolphinSchedulerManager
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
@RunWith
(
PowerMockRunner
.
class
)
@PrepareForTest
({
DolphinSchedulerManager
.
class
,
CreateDolphinScheduler
.
class
})
public
class
CreateDolphinSchedulerTest
{
@Test
public
void
mainTest
()
throws
Exception
{
DolphinSchedulerManager
mockManager
=
PowerMockito
.
mock
(
DolphinSchedulerManager
.
class
);
PowerMockito
.
whenNew
(
DolphinSchedulerManager
.
class
).
withNoArguments
().
thenReturn
(
mockManager
);
CreateDolphinScheduler
.
main
(
null
);
Assert
.
assertTrue
(
true
);
}
}
\ No newline at end of file
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/shell/InitDolphinSchedulerTest.java
已删除
100644 → 0
浏览文件 @
e6d8da48
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.dolphinscheduler.dao.upgrade.shell
;
import
org.apache.dolphinscheduler.dao.upgrade.DolphinSchedulerManager
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
@RunWith
(
PowerMockRunner
.
class
)
@PrepareForTest
({
DolphinSchedulerManager
.
class
,
InitDolphinScheduler
.
class
})
public
class
InitDolphinSchedulerTest
{
@Test
public
void
main
()
throws
Exception
{
DolphinSchedulerManager
mockManager
=
PowerMockito
.
mock
(
DolphinSchedulerManager
.
class
);
PowerMockito
.
whenNew
(
DolphinSchedulerManager
.
class
).
withNoArguments
().
thenReturn
(
mockManager
);
InitDolphinScheduler
.
main
(
null
);
Assert
.
assertTrue
(
true
);
}
}
\ No newline at end of file
pom.xml
浏览文件 @
1c7c4967
...
@@ -910,8 +910,6 @@
...
@@ -910,8 +910,6 @@
<include>
**/dao/datasource/MySQLDataSourceTest.java
</include>
<include>
**/dao/datasource/MySQLDataSourceTest.java
</include>
<include>
**/dao/entity/TaskInstanceTest.java
</include>
<include>
**/dao/entity/TaskInstanceTest.java
</include>
<include>
**/dao/entity/UdfFuncTest.java
</include>
<include>
**/dao/entity/UdfFuncTest.java
</include>
<include>
**/dao/upgrade/shell/CreateDolphinSchedulerTest.java
</include>
<include>
**/dao/upgrade/shell/InitDolphinSchedulerTest.java
</include>
<include>
**/remote/command/alert/AlertSendRequestCommandTest.java
</include>
<include>
**/remote/command/alert/AlertSendRequestCommandTest.java
</include>
<include>
**/remote/command/alert/AlertSendResponseCommandTest.java
</include>
<include>
**/remote/command/alert/AlertSendResponseCommandTest.java
</include>
<include>
**/remote/command/future/ResponseFutureTest.java
</include>
<include>
**/remote/command/future/ResponseFutureTest.java
</include>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录