1 21 22 package org.jacorb.test.notification.perf; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import junit.framework.Test; 28 import junit.textui.TestRunner; 29 30 import org.jacorb.test.notification.NotificationTestCase; 31 import org.jacorb.test.notification.NotificationTestCaseSetup; 32 import org.jacorb.test.notification.StructuredPushReceiver; 33 import org.jacorb.test.notification.StructuredPushSender; 34 import org.omg.CORBA.Any ; 35 import org.omg.CORBA.IntHolder ; 36 import org.omg.CORBA.ORB ; 37 import org.omg.CosNotification.EventHeader; 38 import org.omg.CosNotification.EventType; 39 import org.omg.CosNotification.FixedEventHeader; 40 import org.omg.CosNotification.Property; 41 import org.omg.CosNotification.StructuredEvent; 42 import org.omg.CosNotifyChannelAdmin.EventChannel; 43 import org.omg.CosNotifyChannelAdmin.EventChannelFactory; 44 import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper; 45 46 50 public class LoadTest extends NotificationTestCase 51 { 52 int count = 0; 53 54 EventChannelFactory factory; 55 56 EventChannel channel; 57 58 IntHolder intHolder; 59 60 boolean active = true; 61 62 public LoadTest(String name, NotificationTestCaseSetup setup) 63 { 64 super(name, setup); 65 } 66 67 public void setUpTest() throws Exception 68 { 69 ORB orb = getORB(); 70 71 factory = EventChannelFactoryHelper.narrow(orb 72 .resolve_initial_references("NotificationService")); 73 74 intHolder = new IntHolder (); 75 76 channel = factory.create_channel(new Property[0], new Property[0], intHolder); 77 } 78 79 public void tearDownTest() 80 { 81 channel.destroy(); 82 } 83 84 public static Test suite() throws Exception 85 { 86 return NotificationTestCase.suite(LoadTest.class); 87 } 88 89 public void testLoad() throws Exception 90 { 91 final List received = new ArrayList (); 92 93 StructuredPushSender sender = new StructuredPushSender(getClientORB()); 94 95 StructuredPushReceiver receiver = new StructuredPushReceiver(getClientORB()); 96 97 System.out.println("connect sender"); 98 sender.connect(channel, true); 99 System.out.println("connect receiver"); 100 receiver.connect(channel, true); 101 102 boolean _active = active; 103 104 int batchSize = 1000; 105 106 while (_active) 107 { 108 for (int x = 0; x < batchSize; ++x) 109 { 110 Any any = getORB().create_any(); 111 any.insert_long(x); 112 113 StructuredEvent event = new StructuredEvent(); 114 event.filterable_data = new Property[] { new Property("number", any) }; 115 event.header = new EventHeader(); 116 event.header.fixed_header = new FixedEventHeader(); 117 event.header.variable_header = new Property[0]; 118 event.header.fixed_header.event_name = "event_name"; 119 event.header.fixed_header.event_type = new EventType("domain_name", "type_name"); 120 event.remainder_of_body = getClientORB().create_any(); 121 122 event.remainder_of_body.insert_longlong(System.currentTimeMillis()); 123 sender.pushConsumer_.push_structured_event(event); 124 125 } 127 128 synchronized (this) 129 { 130 _active = active; 131 } 132 Thread.sleep(4000); 133 134 assertEquals(batchSize, received.size()); 135 136 _active = false; 137 } 138 139 Thread.sleep(60000); 140 } 141 142 public static void main(String [] args) throws Exception 143 { 144 TestRunner.run(suite()); 145 } 146 } | Popular Tags |