1 package org.jacorb.test.notification; 2 3 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 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 ; 33 import org.omg.CORBA.IntHolder ; 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 55 56 public class QoSTest extends NotifyServerTestCase 57 { 58 Any fifoOrder; 59 60 Any lifoOrder; 61 62 Any deadlineOrder; 63 64 Any priorityOrder; 65 66 Any anyOrder; 67 68 Any persistent; 69 70 Any bestEffort; 71 72 Any trueAny; 73 74 Any falseAny; 75 76 public void setUpTest() throws Exception 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 107 { 108 IntHolder channelId = new IntHolder (); 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 119 { 120 IntHolder channelId = new IntHolder (); 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 } 140 } 141 142 147 public void testPriorityOrder() throws Exception 148 { 149 150 IntHolder channelId = new IntHolder (); 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 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 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 received = new ArrayList (); 174 175 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 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 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 name, NotifyServerTestSetup setup) 228 { 229 super(name, setup); 230 } 231 232 public static Test suite() throws Exception 233 { 234 return NotifyServerTestCase.suite("Basic QoS Tests", QoSTest.class); 235 } 236 } 237 | Popular Tags |