【问题标题】:Spring integration test hanging, after having run successfully for a while成功运行一段时间后,Spring集成测试挂起
【发布时间】:2017-08-01 12:35:47
【问题描述】:

我继承了一个 Spring 集成测试,它已经运行了好几个月了,但是从昨天开始,它在设置“h2”数据库时甚至在运行“setup”方法之前就一直挂起。经过调试,我发现它在驱动程序级别挂起,当它在运行一些“导入”数据脚本的步骤中尝试读取一些数据时。数据库的测试配置是

@Configuration
@Profile("test")
@EnableJpaRepositories(basePackages = "x.y.z", entityManagerFactoryRef = "myEntityManagerFactory")
public class DatabaseConfig{

    @Bean(destroyMethod = "shutdown")
    @Primary
    public DataSource myDataSource() {
        EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
        EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).setName("XY").addScript("schema-xy.sql").build();
        return db;
    }

    @Bean
    @Primary
    public EntityManagerFactory fcEntityManagerFactory() throws SQLException {
         HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect");
        vendorAdapter.setShowSql(true);

        Properties jpaProperties = new Properties();
        jpaProperties.put("hibernate.hbm2ddl.auto", "create");
        jpaProperties.put("hibernate.hbm2ddl.import_files", "import-xy.sql");


        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPersistenceUnitName(persistenceUnitName);
        factory.setPackagesToScan("x.y.z");
        factory.setDataSource(myDataSource());
        factory.setJpaProperties(jpaProperties);
        factory.afterPropertiesSet();
        return factory.getObject();
    }

}

测试或多或少像

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { MyApplication.class, DatabaseConfig.class})
@WebIntegrationTest({ "server.port=12345", "management.port=12345", "security.user.name=testuser","security.user.password=testpassword" })
@DirtiesContext
@ActiveProfiles("test")
public class MyIntegrationTest {

    @Autowired
    private ServerProperties serverProperties;

    private String contextPath;

    private String basePath;

    @Autowired
    private MyRepository myRepository;

    //
}

此代码没有明显变化。有人可以就如何解决这个问题给出一些指示吗?谢谢!

【问题讨论】:

  • 你升级了一些依赖吗?
  • 不,没有任何依赖变化

标签: java database spring-data-jpa h2


【解决方案1】:

所以这很奇怪,但是在调试过程中,我注意到测试总是挂在第一个“插入”语句上,所以我开始使用它,当我将插入语句分解为时,我发现了一些奇怪的行为单独的行,而不是测试开始运行良好 :-S ,这基本上解决了我的问题,但当然,我不明白为什么。 :-S

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 2019-01-19
    • 1970-01-01
    相关资源
    最近更新 更多