~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to cpp/test/Ice/location/AllTests.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
12
12
#include <IceUtil/IceUtil.h>
13
13
#include <TestCommon.h>
14
14
#include <Test.h>
 
15
#include <list>
15
16
 
16
17
using namespace std;
17
18
using namespace Test;
27
28
    }
28
29
};
29
30
 
 
31
class AMICallback : public IceUtil::Shared
 
32
{
 
33
public:
 
34
    AMICallback()
 
35
    {
 
36
    }
 
37
 
 
38
    void
 
39
    exception1(const Ice::Exception&)
 
40
    {
 
41
        test(false);
 
42
    }
 
43
    void
 
44
    exception2(const Ice::Exception& ex)
 
45
    {
 
46
        test(dynamic_cast<const Ice::NotRegisteredException*>(&ex));
 
47
    }
 
48
 
 
49
    void
 
50
    response1()
 
51
    {
 
52
    }
 
53
 
 
54
    void
 
55
    response2()
 
56
    {
 
57
        test(false);
 
58
    }
 
59
};
 
60
typedef IceUtil::Handle<AMICallback> AMICallbackPtr;
 
61
 
30
62
void
31
63
allTests(const Ice::CommunicatorPtr& communicator, const string& ref)
32
64
{
83
115
 
84
116
    cout << "testing checked cast... " << flush;
85
117
    TestIntfPrx obj = TestIntfPrx::checkedCast(base);
86
 
    obj = TestIntfPrx::checkedCast(communicator->stringToProxy("test@TestAdapter"));
87
 
    obj = TestIntfPrx::checkedCast(communicator->stringToProxy("test   @TestAdapter"));
88
 
    obj = TestIntfPrx::checkedCast(communicator->stringToProxy("test@   TestAdapter"));
89
118
    test(obj);
90
119
    TestIntfPrx obj2 = TestIntfPrx::checkedCast(base2);
91
120
    test(obj2);
104
133
    manager->startServer();
105
134
    try
106
135
    {
107
 
        obj2 = TestIntfPrx::checkedCast(base2);
108
136
        obj2->ice_ping();
109
137
    }
110
138
    catch(const Ice::LocalException& ex)
119
147
    manager->startServer();
120
148
    try
121
149
    {
122
 
        obj6 = TestIntfPrx::checkedCast(base6);
123
150
        obj6->ice_ping();
124
151
    }
125
152
    catch(const Ice::LocalException& ex)
134
161
    manager->startServer();
135
162
    try
136
163
    {
137
 
        obj3 = TestIntfPrx::checkedCast(base3);
138
 
        obj3->ice_ping();
139
 
    }
140
 
    catch(const Ice::LocalException& ex)
141
 
    {
142
 
        cerr << ex << endl;
143
 
        test(false);
144
 
    }
145
 
    try
146
 
    {
147
 
        obj2 = TestIntfPrx::checkedCast(base2);
148
 
        obj2->ice_ping();
149
 
    }
150
 
    catch(const Ice::LocalException& ex)
151
 
    {
152
 
        cerr << ex << endl;
153
 
        test(false);
154
 
    }
155
 
    obj->shutdown();
156
 
    manager->startServer();
157
 
    try
158
 
    {
159
 
        obj2 = TestIntfPrx::checkedCast(base2);
160
 
        obj2->ice_ping();
161
 
    }
162
 
    catch(const Ice::LocalException& ex)
163
 
    {
164
 
        cerr << ex << endl;
165
 
        test(false);
166
 
    }
167
 
    try
168
 
    {
169
 
        obj3 = TestIntfPrx::checkedCast(base3);
170
 
        obj3->ice_ping();
171
 
    }
172
 
    catch(const Ice::LocalException& ex)
173
 
    {
174
 
        cerr << ex << endl;
175
 
        test(false);
176
 
    }
177
 
    obj->shutdown();
178
 
    manager->startServer();
179
 
 
180
 
    try
181
 
    {
182
 
        obj2 = TestIntfPrx::checkedCast(base2);
183
 
        obj2->ice_ping();
184
 
    }
185
 
    catch(const Ice::LocalException& ex)
186
 
    {
187
 
        cerr << ex << endl;
188
 
        test(false);
189
 
    }
190
 
    obj->shutdown();
191
 
    manager->startServer();
192
 
    try
193
 
    {
194
 
        obj3 = TestIntfPrx::checkedCast(base3);
195
 
        obj3->ice_ping();
196
 
    }
197
 
    catch(const Ice::LocalException& ex)
198
 
    {
199
 
        cerr << ex << endl;
200
 
        test(false);
201
 
    }
202
 
    obj->shutdown();
203
 
    manager->startServer();
204
 
    try
205
 
    {
206
 
        obj2 = TestIntfPrx::checkedCast(base2);
207
 
        obj2->ice_ping();
208
 
    }
209
 
    catch(const Ice::LocalException& ex)
210
 
    {
211
 
        cerr << ex << endl;
212
 
        test(false);
213
 
    }
214
 
    obj->shutdown();
215
 
    manager->startServer();
216
 
 
217
 
    try
218
 
    {
219
 
        obj5 = TestIntfPrx::checkedCast(base5);
 
164
        obj3->ice_ping();
 
165
    }
 
166
    catch(const Ice::LocalException& ex)
 
167
    {
 
168
        cerr << ex << endl;
 
169
        test(false);
 
170
    }
 
171
    try
 
172
    {
 
173
        obj2->ice_ping();
 
174
    }
 
175
    catch(const Ice::LocalException& ex)
 
176
    {
 
177
        cerr << ex << endl;
 
178
        test(false);
 
179
    }
 
180
    obj->shutdown();
 
181
    manager->startServer();
 
182
    try
 
183
    {
 
184
        obj2->ice_ping();
 
185
    }
 
186
    catch(const Ice::LocalException& ex)
 
187
    {
 
188
        cerr << ex << endl;
 
189
        test(false);
 
190
    }
 
191
    try
 
192
    {
 
193
        obj3->ice_ping();
 
194
    }
 
195
    catch(const Ice::LocalException& ex)
 
196
    {
 
197
        cerr << ex << endl;
 
198
        test(false);
 
199
    }
 
200
    obj->shutdown();
 
201
    manager->startServer();
 
202
 
 
203
    try
 
204
    {
 
205
        obj2->ice_ping();
 
206
    }
 
207
    catch(const Ice::LocalException& ex)
 
208
    {
 
209
        cerr << ex << endl;
 
210
        test(false);
 
211
    }
 
212
    obj->shutdown();
 
213
    manager->startServer();
 
214
    try
 
215
    {
 
216
        obj3->ice_ping();
 
217
    }
 
218
    catch(const Ice::LocalException& ex)
 
219
    {
 
220
        cerr << ex << endl;
 
221
        test(false);
 
222
    }
 
223
    obj->shutdown();
 
224
    manager->startServer();
 
225
    try
 
226
    {
 
227
        obj2->ice_ping();
 
228
    }
 
229
    catch(const Ice::LocalException& ex)
 
230
    {
 
231
        cerr << ex << endl;
 
232
        test(false);
 
233
    }
 
234
    obj->shutdown();
 
235
    manager->startServer();
 
236
 
 
237
    try
 
238
    {
220
239
        obj5->ice_ping();
221
240
    }
222
241
    catch(const Ice::LocalException& ex)
263
282
    test(++count == locator->getRequestCount());
264
283
    communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout.
265
284
    test(count == locator->getRequestCount());
266
 
    IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1200));
 
