KickJava   Java API By Example, From Geeks To Geeks.

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


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

21
22 package org.jacorb.test.notification;
23
24 import java.util.Date JavaDoc;
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 JavaDoc;
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 JavaDoc name, NotifyServerTestSetup setup)
50     {
51         super(name, setup);
52     }
53
54     public void setUpTest() throws Exception JavaDoc
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 JavaDoc
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 JavaDoc
83     {
84         structuredEvent_.header.variable_header = new Property[2];
85
86         Date JavaDoc _time = new Date JavaDoc(System.currentTimeMillis() + startOffset);
87
88         Any JavaDoc _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 JavaDoc _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 JavaDoc(_receiver).start();
109         new Thread JavaDoc(_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 JavaDoc
127     {
128         return NotifyServerTestCase.suite(TimeoutIntegrationTest.class);
129     }
130 }
131
Popular Tags