Java Reference
In-Depth Information
veloper what to expect from the bean if behavior isn't obvious from the bean's API and
documentation.
The @Asynchronous annotation placed on the placeOrder method makes the
method asynchronously invokable. This means that the bean will return control back to the
client as soon as the innovation happens. The method is then executed as a lightweight
background process. This is an important piece of functionality in this case, because the
billing process can potentially take a long time. Instead of making the user wait for the
billing process to finish, the @Asynchronous annotation means that the user gets an im-
mediate order placement confirmation while the final step of the ordering process can fin-
ish in the background.
It's also important to note the @Remove annotation placed on the placeOrder meth-
od. Although this annotation is optional, it's critical from a server performance standpoint.
The @Remove annotation marks the end of the workflow modeled by a stateful bean. In
this case, you're telling the container that there's no longer a need to maintain the bean's
session with the client after the placeOrder method is invoked. If you didn't tell the
container what method invocation marked the end of the workflow, the container could
wait for a long time until it could safely time out the session. Because stateful beans are
guaranteed to be dedicated to a client for the duration of a session, this could mean a lot of
orphaned state data consuming precious server resources for long time periods!
2.2.3. Unit testing EJB 3
The ability to use EJB 3 in a Java SE environment is one of the most exciting developments
in EJB 3.1. As we discussed in chapter 1 , this is done through EJB 3 containers that can be
embedded into any Java runtime. Although you could do this using nonstandard embedded
containers like OpenEJB since Java EE 5, EJB 3.1 makes it required for all implementa-
tions.
Embedded containers are most useful in unit testing EJB 3 components with frameworks
like JUnit or TestNG. Allowing for robust EJB 3 unit testing is the primary focus of projects
like Arquillian. The following listing shows how the OrderProcessor stateful session
bean can be easily tested inside a JUnit test. The unit test mimics the workflow that would
be implemented by the presentation tier using a test item and bidder.
Search WWH ::




Custom Search