KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > messaging > AbstractClusteredTransactionTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
33  * @version $Revision: 426415 $
34  */

35 public abstract class AbstractClusteredTransactionTest extends AbstractTransactionTest {
36
37     protected JBIContainer receiverContainer;
38     
39     /*
40      * @see TestCase#setUp()
41      */

42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         receiverContainer = createJbiContainer("receiverContainer");
45         Thread.sleep(3000);
46     }
47     
48     protected void tearDown() throws Exception JavaDoc {
49         receiverContainer.shutDown();
50         super.tearDown();
51     }
52     
53     protected void runClusteredTest(final boolean syncSend, final boolean syncReceive) throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc {
81         try {
82             runClusteredTest(true, true);
83             fail("sendSync can not be used on clustered flows with external components");
84         } catch (Exception JavaDoc e) {
85             // ok
86
}
87     }
88
89     public void testClusteredAsyncSendSyncReceive() throws Exception JavaDoc {
90         runClusteredTest(false, true);
91     }
92
93     public void testClusteredSyncSendAsyncReceive() throws Exception JavaDoc {
94         try {
95             runClusteredTest(true, false);
96             fail("sendSync can not be used on clustered flows with external components");
97         } catch (Exception JavaDoc e) {
98             // ok
99
}
100     }
101
102     public void testClusteredAsyncSendAsyncReceive() throws Exception JavaDoc {
103         runClusteredTest(false, false);
104     }
105
106 }
107
Popular Tags