forked from JacORB/JacORB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisconnectTest.java
250 lines (220 loc) · 7.67 KB
/
DisconnectTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package org.jacorb.test.orb;
/*
* JacORB - a free Java ORB
*
* Copyright (C) 1997-2013 Gerald Brose / The JacORB Team.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jacorb.orb.Delegate;
import org.jacorb.orb.giop.ClientConnection;
import org.jacorb.orb.giop.ClientConnectionManager;
import org.jacorb.test.BasicServer;
import org.jacorb.test.BasicServerHelper;
import org.jacorb.test.common.ClientServerSetup;
import org.jacorb.test.common.ClientServerTestCase;
import org.jacorb.test.common.JacORBTestSuite;
import org.omg.CORBA.TIMEOUT;
import org.omg.ETF.Profile;
/**
* @author Nick Cross
*
* Verifies that the connection map is cleared after a timeout and disconnect.
*/
public class DisconnectTest extends ClientServerTestCase
{
protected BasicServer server = null;
public DisconnectTest(String name, ClientServerSetup setup)
{
super(name, setup);
}
protected void setUp() throws Exception
{
server = BasicServerHelper.narrow( setup.getServerObject() );
}
protected void tearDown() throws Exception
{
server = null;
}
public static Test suite()
{
TestSuite suite = new JacORBTestSuite("Disconnect client test", DisconnectTest.class);
Properties client_props = new Properties();
client_props.setProperty ("jacorb.retries", "0");
client_props.setProperty ("jacorb.retry_interval", "50");
client_props.setProperty
("jacorb.connection.client.pending_reply_timeout", "5000");
Properties server_props = new Properties();
server_props.setProperty( "org.omg.PortableInterceptor.ORBInitializerClass."
+ DisconnectInitializer.class.getName(), "" );
ClientServerSetup setup = new ClientServerSetup( suite,
"org.jacorb.test.orb.BasicServerImpl",
client_props,
server_props);
suite.addTest( new DisconnectTest( "test_disconnect", setup ));
return setup;
}
public void test_disconnect()
{
boolean timeout = false;
try
{
server.ping();
}
catch (TIMEOUT e)
{
timeout = true;
Field fconnmgr;
Field connections;
try
{
fconnmgr = Delegate.class.getDeclaredField("conn_mg");
fconnmgr.setAccessible(true);
Delegate d = (Delegate) ((org.omg.CORBA.portable.ObjectImpl)server)._get_delegate();
ClientConnectionManager ccm = (ClientConnectionManager) fconnmgr.get(d);
connections = ClientConnectionManager.class.getDeclaredField("connections");
connections.setAccessible(true);
@SuppressWarnings("unchecked")
HashMap<Profile, ClientConnection> c = (HashMap<Profile, ClientConnection>) connections.get(ccm);
assertTrue (c.size() == 0);
}
catch (SecurityException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (NoSuchFieldException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IllegalArgumentException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IllegalAccessException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if ( ! timeout )
{
fail ("Did not catch a timeout");
}
}
public static class DisconnectInitializer
extends org.omg.CORBA.LocalObject
implements org.omg.PortableInterceptor.ORBInitializer
{
/**
* Called before init of the actual ORB.
*
* @param info The ORB init info.
*/
public void pre_init (org.omg.PortableInterceptor.ORBInitInfo info)
{
try
{
info.add_server_request_interceptor (new ServerInterceptorA());
}
catch ( org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName ex )
{
fail ("unexpected exception received: " + ex);
}
}
/**
* Called after init of the actual ORB.
*
* @param info The ORB init info.
*/
public void post_init (org.omg.PortableInterceptor.ORBInitInfo info)
{
}
}
static class ServerInterceptorA
extends org.omg.CORBA.LocalObject
implements org.omg.PortableInterceptor.ServerRequestInterceptor
{
static boolean localDebugOn = false;
public java.lang.String name()
{
return "";
}
public void destroy()
{
}
public void receive_request_service_contexts(
org.omg.PortableInterceptor.ServerRequestInfo ri )
throws org.omg.PortableInterceptor.ForwardRequest
{
if (localDebugOn)
{
System.out.println ("LocalServerInterceptorA - receive_request_service_contexts");
}
}
public void receive_request( org.omg.PortableInterceptor.ServerRequestInfo ri )
throws org.omg.PortableInterceptor.ForwardRequest
{
if (localDebugOn)
{
System.out.println ("LocalServerInterceptorA - receive_request");
}
try
{
Thread.sleep (10000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void send_reply( org.omg.PortableInterceptor.ServerRequestInfo ri )
{
if (localDebugOn)
{
System.out.println ("LocalServerInterceptorA - send_reply");
}
}
public void send_exception( org.omg.PortableInterceptor.ServerRequestInfo ri )
throws org.omg.PortableInterceptor.ForwardRequest
{
if (localDebugOn)
{
System.out.println ("LocalServerInterceptorA - send_exception");
}
}
public void send_other( org.omg.PortableInterceptor.ServerRequestInfo ri )
throws org.omg.PortableInterceptor.ForwardRequest
{
if (localDebugOn)
{
System.out.println ("LocalServerInterceptorA - send_other");
}
}
}
public static void main(String args[])
{
junit.textui.TestRunner.run(suite());
}
}