KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > SequenceEventChannelTest


1 package org.jacorb.test.notification;
2
3 import junit.framework.Test;
4
5 import org.jacorb.test.notification.common.NotifyServerTestCase;
6 import org.jacorb.test.notification.common.NotifyServerTestSetup;
7 import org.omg.CORBA.Any JavaDoc;
8 import org.omg.CORBA.IntHolder JavaDoc;
9 import org.omg.CosNotification.MaximumBatchSize;
10 import org.omg.CosNotification.Property;
11 import org.omg.CosNotification.StructuredEvent;
12 import org.omg.CosNotifyChannelAdmin.EventChannel;
13
14 /**
15  * @author Alphonse Bendt
16  */

17
18 public class SequenceEventChannelTest extends NotifyServerTestCase {
19
20     EventChannel channel_;
21     StructuredEvent[] testEvent_;
22     private NotificationTestUtils testUtils_;
23
24     public SequenceEventChannelTest(String JavaDoc name, NotifyServerTestSetup setup) {
25         super(name, setup);
26     }
27
28
29     public void setUpTest() throws Exception JavaDoc {
30        channel_ = getDefaultChannel();
31
32         testUtils_ = new NotificationTestUtils(getClientORB());
33         testEvent_ = new StructuredEvent[] {testUtils_.getStructuredEvent()};
34     }
35
36
37     public void testSetMaximumBatchSize() throws Exception JavaDoc {
38         StructuredEvent[] _events = new StructuredEvent[] {
39                 testUtils_.getStructuredEvent(),
40                 testUtils_.getStructuredEvent()
41         };
42
43         Any JavaDoc _value = getClientORB().create_any();
44
45         _value.insert_long(2);
46
47         channel_.set_qos(new Property[] {new Property( MaximumBatchSize.value, _value )});
48
49         SequencePushSender _pushSender = new SequencePushSender(getClientORB(), _events);
50
51         SequencePushReceiver _pushReceiver = new SequencePushReceiver(getClientORB());
52
53         _pushSender.connect(channel_, false);
54         _pushReceiver.connect(channel_, false);
55
56         _pushReceiver.start();
57         _pushSender.start();
58
59         _pushSender.join();
60         _pushReceiver.join();
61     }
62
63
64     public void testDestroyChannelDisconnectsClients() throws Exception JavaDoc {
65         Property[] _p = new Property[0];
66         IntHolder JavaDoc _channelId = new IntHolder JavaDoc();
67
68         EventChannel _channel = getEventChannelFactory().create_channel(_p, _p, _channelId);
69
70         SequencePushSender _pushSender = new SequencePushSender(getClientORB(), testEvent_);
71         SequencePullSender _pullSender = new SequencePullSender(getClientORB(), testEvent_);
72         SequencePushReceiver _pushReceiver = new SequencePushReceiver(getClientORB());
73         SequencePullReceiver _pullReceiver = new SequencePullReceiver(getClientORB());
74
75         _pushSender.connect(_channel,false);
76         _pullSender.connect(_channel,false);
77         _pushReceiver.connect(_channel,false);
78         _pullReceiver.connect(_channel,false);
79
80         assertTrue(_pushSender.isConnected());
81         assertTrue(_pullSender.isConnected());
82         assertTrue(_pushReceiver.isConnected());
83         assertTrue(_pullReceiver.isConnected());
84
85         _channel.destroy();
86
87         try {
88             Thread.sleep(1000);
89         } catch (InterruptedException JavaDoc ie) {
90             // ignored
91
}
92
93         assertTrue(!_pushSender.isConnected());
94         assertTrue(!_pullSender.isConnected());
95         assertTrue(!_pushReceiver.isConnected());
96         assertTrue(!_pullReceiver.isConnected());
97     }
98
99
100     public void testSendPushPush() throws Exception JavaDoc {
101         SequencePushSender _sender = new SequencePushSender(getClientORB(), testEvent_);
102         SequencePushReceiver _receiver = new SequencePushReceiver(getClientORB());
103
104         _sender.connect(channel_,false);
105         _receiver.connect(channel_,false);
106
107         _receiver.start();
108         _sender.start();
109
110         _sender.join();
111         _receiver.join();
112
113         assertTrue("Error while sending", !_sender.error_);
114         assertTrue("Should have received something", _receiver.received_);
115     }
116
117
118     public void testSendPushPull() throws Exception JavaDoc {
119         SequencePushSender _sender = new SequencePushSender(getClientORB(), testEvent_);
120         SequencePullReceiver _receiver = new SequencePullReceiver(getClientORB());
121
122         _sender.connect(channel_,false);
123         _receiver.connect(channel_,false);
124
125         _receiver.start();
126         _sender.start();
127
128         _sender.join();
129         _receiver.join();
130
131         assertTrue("Error while sending", _sender.isEventHandled());
132         assertTrue("Should have received something", _receiver.isEventHandled());
133     }
134
135
136     public void testSendPullPush() throws Exception JavaDoc {
137         SequencePullSender _sender = new SequencePullSender(getClientORB(), testEvent_);
138         SequencePushReceiver _receiver = new SequencePushReceiver(getClientORB());
139
140         _receiver.connect(channel_,false);
141         _sender.connect(channel_,false);
142
143         _receiver.start();
144         _sender.start();
145
146         _sender.join();
147         _receiver.join();
148
149         assertTrue("Error while sending", !_sender.isError());
150         assertTrue("Should have received something", _receiver.received_);
151     }
152
153
154     public void testSendPullPull() throws Exception JavaDoc {
155         SequencePullSender _sender = new SequencePullSender(getClientORB(), testEvent_);
156         SequencePullReceiver _receiver = new SequencePullReceiver(getClientORB());
157             _sender.connect(channel_,false);
158
159         _receiver.connect(channel_,false);
160
161         _receiver.start();
162         _sender.start();
163
164         _sender.join();
165         _receiver.join();
166
167         boolean _senderError = ((TestClientOperations)_sender).isError();
168         assertTrue("Error while sending", !_senderError);
169         assertTrue("Should have received something", _receiver.isEventHandled());
170     }
171
172
173     public static Test suite() throws Exception JavaDoc {
174         return NotifyServerTestCase.suite("Tests for Sequenced Event Channel",
175                                           SequenceEventChannelTest.class);
176     }
177 }
178
179
Popular Tags