1 package org.jacorb.test.notification.perf; 2 3 23 24 import junit.framework.Test; 25 26 import org.apache.avalon.framework.logger.Logger; 27 import org.jacorb.notification.util.LogUtil; 28 import org.jacorb.test.notification.NotificationTestCase; 29 import org.jacorb.test.notification.NotificationTestCaseSetup; 30 import org.jacorb.test.notification.StructuredPushReceiver; 31 import org.jacorb.test.notification.StructuredPushSender; 32 import org.jacorb.test.notification.TestUtils; 33 import org.omg.CORBA.Any ; 34 import org.omg.CORBA.IntHolder ; 35 import org.omg.CosEventComm.Disconnected; 36 import org.omg.CosNotification.EventType; 37 import org.omg.CosNotification.Property; 38 import org.omg.CosNotification.StructuredEvent; 39 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin; 40 import org.omg.CosNotifyChannelAdmin.EventChannel; 41 import org.omg.CosNotifyChannelAdmin.EventChannelFactory; 42 import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper; 43 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 44 import org.omg.CosNotifyFilter.ConstraintExp; 45 import org.omg.CosNotifyFilter.Filter; 46 import org.omg.CosNotifyFilter.FilterFactory; 47 import org.omg.CosNotifyFilter.InvalidConstraint; 48 import org.omg.CosNotifyFilter.InvalidGrammar; 49 50 import EDU.oswego.cs.dl.util.concurrent.Latch; 51 import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean; 52 53 56 57 public class PerformanceTest extends NotificationTestCase 58 { 59 EventChannelFactory factory_; 60 61 FilterFactory filterFactory_; 62 63 Any testPerson_; 64 65 EventChannel channel_; 66 67 IntHolder channelId_; 68 69 SupplierAdmin supplierAdmin_; 70 71 ConsumerAdmin consumerAdmin_; 72 73 Filter trueFilter_; 74 75 TestUtils testUtils_; 76 77 Logger logger_ = LogUtil.getLogger(getClass().getName()); 78 79 static long sInterval = 250L; 80 81 static long sTimeout = 2 * sInterval; 82 83 89 public PerformanceTest(String name, NotificationTestCaseSetup setup) 90 { 91 super(name, setup); 92 } 93 94 97 public void setUpTest() throws Exception 98 { 99 testUtils_ = new TestUtils(); 100 101 factory_ = EventChannelFactoryHelper.narrow(getORB().resolve_initial_references( 102 "NotificationService")); 103 104 testPerson_ = testUtils_.getTestPersonAny(); 106 107 channelId_ = new IntHolder (); 109 110 channel_ = factory_.create_channel(new Property[0], new Property[0], channelId_); 111 112 filterFactory_ = channel_.default_filter_factory(); 113 114 supplierAdmin_ = channel_.default_supplier_admin(); 115 116 consumerAdmin_ = channel_.default_consumer_admin(); 117 118 trueFilter_ = filterFactory_.create_filter("EXTENDED_TCL"); 119 ConstraintExp[] _constraintExp = new ConstraintExp[1]; 120 EventType[] _eventType = new EventType[1]; 121 _eventType[0] = new EventType("*", "*"); 122 String _expression = "TRUE"; 123 _constraintExp[0] = new ConstraintExp(_eventType, _expression); 124 trueFilter_.add_constraints(_constraintExp); 125 } 126 127 public void tearDownTest() throws Exception 128 { 129 trueFilter_.destroy(); 130 131 try 132 { 133 channel_.destroy(); 134 } catch (Exception e) 135 { 136 } 138 } 139 140 public void _testCompareAny() throws Exception 141 { 142 Any _a1 = getORB().create_any(), _a2 = getORB().create_any(); 143 144 _a1.insert_long(10); 145 _a2.insert_long(10); 146 147 assertEquals(_a1, _a2); 148 } 149 150 public void _testMeasureFilterLatency() throws Exception 151 { 152 Any _any = getORB().create_any(); 153 _any.insert_long(10); 154 155 int _runs = 100; 156 157 measureFilterLatency("$ == 10", _any, _runs); 158 159 _any = testUtils_.getTestPersonAny(); 160 161 measureFilterLatency("$.phone_numbers[0] == '12345678'", _any, _runs); 162 163 measureFilterLatency("exist $.phone_numbers[0] and $.phone_numbers[0] == '12345678'", _any, 164 _runs); 165 166 measureFilterLatency( 167 "exist $.phone_numbers[0] and exist $.phone_numbers[0] and $.phone_numbers[0] == '12345678'", 168 _any, _runs); 169 170 measureFilterLatency( 171 "exist $.phone_numbers[0] and exist $.phone_numbers[0] and exist $.phone_numbers[0] and $.phone_numbers[0] == '12345678'", 172 _any, _runs); 173 174 measureFilterLatency( 175 "exist $.phone_numbers[0] and exist $.phone_numbers[0] and exist $.phone_numbers[0] and exist $.phone_numbers[0] and $.phone_numbers[0] == '12345678'", 176 _any, _runs); 177 178 measureFilterLatency( 179 "exist $.phone_numbers[0] and exist $.phone_numbers[0] and exist $.phone_numbers[0] and exist $.phone_numbers[0] and exist $.phone_numbers[0] and $.phone_numbers[0] == '12345678'", 180 _any, _runs); 181 182 StructuredEvent _event = testUtils_.getStructuredEvent(); 183 184 measureFilterLatency("$event_name == 'ALARM'", _event, _runs); 185 186 measureFilterLatency("$type_name == 'TESTING'", _event, _runs); 187 188 measureFilterLatency("$domain_name == 'TESTING'", _event, _runs); 189 } 190 191 private void measureFilterLatency(String filterString, StructuredEvent event, int runs) 192 throws Exception 193 { 194 Filter _filter = createFilter(filterString); 195 196 long _start = System.currentTimeMillis(); 197 198 for (int x = 0; x < runs; ++x) 199 { 200 boolean _r = _filter.match_structured(event); 201 assertTrue(_r); 202 } 203 204 long _total = System.currentTimeMillis() - _start; 205 206 System.out.println(runs + " Filterings of '" + filterString + "' took " + _total 207 + " in average: " + (_total / runs)); 208 } 209 210 private Filter createFilter(String filterString) throws InvalidGrammar, InvalidConstraint 211 { 212 Filter _filter = filterFactory_.create_filter("EXTENDED_TCL"); 213 ConstraintExp[] _constraintExp = new ConstraintExp[1]; 214 EventType[] _eventType = new EventType[1]; 215 _eventType[0] = new EventType("*", "*"); 216 String _expression = filterString; 217 _constraintExp[0] = new ConstraintExp(_eventType, _expression); 218 _filter.add_constraints(_constraintExp); 219 220 return _filter; 221 } 222 223 private void measureFilterLatency(String filterString, Any event, int runs) throws Exception 224 { 225 Filter _filter = createFilter(filterString); 226 227 long _start = System.currentTimeMillis(); 228 229 for (int x = 0; x < runs; ++x) 230 { 231 boolean _r = _filter.match(event); 232 assertTrue(_r); 233 } 234 235 long _total = System.currentTimeMillis() - _start; 236 237 System.out.println(runs + " Filterings of '" + filterString + "' took " + _total 238 + " in average: " + (_total / runs)); 239 } 240 241 public void testLoad() throws Exception 242 { 243 final SynchronizedBoolean active = new SynchronizedBoolean(true); 244 245 final StructuredPushReceiver receiver = new StructuredPushReceiver(getClientORB()); 246 247 receiver.connect(channel_, false); 248 249 final StructuredPushSender sender = new StructuredPushSender(getClientORB()); 250 251 sender.connect(channel_, false); 252 253 while (active.get()) 254 { 255 final StructuredEvent[] data = new StructuredEvent[1000]; 256 257 for (int x = 0; x < data.length; ++x) 258 { 259 data[x] = testUtils_.getStructuredEvent(); 260 } 261 262 final Latch latch = new Latch(); 263 new Thread () 264 { 265 public void run() 266 { 267 System.out.println("Begin to send"); 268 269 try 270 { 271 sender.pushEvents(data); 272 } catch (Disconnected e) 273 { 274 active.set(false); 275 e.printStackTrace(); 277 } 278 279 System.out.println("Sent " + data.length); 280 281 latch.release(); 282 } 283 }.start(); 284 285 latch.acquire(); 286 287 System.out.println(receiver); 288 289 Thread.sleep(60000); 290 291 System.out.println(receiver); 292 } 293 294 sender.shutdown(); 295 296 receiver.shutdown(); 297 } 298 299 public static Test suite() throws Exception 300 { 301 return NotificationTestCase.suite(PerformanceTest.class, "testLoad"); 302 } 303 } 304 | Popular Tags |