Could someone explain me why the following test cannot be successfully performed?
Basically I'm trying to embed the whole process within a global transaction but it seems that JMS queue doesn't like this at all and TextCallback.onText(String text) is never invoked.
I'm very new to JPA-JMS so, please, forgive me if I'm missing some obvious points.
Test code:
Spring context addition:Code:public void testJmsRecieveWithDatabaseUpdate() throws Exception { assertNotNull(textMessageDelegate); assertNotNull(textMessageSender); TransactionTemplate transactionTemplate = (TransactionTemplate) applicationContext .getBean("transactionTemplate"); transactionTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(TransactionStatus status) { int sequence = messageSequenceDAO.readSequence("app1", "keyA"); assertEquals(1, sequence); // set things up to scoop the text out of our MDP and perform // a database opperation. class Handle { Object object; } final Handle handle = new Handle(); textMessageDelegate.setTextCallback(new TextCallback() { public void onText(String text) { synchronized (handle) { if (text.equals("without rollback")) { handle.object = text; messageSequenceDAO.incrementSequence("app1", "keyA"); } } } }); // fire the text message that will be routed to our MDP try { textMessageSender.sendMessage("without rollback"); } catch (Exception e) { // Don't bother e.printStackTrace(); } // in case anything is warming up in our debugger we should // pause to // to allow the MDP code to execute try { Thread.sleep(1000); } catch (InterruptedException e) { // Don't bother e.printStackTrace(); } String fromMdp = null; synchronized (handle) { fromMdp = (String) handle.object; } assertNotNull(fromMdp); assertEquals("without rollback", fromMdp); // check the database update worked sequence = 0; sequence = messageSequenceDAO.readSequence("app1", "keyA"); assertEquals(2, sequence); } }); }
P.S.Code:<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate" scope="prototype"> <property name="transactionManager" ref="jtaTransactionManager" /> </bean>
The code presented above is not meant to be actually useful. It's just that I cannot really figure out what's wrong with it.


Reply With Quote
