简体   繁体   English

使用Jetty,HSQL,JNDI和Spring进行集成测试

[英]Integration tests using jetty, hsql, jndi, and spring

I am attempting to create some integration tests for my Spring web app using Jetty accessing a local HSQL database. 我正在尝试使用Jetty访问本地HSQL数据库为Spring Web应用程序创建一些集成测试。 The goal: run the tests using Selenium (or similar), mock/stub out all external systems, and setup a HSQL database to hit instead of our shared Oracle database. 目标:使用Selenium(或类似工具)运行测试,对所有外部系统进行模拟/存根,并设置要命中的HSQL数据库而不是我们的共享Oracle数据库。 The tests are started during a maven build (the integration-test phase). 测试在Maven构建期间开始(集成测试阶段)。 The database is initialized by Spring's "jdbc:initialize-database", and is registered as a JNDI datasource in Jetty. 该数据库由Spring的“ jdbc:initialize-database”初始化,并在Jetty中注册为JNDI数据源。

After days of trying different configuration, I have finally gotten to the point where the database is created, initialized, and I think registered as a Jetty resource, but when the test cases run, it just hangs; 经过数天的尝试不同的配置,我终于到达创建,初始化数据库的地步,我认为已注册为Jetty资源,但是当测试用例运行时,它就挂了; I think because it is waiting for the database to become available. 我认为是因为它正在等待数据库变得可用。

Maven configuration Maven配置

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.3.3</version>
  <executions>
    <execution>
      <id>start</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>start</goal>
      </goals>
    </execution>
    <execution>
      <id>stop</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <container>
      <containerId>jetty7x</containerId>
      <dependencies>
        <dependency>
          <groupId>org.hsqldb</groupId>
          <artifactId>hsqldb</artifactId>
        </dependency>
        <dependency>
          <groupId>c3p0</groupId>
          <artifactId>c3p0</artifactId>
        </dependency>
      </dependencies>
    </container>
    <configuration>
      <home>${project.build.directory}/cargo/configurations/jetty7x</home>
      <properties>
        <cargo.jetty.createContextXml>false</cargo.jetty.createContextXml>
        <cargo.datasource.datasource>
          cargo.datasource.url=jdbc:hsqldb:file:../../../myDB|
          cargo.datasource.driver=org.hsqldb.jdbcDriver|
          cargo.datasource.username=sa|
          cargo.datasource.password=|
          cargo.datasource.type=javax.sql.DataSource|
          cargo.datasource.jndi=jdbc/myDataSource
        </cargo.datasource.datasource>
      </properties>
    </configuration>
    <deployables>
      <deployable>
        <location>target/myApp</location>
        <properties>
          <context>myApp</context>
        </properties>
      </deployable>
    </deployables>
  </configuration>
 </plugin>

Spring configuration 弹簧配置

<bean id="localDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="org.hsqldb.jdbcDriver"/>
    <property name="jdbcUrl" value="jdbc:hsqldb:file:target/myDB"/>
    <property name="user" value="sa"/>
    <property name="password" value=""/>
</bean>

 <jdbc:initialize-database data-source="mydataSource" ignore-failures="DROPS"> 
    <jdbc:script location="classpath:/sql-scripts/schema/create-schema.sql"/> 
    <jdbc:script location="classpath:/sql-scripts/schema/create-tables.sql"/> 
    <jdbc:script location="classpath:/sql-scripts/testdata/data-load.sql"/> 
</jdbc:initialize-database> 

I am probably missing something, I tried to piece together the configuration through advice from many other posts. 我可能丢失了一些东西,我尝试通过许多其他文章的建议来整理配置。 Any help would be appreciated. 任何帮助,将不胜感激。

The recommended method of using HSQLDB for tests, especially complex test setups, is running a Server. 使用HSQLDB进行测试(尤其是复杂的测试设置)的推荐方法是运行服务器。

Initially, you start an HSQLDB server using the shell, independently of your test setup. 最初,您使用外壳启动HSQLDB服务器,而与测试设置无关。 Use the Server property server.silent=false to see immediately the connections and statements on the console. 使用服务器属性server.silent=false可以立即在控制台上查看连接和语句。

After some progress has been made, you can customize the server settings. 取得一些进展后,您可以自定义服务器设置。 See the Guide: 请参阅指南:

http://www.hsqldb.org/doc/2.0/guide/listeners-chapt.html http://www.hsqldb.org/doc/2.0/guide/listeners-chapt.html

And a summary of different options for testing: 以及不同测试选项的摘要:

http://www.hsqldb.org/doc/2.0/guide/deployment-chapt.html#dec_app_dev_testing http://www.hsqldb.org/doc/2.0/guide/deployment-chapt.html#dec_app_dev_testing

You may need to use the MVCC transaction model. 您可能需要使用MVCC交易模型。 This reduces the locks and sometimes avoids the connections hanging as a result of on one waiting for the other to commit. 这减少了锁,有时避免由于一个等待另一个提交而导致连接挂起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在具有JNDI和spring上下文的Jetty容器中运行TestNG集成测试? - Is it possible to run TestNG integration-tests in a Jetty container with JNDI's and spring context? 使用Spring / Jetty(或Tomcat)/ Maven进行REST测试的集成测试 - Configuring Integration Tests using Spring/Jetty (or Tomcat)/Maven for REST tests 如何进行集成测试setUp()操作在嵌入式Jetty容器中运行的内存数据库中的HSQL数据? - How to have integration tests setUp() manipulate HSQL data in an in-memory DB running in embedded Jetty container? 使用HSQL,Hibernate和Spring进行自动增量和测试 - AutoIncrement with HSQL, Hibernate and Spring and Tests 我的Spring集成测试如何根据HSQL数据库中的模型创建自己的模式? - How can my Spring integration tests create their own schema based on the model in a HSQL database? 在集成测试中使用Spring @ActiveProfile - Using Spring @ActiveProfile in integration tests Jetty 7 Spring 3.0.5集成 - Jetty 7 Spring 3.0.5 integration HSQL在Spring引导测试中不起作用 - HSQL doesn't work in Spring boot tests Jetty JNDI配置与Spring查找 - Jetty JNDI configuration vs Spring lookup 使用不同的Spring属性进行集成测试 - Using different Spring properties for integration tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM