I am using OpenEjb local server (3.1.4) in my integration tests (@LocalClient annotated test classes).
@LocalClient
public class BoxDaoTest{
@EJB
private BoxDao boxDao;
...
}
BoxDao ist a stateful session bean. Ist it possible to trigger passivation of BoxDao in OpenEjb to test it in the integration test?
You can create/configure the Stateful container in the InitialContext
properties you use to boot OpenEJB in the tests case.
These settings will do the trick:
final Properties p = new Properties();
p.put("MyStatefulContainer", "new://Container?type=STATEFUL");
p.put("MyStatefulContainer.Capacity", "0");
p.put("MyStatefulContainer.Frequency", "0");
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
final InitialContext initialContext = new InitialContext(properties);
//lookup your beans from the initialContext
This will cause the @Stateful
bean to essentially never reside in memory, it will be read from disk and written back to disk on each method invocation or lifecycle callback.
The same thing can be done with the EJB 3.1 javax.ejb.embeddable.EJBContainer
API:
final Properties p = new Properties();
p.put("MyStatefulContainer", "new://Container?type=STATEFUL");
p.put("MyStatefulContainer.Capacity", "0");
p.put("MyStatefulContainer.Frequency", "0");
final EJBContainer container = EJBContainer.createEJBContainer(p);
Foo foo = (Foo) container.getContext().lookup("java:global/yourapp/yourbean");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.