1 21 22 package org.jacorb.test.notification; 23 24 import java.util.Date ; 25 26 import junit.framework.Test; 27 28 import org.jacorb.test.notification.common.NotifyServerTestCase; 29 import org.jacorb.test.notification.common.NotifyServerTestSetup; 30 import org.jacorb.util.Time; 31 import org.omg.CORBA.Any ; 32 import org.omg.CosNotification.EventHeader; 33 import org.omg.CosNotification.EventType; 34 import org.omg.CosNotification.FixedEventHeader; 35 import org.omg.CosNotification.Property; 36 import org.omg.CosNotification.StartTime; 37 import org.omg.CosNotification.StructuredEvent; 38 import org.omg.CosNotification.Timeout; 39 import org.omg.CosNotifyChannelAdmin.EventChannel; 40 import org.omg.TimeBase.TimeTHelper; 41 import org.omg.TimeBase.UtcTHelper; 42 43 public class TimeoutIntegrationTest extends NotifyServerTestCase 44 { 45 EventChannel eventChannel_; 46 47 StructuredEvent structuredEvent_; 48 49 public TimeoutIntegrationTest(String name, NotifyServerTestSetup setup) 50 { 51 super(name, setup); 52 } 53 54 public void setUpTest() throws Exception 55 { 56 eventChannel_ = getDefaultChannel(); 57 58 structuredEvent_ = new StructuredEvent(); 59 EventHeader _header = new EventHeader(); 60 FixedEventHeader _fixed = new FixedEventHeader(); 61 _fixed.event_name = "eventname"; 62 _fixed.event_type = new EventType("domain", "type"); 63 _header.fixed_header = _fixed; 64 _header.variable_header = new Property[0]; 65 66 structuredEvent_.header = _header; 67 68 structuredEvent_.filterable_data = new Property[0]; 69 70 structuredEvent_.remainder_of_body = getClientORB().create_any(); 71 } 72 73 public void testSendEventWithTimeout() throws Exception 74 { 75 sendEvent(0, 1000, true); 76 77 sendEvent(2000, 500, false); 78 79 sendEvent(1000, 2000, true); 80 } 81 82 private void sendEvent(long startOffset, long timeout, boolean expect) throws Exception 83 { 84 structuredEvent_.header.variable_header = new Property[2]; 85 86 Date _time = new Date (System.currentTimeMillis() + startOffset); 87 88 Any _startTimeAny = getClientORB().create_any(); 89 90 UtcTHelper.insert(_startTimeAny, Time.corbaTime(_time)); 91 92 structuredEvent_.header.variable_header[0] = new Property(StartTime.value, _startTimeAny); 93 94 Any _timeoutAny = getClientORB().create_any(); 95 TimeTHelper.insert(_timeoutAny, timeout); 96 97 structuredEvent_.header.variable_header[1] = new Property(Timeout.value, _timeoutAny); 98 99 StructuredPushSender _sender = new StructuredPushSender(getClientORB()); 100 101 _sender.setStructuredEvent(structuredEvent_); 102 103 StructuredPushReceiver _receiver = new StructuredPushReceiver(getClientORB()); 104 105 _sender.connect(eventChannel_, false); 106 _receiver.connect(eventChannel_, false); 107 108 new Thread (_receiver).start(); 109 new Thread (_sender).start(); 110 111 Thread.sleep(startOffset + 2000); 112 113 if (expect) 114 { 115 assertTrue("Receiver should have received something", _receiver.isEventHandled()); 116 } 117 else 118 { 119 assertTrue("Receiver shouldn't have received anything", !_receiver.isEventHandled()); 120 } 121 122 _receiver.shutdown(); 123 _sender.shutdown(); 124 } 125 126 public static Test suite() throws Exception 127 { 128 return NotifyServerTestCase.suite(TimeoutIntegrationTest.class); 129 } 130 } 131 | Popular Tags |