Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004502 [Resin] minor always 04-13-11 13:07 04-26-11 16:54
Reporter reza View Status public  
Assigned To ferg
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 4.0.18 Product Version 4.0.17
  Product Build
Summary 0004502: Loading JPA fails in JUnit due to data source JNDI registry ordring issues
Description Loading JPA is failing in JUnit because the JPA bootstrap happens before the data source is registered in JNDI. For example, the following code will fail to deploy:

================================================================================
<beans>
  <database>
    <jndi-name>jdbc/test</jndi-name>
    <driver>
      <type>com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</type>
      <url>jdbc:mysql://localhost:3306/test</url> [^]
      <user></user>
      <password></password>
    </driver>
  </database>
</beans>
================================================================================

================================================================================
<persistence>
  <persistence-unit name="test" transaction-type="JTA">
    <jta-data-source>jdbc/test</jta-data-source>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables" />
      <property name="eclipselink.logging.level" value="FINEST" />
    </properties>
  </persistence-unit>
</persistence>
================================================================================

================================================================================
package qa;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class TestBean {
  @PersistenceContext
  private EntityManager entityManager;

  public void hit() {
    System.out.println("hit(" + entityManager + ")");
  }
}
================================================================================

================================================================================
package qa;

import javax.inject.Inject;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.caucho.junit.ResinBeanContainerRunner;

@RunWith(ResinBeanContainerRunner.class)
public class JUnitTest {
  @Inject
  private TestBean bean;

  @Test
  public void test() {
    bean.hit();
  }
}
================================================================================

This is definitely a timing issue specific to JUnit/the bean container because the same code works fine in a web application, loaded via a Servlet:

================================================================================
package qa;



import java.io.IOException;



import javax.inject.Inject;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



@WebServlet(name = "TestServlet", urlPatterns = { "/test" })

public class TestServlet extends HttpServlet {

  private static final long serialVersionUID = 1L;



  @Inject

  private TestBean bean;



  @Override

  protected void doGet(HttpServletRequest request,

      HttpServletResponse response) throws ServletException, IOException {

    bean.hit();

  }

}
================================================================================

This is pretty serious since loading JPA is critical to most Java EE integration testing.
Steps To Reproduce
Additional Information
Attached Files

- Relationships

- Notes
(0005207)
ferg
04-26-11 16:54

env/0e81
 

- Issue History
Date Modified Username Field Change
04-13-11 13:07 reza New Issue
04-26-11 16:54 ferg Note Added: 0005207
04-26-11 16:54 ferg Assigned To  => ferg
04-26-11 16:54 ferg Status new => closed
04-26-11 16:54 ferg Resolution open => fixed
04-26-11 16:54 ferg Fixed in Version  => 4.0.18


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker