Help! JBoss 3.2.3: Stateless Session Beans and isIdentical
csmmoss Feb 17, 2004 11:12 AMAfter switching from JBoss 3.2.1 to 3.2.3, a jUnit test for equivalence between two stateless session beans is now failing. (Code at bottom!)
Previously, under 3.2.1, this assertion test passed:
assertEqual("catalog same", catalog, newCatalog); // TRUE
as do these:
assertTrue("catalog same", newCatalog.equals(catalog)); // TRUE assertTrue("catalog same", newCatalog.isIdentical(catalog)); // TRUE
But under 3.2.3 (& 3.2.2) none of the following evaluate to true (...unless we change the session beans to stateful):
assertEqual("catalog same", catalog, newCatalog); assertTrue("catalog same", newCatalog.equals(catalog)); assertTrue("catalog same", newCatalog.isIdentical(catalog));
After brushing up on EJB equivalence rules, I can understand why 'equals()' fails (although, I'm now uncertain why it works under 3.2.1) , but as far as I can tell, these two stateless beans should be Identical.
Code snippits:
The Action Class
public class EventListAction extends ProtectedAction { LocalEventCatalog eventCatalog; /** Initializes the servlet. */ public LocalEventCatalog getCatalog() { if ( eventCatalog == null ) { try { Context ctx = new InitialContext(); LocalEventCatalogHome home = (LocalEventCatalogHome)ctx.lookup("java:comp/env/EventCatalog"); eventCatalog = home.create(); } catch ( NamingException ne ) { throw new ServletException( "naming exception looking up LocalEventCatalogHome", ne ); } catch ( CreateException ce ) { throw new ServletException( "create exception creating LocalEventCatalog", ce ); } } return eventCatalog; } ...
The Test Class
public class TestEventListAction extends ServletTestCase { ... public void testGetCatalog() { EventListAction action = new EventListAction(); LocalEventCatalog catalog = action.getCatalog(); assertNotNull( "catalog not null", catalog ); LocalEventCatalog newCat = action.getCatalog(); assertNotNull( "new cat not null", newCat ); assertEquals( "catalog same", catalog, newCat ); // FAILS! assertTrue( "catalog same", newCat.equals(catalog)); // FAILS! assertEquals( "catalog same", newCat.isIdentical(catalog)); // FAILS! } ...
We've alse tried (for testing purposes) pre-creating the Bean in the Action, along with a simplified getCatalog() method to return it:
public LocalEventCatalog getCatalog() { return this.eventCatalog; }
and then changing the Test Class to make successive calls to the Action:
LocalEventCatalog catalog = action.getCatalog(); LocalEventCatalog newCat = action.getCatalog();
But even this evaluates to FALSE equality in all three cases.
Only when we change the Bean to "stateful" do they all evaluate to TRUE, under JBoss 3.2.2+ And this appears to be at direct odds with the EJB spec, for the case of stateless beans. Are we missing something here?
-Logan