Transaction vs. Extended Persistence Contexts Problem
sisepago Aug 8, 2007 10:39 AMHello Guys,
maybe somebody has already hit so a problem, I am trying to test Transaction vs. Extended persistence context example from the O'Reilly EJB 3.0 Workbook (exercise 5.1) in an unit test using Embedded JBoss and I got anytime this error when I ran the test unit.
here is the error trace:
Testsuite: com.titan.travelagent.TravelAgentBeanTestCase
Tests run: 2, Failures: 0, Errors: 1, Time elapsed: 6.241 sec
------------- Standard Output ---------------
WARN 08-08 09:39:04,057 (UnifiedLoaderRepository3.java:addClassLoader:675) -Tried to add non-URLClassLoader. Ignored
WARN 08-08 09:39:05,004 (TxControl.java::266) -[com.arjuna.ats.arjuna.coordinator.TxControl_1] - Name of XA node not defined. Using -3f574dec:c73a:46b97318:0
WARN 08-08 09:39:07,257 (JDBCPersistenceManager.java:start:143) -
JBoss Messaging Warning: DataSource connection transaction isolation should be READ_COMMITTED, but it is currently NONE.
Using an isolation level less strict than READ_COMMITTED may lead to data consistency problems.
Using an isolation level more strict than READ_COMMITTED may lead to deadlock.
WARN 08-08 09:39:08,734 (JBossTimerServiceFactory.java:restoreTimerService:112) -TIMER SERVICE IS NOT INSTALLED
----------------------------------------------------------
no cabin should be null :null
Successfully created and found cabin from @Remote interface
Master Suite
1
1
3
Update detached cabin instance with new bed count of 4
Finding cabin to see it has been updated with merge() on the embedded jboss
new bed count is: 4
----------------------------------------------------------
----------------------------------------------------------
WARN 08-08 09:39:08,919 (MessageCounterManager.java:stop:89) -org.jboss.jms.server.messagecounter.MessageCounterManager@dd79e9 isn't started
------------- ---------------- ---------------
Testcase: testCreateFindAndUpdateCabin took 0.166 sec
Testcase: testTransactionScopeAndExtendedPersistenceContext took 0.001 sec
Caused an ERROR
TransactionPersistenceContextBean not bound
javax.naming.NameNotFoundException: TransactionPersistenceContextBean not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:628)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.titan.travelagent.TravelAgentBeanTestCase.testTransactionScopeAndExtendedPersistenceContext(TravelAgentBeanTestCase.java:140)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
at junit.extensions.TestSetup.run(TestSetup.java:23)
here is the test unit :
package com.titan.travelagent;
import javax.naming.InitialContext;
import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.embedded.Bootstrap;
import org.jboss.virtual.plugins.context.vfs.AssembledContextFactory;
import org.jboss.virtual.plugins.context.vfs.AssembledDirectory;
import com.titan.domain.Cabin;
public class TravelAgentBeanTestCase extends TestCase {
private static AssembledDirectory jar;
private static boolean globalSetup = false;
public TravelAgentBeanTestCase() {
super("TravelAgentBeanTestCase");
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(TravelAgentBeanTestCase.class);
globalSetup = true;
return new TestSetup(suite) {
@Override
protected void setUp() throws Exception {
super.setUp();
if (!Bootstrap.getInstance().isStarted()) {
Bootstrap.getInstance().bootstrap();
}
deploy();
}
@Override
protected void tearDown() throws Exception {
undeploy();
if (System.getProperty("shutdown.embedded.jboss") != null)
Bootstrap.getInstance().shutdown();
super.tearDown();
}
};
}
@Override
protected void setUp() throws Exception {
if (globalSetup)
return;
Bootstrap.getInstance().bootstrap();
deploy();
}
@Override
protected void tearDown() throws Exception {
if (globalSetup)
return;
undeploy();
}
private static void deploy() {
jar = AssembledContextFactory.getInstance().create("titan.jar");
jar.addClass(Cabin.class);
jar.addClass(TravelAgentBean.class);
jar.addClass(TravelAgentRemote.class);
jar.mkdir("META-INF").addResource("META-INF/persistence.xml", "persistence.xml");
try {
Bootstrap.getInstance().deploy(jar);
} catch (DeploymentException e) {
throw new RuntimeException("Unable to deploy", e);
}
}
private static void undeploy() {
try {
Bootstrap.getInstance().undeploy(jar);
AssembledContextFactory.getInstance().remove(jar);
} catch (DeploymentException e) {
throw new RuntimeException("Unable to undeploy", e);
}
}
/**
* persist()/find()/merge()
*
* @throws Exception
*/
public void testCreateFindAndUpdateCabin() throws Exception {
InitialContext ctx = new javax.naming.InitialContext();
TravelAgentRemote remote = (TravelAgentRemote) ctx
.lookup("TravelAgentBean/remote");
System.out
.println("----------------------------------------------------------");
Cabin noCabin = remote.findCabin(1);
System.out.println("no cabin should be null :" + noCabin);
Cabin cabin_1 = new Cabin();
cabin_1.setId(1);
cabin_1.setName("Master Suite");
cabin_1.setDeckLevel(1);
cabin_1.setShipId(1);
cabin_1.setBedCount(3);
remote.createCabin(cabin_1);
Cabin cabin_2 = remote.findCabin(1);
System.out
.println(" Successfully created and found cabin from @Remote interface");
System.out.println(cabin_2.getName());
System.out.println(cabin_2.getDeckLevel());
System.out.println(cabin_2.getShipId());
System.out.println(cabin_2.getBedCount());
System.out.println("Update detached cabin instance with new bed count of 4");
cabin_2.setBedCount(4);
remote.updateCabin(cabin_2);
System.out.println("Finding cabin to see it has been updated with merge() on the embedded jboss");
Cabin cabin_3 = remote.findCabin(1);
System.out.println("new bed count is: " + cabin_3.getBedCount());
System.out
.println("----------------------------------------------------------");
}
//Transaction vs. Extended Persistence Context
public void testTransactionScopeAndExtendedPersistenceContext() throws Exception{
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("TravelAgentBean/remote");
TravelAgentRemote dao = (TravelAgentRemote)ref;
System.out
.println("----------------------------------------------------------");
ref = ctx.lookup("TransactionPersistenceContextBean/remote");
TransactionPersistenceContextRemote txBean = (TransactionPersistenceContextRemote)ref;
Cabin fetchedCabin = dao.findCabin(1);
int oldBedCount = fetchedCabin.getBedCount();
System.out.println("set up transaction persistence context stateful bean");
txBean.setCabin(1);
txBean.updateBedCount(4);
fetchedCabin = dao.findCabin(1);
System.out.println(oldBedCount + " : " + fetchedCabin.getBedCount());
ref = ctx.lookup("ExtendedPersistenceContextBean/remote");
ExtendedPersistenceContextRemote extBean = (ExtendedPersistenceContextRemote)ref;
extBean.setCabin(1);
extBean.updateBedCount(5);
fetchedCabin = dao.findCabin(1);
System.out.println(oldBedCount + " : " + fetchedCabin.getBedCount());
txBean.remove();
extBean.remove();
}
}I will be happy with some infos.
thanks for advance.