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");