1 17 package org.apache.servicemix.jbi.messaging; 18 19 import org.apache.servicemix.jbi.RuntimeJBIException; 20 import org.apache.servicemix.jbi.container.ActivationSpec; 21 import org.apache.servicemix.jbi.container.JBIContainer; 22 import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver; 23 import org.apache.servicemix.tck.AsyncReceiverPojo; 24 import org.apache.servicemix.tck.Receiver; 25 import org.apache.servicemix.tck.ReceiverComponent; 26 import org.apache.servicemix.tck.SenderComponent; 27 import org.springframework.transaction.TransactionStatus; 28 import org.springframework.transaction.support.TransactionCallback; 29 30 import javax.jbi.JBIException; 31 32 35 public abstract class AbstractClusteredTransactionTest extends AbstractTransactionTest { 36 37 protected JBIContainer receiverContainer; 38 39 42 protected void setUp() throws Exception { 43 super.setUp(); 44 receiverContainer = createJbiContainer("receiverContainer"); 45 Thread.sleep(3000); 46 } 47 48 protected void tearDown() throws Exception { 49 receiverContainer.shutDown(); 50 super.tearDown(); 51 } 52 53 protected void runClusteredTest(final boolean syncSend, final boolean syncReceive) throws Exception { 54 final SenderComponent sender = new SenderComponent(); 55 sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE)); 56 final Receiver receiver; 57 if (syncReceive) { 58 receiver = new ReceiverComponent(); 59 } else { 60 receiver = new AsyncReceiverPojo(); 61 } 62 63 senderContainer.activateComponent(new ActivationSpec("sender", sender)); 64 receiverContainer.activateComponent(new ActivationSpec("receiver", receiver)); 65 Thread.sleep(1000); 66 67 tt.execute(new TransactionCallback() { 68 public Object doInTransaction(TransactionStatus status) { 69 try { 70 sender.sendMessages(NUM_MESSAGES, syncSend); 71 } catch (JBIException e) { 72 throw new RuntimeJBIException(e); 73 } 74 return null; 75 } 76 }); 77 receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES); 78 } 79 80 public void testClusteredSyncSendSyncReceive() throws Exception { 81 try { 82 runClusteredTest(true, true); 83 fail("sendSync can not be used on clustered flows with external components"); 84 } catch (Exception e) { 85 } 87 } 88 89 public void testClusteredAsyncSendSyncReceive() throws Exception { 90 runClusteredTest(false, true); 91 } 92 93 public void testClusteredSyncSendAsyncReceive() throws Exception { 94 try { 95 runClusteredTest(true, false); 96 fail("sendSync can not be used on clustered flows with external components"); 97 } catch (Exception e) { 98 } 100 } 101 102 public void testClusteredAsyncSendAsyncReceive() throws Exception { 103 runClusteredTest(false, false); 104 } 105 106 } 107 | Popular Tags |