【问题标题】:arquillian and flyway: Migrations are not executedarquillian 和 flyway:不执行迁移
【发布时间】:2017-10-24 20:56:32
【问题描述】:

我在嵌入式野蝇上运行了 arquillian 测试。即使所有迁移脚本、Integrator 类(在其中设置 FlyWay)和所有 flyway 包(来自 POM 文件)都包含在 .war 文件(部署在嵌入式 Wildfly 上)中的 shrinkwrap 中,但不会进行迁移。

这有什么原因吗?这主要是行不通还是我错过了什么?

我希望实现的是,由 arquillian 运行的自动化测试将使用相同的迁移脚本设置一个与生产数据库具有相同方案的内存数据库。

edit:正如 ytg 下面问的,我添加了 Integrator 类;但是,此代码未在 arquillian 测试中输入;如果我在集成方法之上设置断点,它将永远不会被命中。为什么?

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;

public class FlywayIntegrator implements Integrator
{
    @Override
    public void integrate(final Configuration configuration,
                          final SessionFactoryImplementor sessionFactoryImplementor,
                          final SessionFactoryServiceRegistry sessionFactoryServiceRegistry)
    {

        System.out.println("Starting Flyway database migrations");

        Flyway flywayEvending = new Flyway();

        // enable this to migrate from the state currently on useqrnow.com
        flywayEvending.setBaselineVersionAsString("0");
        flywayEvending.setBaselineOnMigrate(true);
        flywayEvending.setDataSource(...)

        flywayEvending.setLocations(...);
        for (MigrationInfo i : flywayEvending.info().all())
        {
            System.out.println("migrate task: " + i.getVersion() + " : " + i.getDescription() + " from file: " + i.getScript());
        }
        flywayEvending.migrate();
    }

    @Override
    public void integrate(final MetadataImplementor metadataImplementor, final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry)
    {
        // do nothing
    }

    @Override
    public void disintegrate(final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry)
    {
        // do nothing
    }
}

【问题讨论】:

  • 请包含您的 Integrator 类中的设置代码。
  • 好的,即使没有输入此代码,我也添加了它。如果我设置了一个断点,它不会在运行 arquillian 测试期间被击中......
  • 如果您针对 WildFly 等应用程序容器对其进行测试,您应该在调试模式下运行它并附加远程调试器,否则您只能对运行测试的 JVM 进行调试(这不是一回事)。
  • 谢谢,@bartosz.majsak,但这很清楚。顺便说一句,它不输入​​代码只是一致的,因为我还说,没有进行任何迁移。如果它会进入代码而不迁移,那么很有可能会出现异常......有什么更好的主意吗?
  • 您可以尝试使用托管 WF 吗?

标签: jakarta-ee flyway jboss-arquillian


【解决方案1】:

很久之后,我重新尝试解决这个问题。这很简单:我错过了添加文件META-INF/services/org.hibernate.integrator.spi.Integrator,我们必须在其中存储积分器类。我需要将此文件添加到 ShrinkWrap 创建的 .war 中。

【讨论】:

    猜你喜欢
    • 2016-10-24
    • 2021-04-13
    • 1970-01-01
    • 2018-07-29
    • 2020-11-15
    • 2016-09-12
    • 2016-12-12
    • 2016-06-21
    • 2015-04-10
    相关资源
    最近更新 更多