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
|
// **********************************************************************
//
// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#import <objc/Ice.h>
#import <TestCommon.h>
#import <LocationTest.h>
#include <Foundation/NSThread.h>
@interface DummyHelloI : TestLocationHello
@end
@implementation DummyHelloI
-(void) sayHello:(ICECurrent*)current
{
// Do nothing, this is just a dummy servant.
}
@end
void
locationAllTests(id<ICECommunicator> communicator, NSString* ref)
{
id<TestLocationServerManagerPrx> manager =
[TestLocationServerManagerPrx checkedCast:[communicator stringToProxy:ref]];
id<TestLocationTestLocatorPrx> locator =
[TestLocationTestLocatorPrx uncheckedCast:[communicator getDefaultLocator]];
test(manager);
id<TestLocationTestLocatorRegistryPrx> registry =
[TestLocationTestLocatorRegistryPrx checkedCast:[locator getRegistry]];
test(registry);
tprintf("testing stringToProxy... ");
id<ICEObjectPrx> base = [communicator stringToProxy:@"test @ TestAdapter"];
id<ICEObjectPrx> base2 = [communicator stringToProxy:@"test @ TestAdapter"];
id<ICEObjectPrx> base3 = [communicator stringToProxy:@"test"];
id<ICEObjectPrx> base4 = [communicator stringToProxy:@"ServerManager"];
id<ICEObjectPrx> base5 = [communicator stringToProxy:@"test2"];
id<ICEObjectPrx> base6 = [communicator stringToProxy:@"test @ ReplicatedAdapter"];
tprintf("ok\n");
tprintf("testing ice_locator and ice_getLocator... ");
test([[base ice_getLocator] compareIdentity:[communicator getDefaultLocator]] == NSOrderedSame);
id<ICELocatorPrx> anotherLocator = [ICELocatorPrx uncheckedCast:[communicator stringToProxy:@"anotherLocator"]];
base = [base ice_locator:anotherLocator];
test([[base ice_getLocator] compareIdentity:anotherLocator] == NSOrderedSame);
[communicator setDefaultLocator:0];
base = [communicator stringToProxy:@"test @ TestAdapter"];
test(![base ice_getLocator]);
base = [base ice_locator:anotherLocator];
test([[base ice_getLocator] compareIdentity:anotherLocator] == NSOrderedSame);
[communicator setDefaultLocator:locator];
base = [communicator stringToProxy:@"test @ TestAdapter"];
test([[base ice_getLocator] compareIdentity:[communicator getDefaultLocator]] == NSOrderedSame);
//
// We also test ice_router/ice_getRouter (perhaps we should add a
// test/Ice/router test?)
//
test(![base ice_getRouter]);
id<ICERouterPrx> anotherRouter = [ICERouterPrx uncheckedCast:[communicator stringToProxy:@"anotherRouter"]];
base = [base ice_router:anotherRouter];
test([[base ice_getRouter] compareIdentity:anotherRouter] == NSOrderedSame);
id<ICERouterPrx> router = [ICERouterPrx uncheckedCast:[communicator stringToProxy:@"dummyrouter"]];
[communicator setDefaultRouter:router];
base = [communicator stringToProxy:@"test @ TestAdapter"];
test([[base ice_getRouter] compareIdentity:[communicator getDefaultRouter]] == NSOrderedSame);
[communicator setDefaultRouter:0];
base = [communicator stringToProxy:@"test @ TestAdapter"];
test(![base ice_getRouter]);
tprintf("ok\n");
tprintf("starting server... ");
[manager startServer];
tprintf("ok\n");
tprintf("testing checked cast... ");
id<TestLocationTestIntfPrx> obj = [TestLocationTestIntfPrx checkedCast:base];
obj = [TestLocationTestIntfPrx checkedCast:[communicator stringToProxy:@"test@TestAdapter"]];
obj = [TestLocationTestIntfPrx checkedCast:[communicator stringToProxy:@"test @TestAdapter"]];
obj = [TestLocationTestIntfPrx checkedCast:[communicator stringToProxy:@"test@ TestAdapter"]];
test(obj);
id<TestLocationTestIntfPrx> obj2 = [TestLocationTestIntfPrx checkedCast:base2];
test(obj2);
id<TestLocationTestIntfPrx> obj3 = [TestLocationTestIntfPrx checkedCast:base3];
test(obj3);
id<TestLocationServerManagerPrx> obj4 = [TestLocationServerManagerPrx checkedCast:base4];
test(obj4);
id<TestLocationTestIntfPrx> obj5 = [TestLocationTestIntfPrx checkedCast:base5];
test(obj5);
id<TestLocationTestIntfPrx> obj6 = [TestLocationTestIntfPrx checkedCast:base6];
test(obj6);
tprintf("ok\n");
tprintf("testing id@AdapterId indirect proxy... ");
[obj shutdown];
[manager startServer];
@try
{
obj2 = [TestLocationTestIntfPrx checkedCast:base2];
[obj2 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
tprintf("ok\n");
tprintf("testing id@ReplicaGroupId indirect proxy... ");
[obj shutdown];
[manager startServer];
@try
{
obj6 = [TestLocationTestIntfPrx checkedCast:base6];
[obj6 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
tprintf("ok\n");
tprintf("testing identity indirect proxy... ");
[obj shutdown];
[manager startServer];
@try
{
obj3 = [TestLocationTestIntfPrx checkedCast:base3];
[obj3 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
@try
{
obj2 = [TestLocationTestIntfPrx checkedCast:base2];
[obj2 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
[obj shutdown];
[manager startServer];
@try
{
obj2 = [TestLocationTestIntfPrx checkedCast:base2];
[obj2 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
@try
{
obj3 = [TestLocationTestIntfPrx checkedCast:base3];
[obj3 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
[obj shutdown];
[manager startServer];
@try
{
obj2 = [TestLocationTestIntfPrx checkedCast:base2];
[obj2 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
[obj shutdown];
[manager startServer];
@try
{
obj3 = [TestLocationTestIntfPrx checkedCast:base3];
[obj3 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
[obj shutdown];
[manager startServer];
@try
{
obj2 = [TestLocationTestIntfPrx checkedCast:base2];
[obj2 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
[obj shutdown];
[manager startServer];
@try
{
obj5 = [TestLocationTestIntfPrx checkedCast:base5];
[obj5 ice_ping];
}
@catch(ICELocalException* ex)
{
NSLog(@"%@", ex);
test(NO);
}
tprintf("ok\n");
tprintf("testing proxy with unknown identity... ");
@try
{
base = [communicator stringToProxy:@"unknown/unknown"];
[base ice_ping];
test(NO);
}
@catch(ICENotRegisteredException* ex)
{
test([ex.kindOfObject isEqualToString:@"object"]);
test([ex.id_ isEqualToString:@"unknown/unknown"]);
}
tprintf("ok\n");
tprintf("testing proxy with unknown adapter... ");
@try
{
base = [communicator stringToProxy:@"test @ TestAdapterUnknown"];
[base ice_ping];
test(NO);
}
@catch(ICENotRegisteredException* ex)
{
test([ex.kindOfObject isEqualToString:@"object adapter"]);
test([ex.id_ isEqualToString:@"TestAdapterUnknown"]);
}
tprintf("ok\n");
tprintf("testing locator cache timeout... ");
int count = [locator getRequestCount];
[[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:0] ice_ping]; // No locator cache.
test(++count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:0] ice_ping]; // No locator cache.
test(++count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout.
test(count == [locator getRequestCount]);
[NSThread sleepForTimeInterval:1.2];
[[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout.
test(++count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:0] ice_ping]; // No locator cache.
count += 2;
test(count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout
test(count == [locator getRequestCount]);
[NSThread sleepForTimeInterval:1.2];
[[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout
count += 2;
test(count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:-1] ice_ping];
test(count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:-1] ice_ping];
test(count == [locator getRequestCount]);
[[communicator stringToProxy:@"test@TestAdapter"] ice_ping];
test(count == [locator getRequestCount]);
[[communicator stringToProxy:@"test"] ice_ping];
test(count == [locator getRequestCount]);
test([[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:99] ice_getLocatorCacheTimeout] == 99);
tprintf("ok\n");
tprintf("testing proxy from server... ");
id<TestLocationHelloPrx> hello = [obj getHello];
test([[hello ice_getAdapterId] isEqualToString:@"TestAdapter"]);
[hello sayHello];
hello = [obj getReplicatedHello];
test([[hello ice_getAdapterId] isEqualToString:@"ReplicatedAdapter"]);
[hello sayHello];
tprintf("ok\n");
tprintf("testing well-known object locator cache... ");
[registry addObject:[communicator stringToProxy:@"test3@TestUnknown"]];
@try
{
[[communicator stringToProxy:@"test3"] ice_ping];
test(NO);
}
@catch(ICENotRegisteredException* ex)
{
test([ex.kindOfObject isEqualToString:@"object adapter"]);
test([ex.id_ isEqualToString:@"TestUnknown"]);
}
[registry addObject:[communicator stringToProxy:@"test3@TestAdapter4"]]; // Update
[registry setAdapterDirectProxy:@"TestAdapter4" proxy:[communicator stringToProxy:@"dummy:tcp"]];
@try
{
[[communicator stringToProxy:@"test3"] ice_ping];
test(NO);
}
@catch(ICELocalException* ex)
{
}
[registry setAdapterDirectProxy:@"TestAdapter4" proxy:[locator findAdapterById:@"TestAdapter"]];
@try
{
[[communicator stringToProxy:@"test3"] ice_ping];
}
@catch(ICELocalException* ex)
{
test(NO);
}
[registry setAdapterDirectProxy:@"TestAdapter4" proxy:[communicator stringToProxy:@"dummy:tcp"]];
@try
{
[[communicator stringToProxy:@"test3"] ice_ping];
}
@catch(ICELocalException* ex)
{
test(NO);
}
@try
{
[[[communicator stringToProxy:@"test@TestAdapter4"] ice_locatorCacheTimeout:0] ice_ping];
test(NO);
}
@catch(ICELocalException* ex)
{
}
@try
{
[[communicator stringToProxy:@"test@TestAdapter4"] ice_ping];
test(NO);
}
@catch(ICELocalException* ex)
{
}
@try
{
[[communicator stringToProxy:@"test3"] ice_ping];
test(NO);
}
@catch(ICELocalException* ex)
{
}
[registry addObject:[communicator stringToProxy:@"test3@TestAdapter"]];
@try
{
[[communicator stringToProxy:@"test3"] ice_ping];
}
@catch(ICELocalException* ex)
{
test(NO);
}
[registry addObject:[communicator stringToProxy:@"test4"]];
@try
{
[[communicator stringToProxy:@"test4"] ice_ping];
test(NO);
}
@catch(ICENoEndpointException* ex)
{
}
tprintf("ok\n");
tprintf("testing proxy from server after shutdown... ");
[obj shutdown];
[manager startServer];
[hello sayHello];
tprintf("ok\n");
tprintf("testing object migration... ");
hello = [TestLocationHelloPrx checkedCast:[communicator stringToProxy:@"hello"]];
[obj migrateHello];
[hello sayHello];
[obj migrateHello];
[hello sayHello];
[obj migrateHello];
[hello sayHello];
tprintf("ok\n");
tprintf("testing locator encoding resolution... ");
hello = [TestLocationHelloPrx checkedCast:[communicator stringToProxy:@"hello"]];
count = [locator getRequestCount];
[[[communicator stringToProxy:@"test@TestAdapter"] ice_encodingVersion:ICEEncoding_1_1] ice_ping];
test(count == [locator getRequestCount]);
[[[communicator stringToProxy:@"test@TestAdapter10"] ice_encodingVersion:ICEEncoding_1_0] ice_ping];
test(++count == [locator getRequestCount]);
[[communicator stringToProxy:@"test -e 1.0@TestAdapter10-2"] ice_ping];
test(++count == [locator getRequestCount]);
tprintf("ok\n");
tprintf("shutdown server... ");
[obj shutdown];
tprintf("ok\n");
tprintf("testing whether server is gone... ");
@try
{
[obj2 ice_ping];
test(NO);
}
@catch(ICELocalException*)
{
}
@try
{
[obj3 ice_ping];
test(NO);
}
@catch(ICELocalException*)
{
}
@try
{
[obj5 ice_ping];
test(NO);
}
@catch(ICELocalException*)
{
}
tprintf("ok\n");
// tprintf("testing indirect proxies to collocated objects... ");
// //
// // Set up test for calling a collocated object through an indirect, adapterless reference.
// //
// id<ICEProperties> properties = [communicator getProperties];
// [properties setProperty:@"Ice.PrintAdapterReady" value:@"0"];
// id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints:@"Hello" endpoints:@"default"];
// [adapter setLocator:locator];
// id<TestLocationTestLocatorRegistryPrx> registry = [TestLocationTestLocatorRegistryPrx checkedCast:[locator getRegistry]];
// test(registry);
// ICEIdentity* ident = [ICEIdentity identity:[ICEUtil generateUUID] category:@""];
// [registry addObject:[adapter add:[DummyHelloI hello] identity:ident]];
// [adapter activate];
// @try
// {
// id<TestLocationHelloPrx> helloPrx = [TestLocationHelloPrx checkedCast:[communicator stringToProxy:
// [ICEUtil identityToString:ident]]];
// [helloPrx ice_getConnection];
// test(NO);
// }
// @catch(ICECollocationOptimizationException*)
// {
// }
// [adapter deactivate];
// tprintf("ok\n");
tprintf("shutdown server manager... ");
[manager shutdown];
tprintf("ok\n");
}
|