285
    IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1300));
267
286
    communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout.
268
287
    test(++count == locator->getRequestCount());
269
288
 
272
291
    test(count == locator->getRequestCount());
273
292
    communicator->stringToProxy("test")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout
274
293
    test(count == locator->getRequestCount());
275
 
    IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1200));
 
294
    IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1300));
276
295
    communicator->stringToProxy("test")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout
277
296
    count += 2;
278
297
    test(count == locator->getRequestCount());
306
325
    hello->ice_ping();
307
326
    test(++count == locator->getRequestCount());
308
327
    int i;
 
328
 
 
329
    list<Ice::AsyncResultPtr>  results;
 
330
    AMICallbackPtr cb = new AMICallback;
309
331
    for(i = 0; i < 1000; i++)
310
332
    {
311
 
        class AMICallback : public Test::AMI_Hello_sayHello
312
 
        {
313
 
        public:
314
 
            virtual void
315
 
            ice_exception(const Ice::Exception&)
316
 
            {
317
 
                test(false);
318
 
            }
319
 
 
320
 
            virtual void
321
 
            ice_response()
322
 
            {
323
 
            }
324
 
        };
325
 
        hello->sayHello_async(new AMICallback());
326
 
    }
327
 
    hello->ice_ping();
 
333
        Ice::AsyncResultPtr result = hello->begin_sayHello(
 
334
            newCallback_Hello_sayHello(cb, &AMICallback::response1, &AMICallback::exception1));
 
335
        results.push_back(result);
 
336
    }
 
337
    while(!results.empty())
 
338
    {
 
339
        Ice::AsyncResultPtr result = results.front();
 
340
        results.pop_front();
 
341
        result->waitForCompleted();
 
342
    }
328
343
    test(locator->getRequestCount() > count && locator->getRequestCount() < count + 999);
329
344
    if(locator->getRequestCount() > count + 800)
330
345
    {
334
349
    hello = hello->ice_adapterId("unknown");
335
350
    for(i = 0; i < 1000; i++)
336
351
    {
337
 
        class AMICallback : public Test::AMI_Hello_sayHello
338
 
        {
339
 
        public:
340
 
            virtual void
341
 
            ice_exception(const Ice::Exception& ex)
342
 
            {
343
 
                test(dynamic_cast<const Ice::NotRegisteredException*>(&ex));
344
 
            }
345
 
 
346
 
            virtual void
347
 
            ice_response()
348
 
            {
349
 
                test(false);
350
 
            }
351
 
        };
352
 
        hello->sayHello_async(new AMICallback());
353
 
    }
354
 
    try
355
 
    {
356
 
        hello->ice_ping();
357
 
        test(false);
358
 
    }
359
 
    catch(const Ice::NotRegisteredException&)
360
 
    {
 
352
        Ice::AsyncResultPtr result = hello->begin_sayHello(
 
353
            newCallback_Hello_sayHello(cb, &AMICallback::response2, &AMICallback::exception2));
 
354
        results.push_back(result);
 
355
    }
 
356
    while(!results.empty())
 
357
    {
 
358
        Ice::AsyncResultPtr result = results.front();
 
359
        results.pop_front();
 
360
        result->waitForCompleted();
361
361
    }
362
362
    // Take into account the retries.
363
363
    test(locator->getRequestCount() > count && locator->getRequestCount() < count + 1999);
368
368
    cout << "ok" << endl;
369
369
 
370
370
    cout << "testing adapter locator cache... " << flush;
371
 
 
372
371
    try
373
372
    {
374
373
        communicator->stringToProxy("test@TestAdapter3")->ice_ping();
528
527
        test(count == locator->getRequestCount());
529
528
        IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1200));
530
529
 
531
 
        // The following requets should trigger the background updates but still use the cached endpoints
 
530
        // The following request should trigger the background updates but still use the cached endpoints
532
531
        // and therefore succeed.
533
532
        ic->stringToProxy("test@TestAdapter5")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout.
534
533
        ic->stringToProxy("test3")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout.