KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.test.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import junit.framework.Test;
29
30 import org.jacorb.test.notification.common.NotifyServerTestCase;
31 import org.jacorb.test.notification.common.NotifyServerTestSetup;
32 import org.omg.CORBA.Any JavaDoc;
33 import org.omg.CORBA.IntHolder JavaDoc;
34 import org.omg.CosEventComm.Disconnected;
35 import org.omg.CosNotification.AnyOrder;
36 import org.omg.CosNotification.BestEffort;
37 import org.omg.CosNotification.ConnectionReliability;
38 import org.omg.CosNotification.DeadlineOrder;
39 import org.omg.CosNotification.DiscardPolicy;
40 import org.omg.CosNotification.EventReliability;
41 import org.omg.CosNotification.FifoOrder;
42 import org.omg.CosNotification.LifoOrder;
43 import org.omg.CosNotification.OrderPolicy;
44 import org.omg.CosNotification.Persistent;
45 import org.omg.CosNotification.Priority;
46 import org.omg.CosNotification.PriorityOrder;
47 import org.omg.CosNotification.Property;
48 import org.omg.CosNotification.StructuredEvent;
49 import org.omg.CosNotification.UnsupportedQoS;
50 import org.omg.CosNotifyChannelAdmin.EventChannel;
51
52 /**
53  * @author Alphonse Bendt
54  */

55
56 public class QoSTest extends NotifyServerTestCase
57 {
58     Any JavaDoc fifoOrder;
59
60     Any JavaDoc lifoOrder;
61
62     Any JavaDoc deadlineOrder;
63
64     Any JavaDoc priorityOrder;
65
66     Any JavaDoc anyOrder;
67
68     Any JavaDoc persistent;
69
70     Any JavaDoc bestEffort;
71
72     Any JavaDoc trueAny;
73
74     Any JavaDoc falseAny;
75
76     public void setUpTest() throws Exception JavaDoc
77     {
78         trueAny = getClientORB().create_any();
79         trueAny.insert_boolean(true);
80
81         falseAny = getClientORB().create_any();
82         falseAny.insert_boolean(false);
83
84         fifoOrder = getClientORB().create_any();
85         fifoOrder.insert_short(FifoOrder.value);
86
87         lifoOrder = getClientORB().create_any();
88         lifoOrder.insert_short(LifoOrder.value);
89
90         deadlineOrder = getClientORB().create_any();
91         deadlineOrder.insert_short(DeadlineOrder.value);
92
93         priorityOrder = getClientORB().create_any();
94         priorityOrder.insert_short(PriorityOrder.value);
95
96         anyOrder = getClientORB().create_any();
97         anyOrder.insert_short(AnyOrder.value);
98
99         bestEffort = getClientORB().create_any();
100         bestEffort.insert_short(BestEffort.value);
101
102         persistent = getClientORB().create_any();
103         persistent.insert_short(Persistent.value);
104     }
105
106     public void testCreate_QueueSettings() throws Exception JavaDoc
107     {
108         IntHolder JavaDoc channelId = new IntHolder JavaDoc();
109
110         Property[] qosProps;
111
112         qosProps = new Property[] { new Property(DiscardPolicy.value, priorityOrder),
113                 new Property(OrderPolicy.value, priorityOrder) };
114
115         getEventChannelFactory().create_channel(qosProps, new Property[0], channelId);
116     }
117
118     public void testCreate_Reliability() throws Exception JavaDoc
119     {
120         IntHolder JavaDoc channelId = new IntHolder JavaDoc();
121
122         Property[] qosProps;
123
124         qosProps = new Property[] { new Property(ConnectionReliability.value, bestEffort),
125                 new Property(EventReliability.value, bestEffort) };
126
127         getEventChannelFactory().create_channel(qosProps, new Property[0], channelId);
128
129         qosProps = new Property[] { new Property(ConnectionReliability.value, persistent),
130                 new Property(EventReliability.value, persistent) };
131
132         try
133         {
134             getEventChannelFactory().create_channel(qosProps, new Property[0], channelId);
135             fail();
136         } catch (UnsupportedQoS e)
137         {
138             // expected
139
}
140     }
141
142     /**
143      * test if events are reorderd respecting their priority. a supplier pushes some events with
144      * ascending priority into a channel that was setup with OrderPolicy=PriorityOrder. A Consumer
145      * receives and checks if the Events are delivered in descending Priority order.
146      */

147     public void testPriorityOrder() throws Exception JavaDoc
148     {
149
150         // create and setup channel
151
IntHolder JavaDoc channelId = new IntHolder JavaDoc();
152
153         Property[] qosProps;
154
155         qosProps = new Property[] { new Property(OrderPolicy.value, priorityOrder) };
156
157         EventChannel channel = getEventChannelFactory().create_channel(qosProps, new Property[0], channelId);
158
159         // testdata
160
StructuredEvent[] events = new StructuredEvent[10];
161         for (int x = 0; x < events.length; ++x)
162         {
163             events[x] = new NotificationTestUtils(getClientORB()).getStructuredEvent();
164
165             Any JavaDoc priority = getClientORB().create_any();
166             priority.insert_short((short) x);
167
168             events[x].header.variable_header = new Property[] { new Property(Priority.value,
169                     priority) };
170
171         }
172
173         final List JavaDoc received = new ArrayList JavaDoc();
174
175         // setup clients
176
StructuredPushReceiver receiver = new StructuredPushReceiver(this.getClientORB(), events.length)
177         {
178             public void push_structured_event(StructuredEvent event) throws Disconnected
179             {
180                 super.push_structured_event(event);
181                 
182                 received.add(event);
183             }
184         };
185
186         receiver.connect(channel, false);
187
188         receiver.pushSupplier_.suspend_connection();
189
190         StructuredPushSender sender = new StructuredPushSender(this.getClientORB());
191
192         sender.setStructuredEvent(events);
193         sender.setInterval(100);
194
195         sender.connect(channel, false);
196
197         // push events
198
sender.run();
199
200         assertFalse(receiver.isEventHandled());
201
202         receiver.pushSupplier_.resume_connection();
203
204         receiver.setTimeOut(events.length * 1000);
205
206         receiver.run();
207
208         assertTrue(receiver.isEventHandled());
209
210         while (!received.isEmpty())
211         {
212             StructuredEvent event = (StructuredEvent) received.remove(0);
213
214             Iterator JavaDoc i = received.iterator();
215             while (i.hasNext())
216             {
217                 short p1 = event.header.variable_header[0].value.extract_short();
218
219                 short p2 = ((StructuredEvent) i.next()).header.variable_header[0].value
220                         .extract_short();
221
222                 assertTrue(p1 + " > " + p2, p1 > p2);
223             }
224         }
225     }
226
227     public QoSTest(String JavaDoc name, NotifyServerTestSetup setup)
228     {
229         super(name, setup);
230     }
231
232     public static Test suite() throws Exception JavaDoc
233     {
234         return NotifyServerTestCase.suite("Basic QoS Tests", QoSTest.class);
235     }
236 }
237
Popular Tags