Skip to content

Commit

Permalink
Revert "automatically run dropall before and after all integration te…
Browse files Browse the repository at this point in the history
…sts (#5493)"

This reverts commit 7197262.
  • Loading branch information
abrackx committed Jan 23, 2024
1 parent 88d2498 commit 1cbbb10
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package liquibase.extension.testing.testsystem.spock;

import liquibase.Scope;
import liquibase.command.CommandScope;
import liquibase.command.core.DropAllCommandStep;
import liquibase.command.core.helpers.DbUrlConnectionArgumentsCommandStep;
import liquibase.configuration.ConfigurationValueConverter;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.extension.testing.testsystem.DatabaseTestSystem;
import liquibase.extension.testing.testsystem.TestSystem;
import liquibase.lockservice.LockService;
import liquibase.lockservice.LockServiceFactory;
import org.junit.Assume;
import org.spockframework.runtime.extension.AbstractMethodInterceptor;
import org.spockframework.runtime.extension.IMethodInvocation;
import org.spockframework.runtime.model.FieldInfo;
import org.spockframework.runtime.model.SpecInfo;

import java.io.ByteArrayOutputStream;
import java.util.*;

public class LiquibaseIntegrationMethodInterceptor extends AbstractMethodInterceptor {
Expand Down Expand Up @@ -63,13 +57,7 @@ private void verifyNoMultipleDatabases(SpecInfo spec) {
public void interceptSetupSpecMethod(IMethodInvocation invocation) throws Throwable {
final List<FieldInfo> containers = findAllContainers();
startContainers(containers, invocation);
dropAllDatabases();
invocation.proceed();
}

@Override
public void interceptSetupMethod(IMethodInvocation invocation) throws Throwable {
dropAllDatabases();
invocation.proceed();
}

Expand Down Expand Up @@ -124,32 +112,6 @@ private static TestSystem readContainerFromField(FieldInfo f, IMethodInvocation
*/
@Override
public void interceptCleanupSpecMethod(IMethodInvocation invocation) throws Throwable {
dropAllDatabases();
invocation.proceed();
}

private static void dropAllDatabases() throws Exception {
for (TestSystem startedTestSystem : startedTestSystems) {
if (startedTestSystem instanceof DatabaseTestSystem) {
runDropAll(((DatabaseTestSystem) startedTestSystem));
}
}
}

@Override
public void interceptCleanupMethod(IMethodInvocation invocation) throws Throwable {
dropAllDatabases();
invocation.proceed();
}

private static void runDropAll(DatabaseTestSystem db) throws Exception {
LockService lockService = LockServiceFactory.getInstance().getLockService(db.getDatabaseFromFactory());
lockService.releaseLock();
CommandScope commandScope = new CommandScope(DropAllCommandStep.COMMAND_NAME);
commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, db.getConnectionUrl());
commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, db.getUsername());
commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, db.getPassword());
commandScope.setOutput(new ByteArrayOutputStream());
commandScope.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class ClearCheckSumsIntegrationTest extends Specification {
@Shared
private DatabaseTestSystem h2 = (DatabaseTestSystem) Scope.currentScope.getSingleton(TestSystemFactory.class).getTestSystem("h2")

def "validate checksums are cleared"() {
given:
def setupSpec(){
def updateCommand = new CommandScope(UpdateCommandStep.COMMAND_NAME)
updateCommand.addArgumentValue(DbUrlConnectionArgumentsCommandStep.DATABASE_ARG, h2.getDatabaseFromFactory())
updateCommand.addArgumentValue(UpdateSqlCommandStep.CHANGELOG_FILE_ARG, "liquibase/update-tests.yml")
updateCommand.execute()
}

def "validate checksums are cleared"() {
when:
def h2Database = h2.getDatabaseFromFactory()
def commandResults = new CommandScope("clearChecksums")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GenerateChangeLogMySQLIntegrationTest extends Specification {
@Shared
private DatabaseTestSystem mysql = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("mysql")

def setup() {
def setupSpec() {
CommandUtil.runDropAll(mysql)
def sql = """
create table str4 (
Expand Down

0 comments on commit 1cbbb10

Please sign in to comment.