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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#
def test(b)
if !b
raise RuntimeError, 'test assertion failed'
end
end
def createTestIntfPrx(adapters)
endpoints = []
test = nil
for p in adapters
test = p.getTestIntf()
edpts = test.ice_getEndpoints()
endpoints.concat(edpts)
end
return Test::TestIntfPrx::uncheckedCast(test.ice_endpoints(endpoints))
end
def deactivate(com, adapters)
for p in adapters
com.deactivateObjectAdapter(p)
end
end
def allTests(helper, communicator)
ref = "communicator:#{helper.getTestEndpoint()}"
com = Test::RemoteCommunicatorPrx::uncheckedCast(communicator.stringToProxy(ref))
print "testing binding with single endpoint... "
STDOUT.flush
adapter = com.createObjectAdapter("Adapter", "default")
test1 = adapter.getTestIntf()
test2 = adapter.getTestIntf()
test(test1.ice_getConnection() == test2.ice_getConnection())
test1.ice_ping()
test2.ice_ping()
com.deactivateObjectAdapter(adapter)
test3 = Test::TestIntfPrx::uncheckedCast(test1)
test(test3.ice_getConnection() == test1.ice_getConnection())
test(test3.ice_getConnection() == test2.ice_getConnection())
begin
test3.ice_ping()
test(false)
rescue Ice::ConnectionRefusedException
# Expected
rescue Ice::ConnectTimeoutException
# Expected
end
puts "ok"
print "testing binding with multiple endpoints... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter11", "default"))
adapters.push(com.createObjectAdapter("Adapter12", "default"))
adapters.push(com.createObjectAdapter("Adapter13", "default"))
#
# Ensure that when a connection is opened it's reused for new
# proxies and that all endpoints are eventually tried.
#
names = ["Adapter11", "Adapter12", "Adapter13"]
while names.length > 0
adpts = adapters.clone
test1 = createTestIntfPrx(adpts)
adpts = adpts.sort_by { rand }
test2 = createTestIntfPrx(adpts)
adpts = adpts.sort_by { rand }
test3 = createTestIntfPrx(adpts)
test(test1.ice_getConnection() == test2.ice_getConnection())
test(test2.ice_getConnection() == test3.ice_getConnection())
name = test1.getAdapterName()
if names.include?(name)
names.delete(name)
end
test1.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
#
# Ensure that the proxy correctly caches the connection (we
# always send the request over the same connection.)
#
for a in adapters
a.getTestIntf().ice_ping()
end
t = createTestIntfPrx(adapters)
name = t.getAdapterName()
i = 0
nRetry = 5
while i < nRetry and t.getAdapterName() == name
i = i + 1
end
test(i == nRetry)
for a in adapters
a.getTestIntf().ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
#
# Deactivate an adapter and ensure that we can still
# establish the connection to the remaining adapters.
#
com.deactivateObjectAdapter(adapters[0])
names.push("Adapter12")
names.push("Adapter13")
while names.length > 0
adpts = adapters.clone
test1 = createTestIntfPrx(adpts)
adpts = adpts.sort_by { rand }
test2 = createTestIntfPrx(adpts)
adpts = adpts.sort_by { rand }
test3 = createTestIntfPrx(adpts)
test(test1.ice_getConnection() == test2.ice_getConnection())
test(test2.ice_getConnection() == test3.ice_getConnection())
name = test1.getAdapterName()
if names.include?(name)
names.delete(name)
end
test1.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
#
# Deactivate an adapter and ensure that we can still
# establish the connection to the remaining adapters.
#
com.deactivateObjectAdapter(adapters[2])
t = createTestIntfPrx(adapters)
test(t.getAdapterName() == "Adapter12")
deactivate(com, adapters)
puts "ok"
print "testing random endpoint selection... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter21", "default"))
adapters.push(com.createObjectAdapter("Adapter22", "default"))
adapters.push(com.createObjectAdapter("Adapter23", "default"))
t = createTestIntfPrx(adapters)
test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Random)
names = ["Adapter21", "Adapter22", "Adapter23"]
while names.length > 0
name = t.getAdapterName()
if names.include?(name)
names.delete(name)
end
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
t = Test::TestIntfPrx::uncheckedCast(t.ice_endpointSelection(Ice::EndpointSelectionType::Random))
test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Random)
names.push("Adapter21")
names.push("Adapter22")
names.push("Adapter23")
while names.length > 0
name = t.getAdapterName()
if names.include?(name)
names.delete(name)
end
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
deactivate(com, adapters)
puts "ok"
print "testing ordered endpoint selection... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter31", "default"))
adapters.push(com.createObjectAdapter("Adapter32", "default"))
adapters.push(com.createObjectAdapter("Adapter33", "default"))
t = createTestIntfPrx(adapters)
t = Test::TestIntfPrx::uncheckedCast(t.ice_endpointSelection(Ice::EndpointSelectionType::Ordered))
test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Ordered)
nRetry = 5
#
# Ensure that endpoints are tried in order by deactivating the adapters
# one after the other.
#
i = 0
while i < nRetry and t.getAdapterName() == "Adapter31"
i = i + 1
end
test(i == nRetry)
com.deactivateObjectAdapter(adapters[0])
i = 0
while i < nRetry and t.getAdapterName() == "Adapter32"
i = i + 1
end
test(i == nRetry)
com.deactivateObjectAdapter(adapters[1])
i = 0
while i < nRetry and t.getAdapterName() == "Adapter33"
i = i + 1
end
test(i == nRetry)
com.deactivateObjectAdapter(adapters[2])
begin
t.getAdapterName()
rescue Ice::ConnectionRefusedException
# Expected
rescue Ice::ConnectTimeoutException
# Expected
end
endpoints = t.ice_getEndpoints()
adapters = []
#
# Now, re-activate the adapters with the same endpoints in the opposite
# order.
#
adapters.push(com.createObjectAdapter("Adapter36", endpoints[2].toString()))
i = 0
while i < nRetry and t.getAdapterName() == "Adapter36"
i = i + 1
end
test(i == nRetry)
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
adapters.push(com.createObjectAdapter("Adapter35", endpoints[1].toString()))
i = 0
while i < nRetry and t.getAdapterName() == "Adapter35"
i = i + 1
end
test(i == nRetry)
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
adapters.push(com.createObjectAdapter("Adapter34", endpoints[0].toString()))
i = 0
while i < nRetry and t.getAdapterName() == "Adapter34"
i = i + 1
end
test(i == nRetry)
deactivate(com, adapters)
puts "ok"
print "testing per request binding with single endpoint... "
STDOUT.flush
adapter = com.createObjectAdapter("Adapter41", "default")
test1 = Test::TestIntfPrx::uncheckedCast(adapter.getTestIntf().ice_connectionCached(false))
test2 = Test::TestIntfPrx::uncheckedCast(adapter.getTestIntf().ice_connectionCached(false))
test(!test1.ice_isConnectionCached())
test(!test2.ice_isConnectionCached())
test(test1.ice_getConnection() == test2.ice_getConnection())
test1.ice_ping()
com.deactivateObjectAdapter(adapter)
test3 = Test::TestIntfPrx::uncheckedCast(test1)
begin
test(test3.ice_getConnection() == test1.ice_getConnection())
test(false)
rescue Ice::ConnectionRefusedException
# Expected
rescue Ice::ConnectTimeoutException
# Expected
end
puts "ok"
print "testing per request binding with multiple endpoints... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter51", "default"))
adapters.push(com.createObjectAdapter("Adapter52", "default"))
adapters.push(com.createObjectAdapter("Adapter53", "default"))
t = Test::TestIntfPrx::uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false))
test(!t.ice_isConnectionCached())
names = ["Adapter51", "Adapter52", "Adapter53"]
while names.length > 0
name = t.getAdapterName()
if names.include?(name)
names.delete(name)
end
end
com.deactivateObjectAdapter(adapters[0])
names.push("Adapter52")
names.push("Adapter53")
while names.length > 0
name = t.getAdapterName()
if names.include?(name)
names.delete(name)
end
end
com.deactivateObjectAdapter(adapters[2])
test(t.getAdapterName() == "Adapter52")
deactivate(com, adapters)
puts "ok"
print "testing per request binding and ordered endpoint selection... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter61", "default"))
adapters.push(com.createObjectAdapter("Adapter62", "default"))
adapters.push(com.createObjectAdapter("Adapter63", "default"))
t = createTestIntfPrx(adapters)
t = Test::TestIntfPrx::uncheckedCast(t.ice_endpointSelection(Ice::EndpointSelectionType::Ordered))
test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Ordered)
t = Test::TestIntfPrx::uncheckedCast(t.ice_connectionCached(false))
test(!t.ice_isConnectionCached())
nRetry = 5
#
# Ensure that endpoints are tried in order by deactiving the adapters
# one after the other.
#
i = 0
while i < nRetry and t.getAdapterName() == "Adapter61"
i = i + 1
end
test(i == nRetry)
com.deactivateObjectAdapter(adapters[0])
i = 0
while i < nRetry and t.getAdapterName() == "Adapter62"
i = i + 1
end
test(i == nRetry)
com.deactivateObjectAdapter(adapters[1])
i = 0
while i < nRetry and t.getAdapterName() == "Adapter63"
i = i + 1
end
test(i == nRetry)
com.deactivateObjectAdapter(adapters[2])
begin
t.getAdapterName()
rescue Ice::ConnectionRefusedException
# Expected
rescue Ice::ConnectTimeoutException
# Expected
end
endpoints = t.ice_getEndpoints()
adapters = []
#
# Now, re-activate the adapters with the same endpoints in the opposite
# order.
#
adapters.push(com.createObjectAdapter("Adapter66", endpoints[2].toString()))
i = 0
while i < nRetry and t.getAdapterName() == "Adapter66"
i = i + 1
end
test(i == nRetry)
adapters.push(com.createObjectAdapter("Adapter65", endpoints[1].toString()))
i = 0
while i < nRetry and t.getAdapterName() == "Adapter65"
i = i + 1
end
test(i == nRetry)
adapters.push(com.createObjectAdapter("Adapter64", endpoints[0].toString()))
i = 0
while i < nRetry and t.getAdapterName() == "Adapter64"
i = i + 1
end
test(i == nRetry)
deactivate(com, adapters)
puts "ok"
print "testing endpoint mode filtering... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter71", "default"))
adapters.push(com.createObjectAdapter("Adapter72", "udp"))
t = createTestIntfPrx(adapters)
test(t.getAdapterName() == "Adapter71")
testUDP = Test::TestIntfPrx::uncheckedCast(t.ice_datagram())
test(t.ice_getConnection() != testUDP.ice_getConnection())
begin
testUDP.getAdapterName()
rescue Ice::TwowayOnlyException
# Expected
end
puts "ok"
if communicator.getProperties().getProperty("Ice.Plugin.IceSSL").length > 0
print "testing unsecure vs. secure endpoints... "
STDOUT.flush
adapters = []
adapters.push(com.createObjectAdapter("Adapter81", "ssl"))
adapters.push(com.createObjectAdapter("Adapter82", "tcp"))
t = createTestIntfPrx(adapters)
for i in 0...5
test(t.getAdapterName() == "Adapter82")
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
testSecure = Test::TestIntfPrx::uncheckedCast(t.ice_secure(true))
test(testSecure.ice_isSecure())
testSecure = Test::TestIntfPrx::uncheckedCast(t.ice_secure(false))
test(!testSecure.ice_isSecure())
testSecure = Test::TestIntfPrx::uncheckedCast(t.ice_secure(true))
test(testSecure.ice_isSecure())
test(t.ice_getConnection() != testSecure.ice_getConnection())
com.deactivateObjectAdapter(adapters[1])
for i in 0...5
test(t.getAdapterName() == "Adapter81")
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
com.createObjectAdapter("Adapter83", (t.ice_getEndpoints()[1]).toString()) # Reactive tcp OA.
for i in 0...5
test(t.getAdapterName() == "Adapter83")
t.ice_getConnection().close(Ice::ConnectionClose::GracefullyWithWait)
end
com.deactivateObjectAdapter(adapters[0])
begin
testSecure.ice_ping()
test(false)
rescue Ice::ConnectionRefusedException
# Expected
rescue Ice::ConnectTimeoutException
# Expected
end
deactivate(com, adapters)
puts "ok"
end
com.shutdown()
end
|