KickJava   Java API By Example, From Geeks To Geeks.

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


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.Property;
10 import org.omg.CosNotifyChannelAdmin.EventChannel;
11
12 /**
13  * Unit Test for class EventChannel. Test Backward compability. Access Notification Channel via the
14  * CosEvent Interfaces.
15  *
16  * @author Alphonse Bendt
17  */

18
19 public class CosEventChannelTest extends NotifyServerTestCase
20 {
21     EventChannel channel_;
22
23     Any JavaDoc testData_;
24
25     public void setUpTest() throws Exception JavaDoc
26     {
27         channel_ = getDefaultChannel();
28
29         testData_ = new NotificationTestUtils(getClientORB()).getTestPersonAny();
30     }
31
32     public void testPushPush() throws Exception JavaDoc
33     {
34         CosEventPushReceiver _receiver = new CosEventPushReceiver(getClientORB());
35
36         _receiver.connect(channel_, false);
37
38         CosEventPushSender _sender = new CosEventPushSender(getClientORB(), testData_);
39         _sender.connect(channel_, false);
40
41         Thread JavaDoc _r = new Thread JavaDoc(_receiver);
42         _r.start();
43
44         Thread JavaDoc _s = new Thread JavaDoc(_sender);
45         _s.start();
46         _s.join();
47         assertTrue(_sender.isEventHandled());
48         _r.join();
49         assertTrue(_receiver.isEventHandled());
50     }
51
52     public void testPushPull() throws Exception JavaDoc
53     {
54         CosEventPullReceiver _receiver = new CosEventPullReceiver(getClientORB());
55         _receiver.connect(channel_, false);
56         Thread JavaDoc _r = new Thread JavaDoc(_receiver);
57
58         CosEventPushSender _sender = new CosEventPushSender(getClientORB(), testData_);
59         _sender.connect(channel_, false);
60         Thread JavaDoc _s = new Thread JavaDoc(_sender);
61
62         _r.start();
63
64         _s.start();
65         _s.join();
66         assertTrue(_sender.isEventHandled());
67
68         _r.join();
69
70         assertTrue(_receiver.isEventHandled());
71     }
72
73     public void testPullPush() throws Exception JavaDoc
74     {
75         CosEventPushReceiver _receiver = new CosEventPushReceiver(getClientORB());
76         _receiver.connect(channel_, false);
77
78         CosEventPullSender _sender = new CosEventPullSender(getClientORB(), testData_);
79         _sender.connect(channel_, false);
80
81         Thread JavaDoc _r = new Thread JavaDoc(_receiver);
82         _r.start();
83         Thread JavaDoc _s = new Thread JavaDoc(_sender);
84         _s.start();
85
86         _s.join();
87         assertTrue(_sender.isEventHandled());
88
89         _r.join();
90         assertTrue(_receiver.isEventHandled());
91     }
92
93     public void testPullPull() throws Exception JavaDoc
94     {
95         CosEventPullReceiver _receiver = new CosEventPullReceiver(getClientORB());
96         _receiver.connect(channel_, false);
97         Thread JavaDoc _r = new Thread JavaDoc(_receiver);
98
99         CosEventPullSender _sender = new CosEventPullSender(getClientORB(), testData_);
100         _sender.connect(channel_, false);
101
102         _r.start();
103
104         _r.join();
105
106         assertTrue(_receiver.isEventHandled());
107     }
108
109     public void testDestroyChannelDisconnectsClients() throws Exception JavaDoc
110     {
111         EventChannel _channel =
112             getEventChannelFactory().create_channel(new Property[0],
113                     new Property[0],
114                     new IntHolder JavaDoc());
115
116         TestClientOperations[] _testClients = new TestClientOperations[] {
117                 new CosEventPullSender(getClientORB(), testData_),
118                 new CosEventPushSender(getClientORB(), testData_),
119                 new CosEventPushReceiver(getClientORB()),
120                 new CosEventPullReceiver(getClientORB()) };
121
122         for (int x = 0; x < _testClients.length; ++x)
123         {
124             _testClients[x].connect(_channel, false);
125             assertTrue(_testClients[x].isConnected());
126         }
127
128         _channel.destroy();
129
130         Thread.sleep(1000);
131
132         for (int x = 0; x < _testClients.length; ++x)
133         {
134             assertTrue("Idx: " + x + " still connected", !_testClients[x].isConnected());
135         }
136     }
137
138     public CosEventChannelTest(String JavaDoc name, NotifyServerTestSetup setup)
139     {
140         super(name, setup);
141     }
142
143     public static Test suite() throws Exception JavaDoc
144     {
145         return NotifyServerTestCase.suite("Basic CosEvent EventChannel Tests",
146                 CosEventChannelTest.class);
147     }
148 }
149
Popular Tags