Commit e378cccf by 钟明宏

增加单元测试插件以及增加了部分注释

parent 30a79451
......@@ -41,6 +41,31 @@
<artifactId>postgresql</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
/*
* Copyright 2010-2019 Boxfuse GmbH
*
* 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.
*/
package org.flywaydb.core;
import org.flywaydb.core.api.FlywayException;
......@@ -85,7 +70,7 @@ public class Flyway {
/**
* Designed so we can fail fast if the configuration is invalid
*/
private ConfigurationValidator configurationValidator = new ConfigurationValidator();
private ConfigurationValidator configurationValidator = new ConfigurationValidator();
/**
* This is your starting point. This creates a configuration which can be customized to your needs before being
......@@ -151,8 +136,6 @@ public class Flyway {
public Integer execute(MigrationResolver migrationResolver,
SchemaHistory schemaHistory, Database database, Schema[] schemas, CallbackExecutor callbackExecutor
) {
if (configuration.isValidateOnMigrate()) {
doValidate(database, migrationResolver, schemaHistory, schemas, callbackExecutor,
......@@ -210,18 +193,6 @@ public class Flyway {
public int undo() throws FlywayException {
throw new org.flywaydb.core.internal.license.FlywayProUpgradeRequiredException("undo");
}
/**
......@@ -244,7 +215,6 @@ public class Flyway {
Schema[] schemas, CallbackExecutor callbackExecutor
) {
doValidate(database, migrationResolver, schemaHistory, schemas, callbackExecutor,
configuration.isIgnorePendingMigrations());
......@@ -295,7 +265,6 @@ public class Flyway {
Schema[] schemas, CallbackExecutor callbackExecutor
) {
doClean(database, schemaHistory, schemas, callbackExecutor);
return null;
......@@ -317,7 +286,6 @@ public class Flyway {
final Database database, final Schema[] schemas, CallbackExecutor callbackExecutor
) {
return new DbInfo(migrationResolver, schemaHistory, configuration, callbackExecutor).info();
}
......@@ -337,7 +305,6 @@ public class Flyway {
SchemaHistory schemaHistory, Database database, Schema[] schemas, CallbackExecutor callbackExecutor
) {
new DbSchemas(database, schemas, schemaHistory).create(true);
doBaseline(schemaHistory, callbackExecutor);
......@@ -362,7 +329,6 @@ public class Flyway {
SchemaHistory schemaHistory, Database database, Schema[] schemas, CallbackExecutor callbackExecutor
) {
new DbRepair(database, migrationResolver, schemaHistory, callbackExecutor, configuration).repair();
return null;
......@@ -376,7 +342,6 @@ public class Flyway {
SchemaHistory schemaHistory, Database database, Schema[] schemas, CallbackExecutor callbackExecutor
) {
if (!schemaHistory.exists()) {
List<Schema> nonEmptySchemas = new ArrayList<>();
......@@ -434,30 +399,16 @@ public class Flyway {
* @param <T> The type of the result.
* @return The result of the command.
*/
/*private -> testing*/ <T> T execute(Command<T> command, boolean scannerRequired) {
/*private -> testing*/
<T> T execute(Command<T> command, boolean scannerRequired) {
T result;
VersionPrinter.printVersion(
);
//打印版本号
VersionPrinter.printVersion();
//校验数据库设置是否为空
configurationValidator.validate(configuration);
final ResourceProvider resourceProvider;
ClassProvider<JavaMigration> classProvider;
//获取文件扫描器
if (!scannerRequired && configuration.isSkipDefaultResolvers() && configuration.isSkipDefaultCallbacks()) {
resourceProvider = NoopResourceProvider.INSTANCE;
//noinspection unchecked
......@@ -468,9 +419,6 @@ public class Flyway {
Arrays.asList(configuration.getLocations()),
configuration.getClassLoader(),
configuration.getEncoding()
, resourceNameCache
);
resourceProvider = scanner;
......@@ -478,25 +426,15 @@ public class Flyway {
}
JdbcConnectionFactory jdbcConnectionFactory = new JdbcConnectionFactory(configuration.getDataSource(),
configuration.getConnectRetries()
);
configuration.getConnectRetries());
final ParsingContext parsingContext = new ParsingContext();
final SqlScriptFactory sqlScriptFactory =
DatabaseFactory.createSqlScriptFactory(jdbcConnectionFactory, configuration, parsingContext);
final SqlScriptExecutorFactory noCallbackSqlScriptExecutorFactory = DatabaseFactory.createSqlScriptExecutorFactory(
jdbcConnectionFactory
);
final SqlScriptExecutorFactory noCallbackSqlScriptExecutorFactory = DatabaseFactory.createSqlScriptExecutorFactory(jdbcConnectionFactory);
//执行sql
jdbcConnectionFactory.setConnectionInitializer(new JdbcConnectionFactory.ConnectionInitializer() {
@Override
public void initialize(JdbcConnectionFactory jdbcConnectionFactory, Connection connection) {
......@@ -504,81 +442,39 @@ public class Flyway {
return;
}
StringResource resource = new StringResource(configuration.getInitSql());
SqlScript sqlScript = sqlScriptFactory.createSqlScript(resource, true
);
noCallbackSqlScriptExecutorFactory.createSqlScriptExecutor(connection
).execute(sqlScript);
SqlScript sqlScript = sqlScriptFactory.createSqlScript(resource, true);
noCallbackSqlScriptExecutorFactory.createSqlScriptExecutor(connection).execute(sqlScript);
}
});
Database database = null;
try {
database = DatabaseFactory.createDatabase(configuration, !dbConnectionInfoPrinted, jdbcConnectionFactory
);
database = DatabaseFactory.createDatabase(configuration, !dbConnectionInfoPrinted, jdbcConnectionFactory);
Schema currentSchema = getSchemaNameForParsingContext(database);
if (currentSchema != null) {
parsingContext.setCurrentSchema(currentSchema.getName());
}
dbConnectionInfoPrinted = true;
LOG.debug("DDL Transactions Supported: " + database.supportsDdlTransactions());
Schema[] schemas = prepareSchemas(database);
database.ensureSupported();
DefaultCallbackExecutor callbackExecutor = new DefaultCallbackExecutor(configuration, database, schemas[0],
prepareCallbacks(database, resourceProvider, jdbcConnectionFactory, sqlScriptFactory
prepareCallbacks(database, resourceProvider, jdbcConnectionFactory, sqlScriptFactory));
SqlScriptExecutorFactory sqlScriptExecutorFactory = DatabaseFactory.createSqlScriptExecutorFactory(jdbcConnectionFactory);
));
SqlScriptExecutorFactory sqlScriptExecutorFactory = DatabaseFactory.createSqlScriptExecutorFactory(jdbcConnectionFactory
);
result = command.execute(
createMigrationResolver(resourceProvider, classProvider, sqlScriptExecutorFactory, sqlScriptFactory),
SchemaHistoryFactory.getSchemaHistory(configuration, noCallbackSqlScriptExecutorFactory, sqlScriptFactory,
database, schemas[0]
),
database, schemas[0]),
database,
schemas,
callbackExecutor
);
callbackExecutor);
} finally {
IOUtils.close(database);
showMemoryUsage();
}
return result;
......@@ -633,28 +529,8 @@ public class Flyway {
SqlScriptFactory sqlScriptFactory
) {
List<Callback> effectiveCallbacks = new ArrayList<>();
effectiveCallbacks.addAll(Arrays.asList(configuration.getCallbacks()));
if (!configuration.isSkipDefaultCallbacks()) {
......@@ -662,8 +538,6 @@ public class Flyway {
DatabaseFactory.createSqlScriptExecutorFactory(jdbcConnectionFactory
);
effectiveCallbacks.addAll(
......@@ -676,9 +550,6 @@ public class Flyway {
}
return effectiveCallbacks;
}
......@@ -702,7 +573,6 @@ public class Flyway {
Database database, Schema[] schemas, CallbackExecutor callbackExecutor
);
}
}
\ No newline at end of file
......@@ -21,15 +21,6 @@ import org.flywaydb.core.api.configuration.Configuration;
public class ConfigurationValidator {
public void validate(Configuration configuration) {
if (configuration.getDataSource() == null) {
throw new FlywayException(
"Unable to connect to the database. Configure the url, user and password!",
......
......@@ -63,15 +63,8 @@ public class MySQLDatabase extends Database<MySQLConnection> {
* @param configuration The Flyway configuration.
*/
public MySQLDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory
) {
super(configuration, jdbcConnectionFactory
);
super(configuration, jdbcConnectionFactory);
JdbcTemplate jdbcTemplate = new JdbcTemplate(rawMainJdbcConnection, databaseType);
pxcStrict = isRunningInPerconaXtraDBClusterWithStrictMode(jdbcTemplate);
......
......@@ -54,6 +54,7 @@
<version.jre>11.0.2</version.jre>
<version.jansi>1.18</version.jansi>
<version.gson>2.8.6</version.gson>
<junit_jupiter_version>5.4.0</junit_jupiter_version>
</properties>
<dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment