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

« back to all changes in this revision

Viewing changes to java/test/Ice/binding/AllTests.java

  • 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.
7
7
//
8
8
// **********************************************************************
9
9
 
10
 
import Test.*;
 
10
package test.Ice.binding;
 
11
 
 
12
import java.io.PrintWriter;
 
13
 
 
14
import test.Ice.binding.Test.RemoteCommunicatorPrx;
 
15
import test.Ice.binding.Test.RemoteCommunicatorPrxHelper;
 
16
import test.Ice.binding.Test.RemoteObjectAdapterPrx;
 
17
import test.Ice.binding.Test.TestIntfPrx;
 
18
import test.Ice.binding.Test.TestIntfPrxHelper;
 
19
import test.Ice.binding.Test.Callback_TestIntf_getAdapterName;
11
20
 
12
21
public class AllTests
13
22
{
20
29
        }
21
30
    }
22
31
 
23
 
    static class NoOpGetAdapterNameCB extends AMI_TestIntf_getAdapterName
24
 
    {
25
 
        public
26
 
        void ice_response(String name)
27
 
        {
28
 
        }
29
 
        
30
 
        public void
31
 
        ice_exception(Ice.LocalException ex)
32
 
        {
33
 
        }
34
 
 
35
 
        public void
36
 
        ice_exception(Ice.UserException ex)
37
 
        {
38
 
        }
39
 
    };
40
 
 
41
 
    static class GetAdapterNameCB extends AMI_TestIntf_getAdapterName
 
32
    static class GetAdapterNameCB extends Ice.Callback
42
33
    {
43
34
        synchronized public void
44
 
        ice_response(String adapterName)
45
 
        {
46
 
            _name = adapterName;
47
 
            notify();
48
 
        }
49
 
 
50
 
        public void
51
 
        ice_exception(Ice.LocalException ex)
52
 
        {
53
 
            test(false);
54
 
        }
55
 
 
56
 
        public void
57
 
        ice_exception(Ice.UserException ex)
58
 
        {
59
 
            test(false);
 
35
        completed(Ice.AsyncResult result)
 
36
        {
 
37
            try
 
38
            {
 
39
                _name = TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_getAdapterName(result);
 
40
                notify();
 
41
            }
 
42
            catch(Ice.LocalException ex)
 
43
            {
 
44
                test(false);
 
45
            }
60
46
        }
61
47
 
62
48
        synchronized public String
82
68
    getAdapterNameWithAMI(TestIntfPrx test)
83
69
    {
84
70
        GetAdapterNameCB cb = new GetAdapterNameCB();
85
 
        test.getAdapterName_async(cb);
 
71
        test.begin_getAdapterName(cb);
86
72
        return cb.getResult();
87
73
    }
88
74
 
91
77
    {
92
78
        java.util.List<Ice.Endpoint> endpoints = new java.util.ArrayList<Ice.Endpoint>();
93
79
        TestIntfPrx test = null;
94
 
        java.util.Iterator<RemoteObjectAdapterPrx> p = adapters.iterator();
95
 
        while(p.hasNext())
 
80
        for(RemoteObjectAdapterPrx p : adapters)
96
81
        {
97
 
            test = p.next().getTestIntf();
 
82
            test = p.getTestIntf();
98
83
            Ice.Endpoint[] edpts = test.ice_getEndpoints();
99
84
            endpoints.addAll(java.util.Arrays.asList(edpts));
100
85
        }
105
90
    private static void
106
91
    deactivate(RemoteCommunicatorPrx communicator, java.util.List<RemoteObjectAdapterPrx> adapters)
107
92
    {
108
 
        java.util.Iterator<RemoteObjectAdapterPrx> p = adapters.iterator();
109
 
        while(p.hasNext())
 
93
        for(RemoteObjectAdapterPrx p : adapters)
110
94
        {
111
 
            communicator.deactivateObjectAdapter(p.next());
 
95
            communicator.deactivateObjectAdapter(p);
112
96
        }
113
97
    }
114
98
 
115
99
    public static void
116
 
    allTests(Ice.Communicator communicator)
 
100
    allTests(Ice.Communicator communicator, PrintWriter out)
117
101
    {
118
 
        String ref = "communicator:default -p 12010 -t 10000";
 
102
        String ref = "communicator:default -p 12010";
119
103
        RemoteCommunicatorPrx com = RemoteCommunicatorPrxHelper.uncheckedCast(communicator.stringToProxy(ref));
120
104
 
121
 
        System.out.print("testing binding with single endpoint... ");
122
 
        System.out.flush();
 
105
                out.print("testing binding with single endpoint... ");
 
106
        out.flush();
123
107
        {
124
108
            RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default");
125
109
 
141
125
                test3.ice_ping();
142
126
                test(false);
143
127
            }
144
 
            catch(Ice.ConnectionRefusedException ex)
 
128
            catch(Ice.ConnectFailedException ex)
145
129
            {
 
130
                //
 
131
                // Usually the actual type of this exception is ConnectionRefusedException,
 
132
                // but not always. See bug 3179.
 
133
                //
146
134
            }
147
135
        }
148
 
        System.out.println("ok");
 
136
        out.println("ok");
149
137
 
150
 
        System.out.print("testing binding with multiple endpoints... ");
151
 
        System.out.flush();
 
138
        out.print("testing binding with multiple endpoints... ");
 
139
        out.flush();
152
140
        {
153
141
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
154
142
            adapters.add(com.createObjectAdapter("Adapter11", "default"));
186
174
            // always send the request over the same connection.)
187
175
            //
188
176
            {
189
 
                java.util.Iterator<RemoteObjectAdapterPrx> p = adapters.iterator();
190
 
                while(p.hasNext())
 
177
                for(RemoteObjectAdapterPrx p : adapters)
191
178
                {
192
 
                    p.next().getTestIntf().ice_ping();
 
179
                    p.getTestIntf().ice_ping();
193
180
                }
194
181
 
195
182
                TestIntfPrx test = createTestIntfPrx(adapters);
199
186
                for(i = 0; i < nRetry && test.getAdapterName().equals(name); i++);
200
187
                test(i == nRetry);
201
188
 
202
 
                p = adapters.iterator();
203
 
                while(p.hasNext())
 
189
                for(RemoteObjectAdapterPrx p : adapters)
204
190
                {
205
 
                    p.next().getTestIntf().ice_getConnection().close(false);
 
191
                    p.getTestIntf().ice_getConnection().close(false);
206
192
                }
207
193
            }
208
194
 
241
227
 
242
228
            deactivate(com, adapters);
243
229
        }
244
 
        System.out.println("ok");
 
230
        out.println("ok");
245
231
 
246
 
        System.out.print("testing binding with multiple random endpoints... ");
247
 
        System.out.flush();
 
232
        out.print("testing binding with multiple random endpoints... ");
 
233
        out.flush();
248
234
        {
249
235
            java.util.Random rand = new java.util.Random();
250
236
 
258
244
            int count;
259
245
            if(System.getProperty("os.name").startsWith("Windows"))
260
246
            {
 
247
                count = 60;
 
248
            }
 
249
            else
 
250
            {
261
251
                count = 20;
262
252
            }
263
 
            else
264
 
            {
265
 
                count = 60;
266
 
            }
267
 
            
 
253
 
268
254
            int adapterCount = adapters.length;
269
255
            while(--count > 0)
270
256
            {
302
288
                    }
303
289
                    proxies[i] = createTestIntfPrx(java.util.Arrays.asList((adpts)));
304
290
                }
305
 
            
306
 
                for(i = 0; i < proxies.length; i++)
 
291
 
 
292
                for(TestIntfPrx p : proxies)
307
293
                {
308
 
                    proxies[i].getAdapterName_async(new NoOpGetAdapterNameCB());
 
294
                    p.begin_getAdapterName();
309
295
                }
310
 
                for(i = 0; i < proxies.length; i++)
 
296
                for(TestIntfPrx p : proxies)
311
297
                {
312
298
                    try
313
299
                    {
314
 
                        proxies[i].ice_ping();
 
300
                        p.ice_ping();
315
301
                    }
316
302
                    catch(Ice.LocalException ex)
317
303
                    {
319
305
                }
320
306
 
321
307
                java.util.Set<Ice.Connection> connections = new java.util.HashSet<Ice.Connection>();
322
 
                for(i = 0; i < proxies.length; i++)
 
308
                for(TestIntfPrx p : proxies)
323
309
                {
324
 
                    if(proxies[i].ice_getCachedConnection() != null)
 
310
                    if(p.ice_getCachedConnection() != null)
325
311
                    {
326
 
                        connections.add(proxies[i].ice_getCachedConnection());
 
312
                        connections.add(p.ice_getCachedConnection());
327
313
                    }
328
314
                }
329
315
                test(connections.size() <= adapterCount);
341
327
                }
342
328
            }
343
329
        }
344
 
        System.out.println("ok");
 
330
        out.println("ok");
345
331
 
346
 
        System.out.print("testing binding with multiple endpoints and AMI... ");
347
 
        System.out.flush();
 
332
        out.print("testing binding with multiple endpoints and AMI... ");
 
333
        out.flush();
348
334
        {
349
335
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
350
336
            adapters.add(com.createObjectAdapter("AdapterAMI11", "default"));
382
368
            // always send the request over the same connection.)
383
369
            //
384
370
            {
385
 
                java.util.Iterator<RemoteObjectAdapterPrx> p = adapters.iterator();
386
 
                while(p.hasNext())
 
371
                for(RemoteObjectAdapterPrx p : adapters)
387
372
                {
388
 
                    p.next().getTestIntf().ice_ping();
 
373
                    p.getTestIntf().ice_ping();
389
374
                }
390
375
 
391
376
                TestIntfPrx test = createTestIntfPrx(adapters);
395
380
                for(i = 0; i < nRetry &&  getAdapterNameWithAMI(test).equals(name); i++);
396
381
                test(i == nRetry);
397
382
 
398
 
                p = adapters.iterator();
399
 
                while(p.hasNext())
 
383
                for(RemoteObjectAdapterPrx p : adapters)
400
384
                {
401
 
                    p.next().getTestIntf().ice_getConnection().close(false);
 
385
                    p.getTestIntf().ice_getConnection().close(false);
402
386
                }
403
387
            }
404
388
 
437
421
 
438
422
            deactivate(com, adapters);
439
423
        }
440
 
        System.out.println("ok");
 
424
        out.println("ok");
441
425
 
442
 
        System.out.print("testing random endpoint selection... ");
443
 
        System.out.flush();
 
426
        out.print("testing random endpoint selection... ");
 
427
        out.flush();
444
428
        {
445
429
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
446
430
            adapters.add(com.createObjectAdapter("Adapter21", "default"));
474
458
 
475
459
            deactivate(com, adapters);
476
460
        }
477
 
        System.out.println("ok");
 
461
        out.println("ok");
478
462
 
479
 
        System.out.print("testing ordered endpoint selection... ");
480
 
        System.out.flush();
 
463
        out.print("testing ordered endpoint selection... ");
 
464
        out.flush();
481
465
        {
482
466
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
483
467
            adapters.add(com.createObjectAdapter("Adapter31", "default"));
508
492
            {
509
493
                test.getAdapterName();
510
494
            }
511
 
            catch(Ice.ConnectionRefusedException ex)
 
495
            catch(Ice.ConnectFailedException ex)
512
496
            {
 
497
                //
 
498
                // Usually the actual type of this exception is ConnectionRefusedException,
 
499
                // but not always. See bug 3179.
 
500
                //
513
501
            }
514
502
 
515
503
            Ice.Endpoint[] endpoints = test.ice_getEndpoints();
534
522
 
535
523
            deactivate(com, adapters);
536
524
        }
537
 
        System.out.println("ok");
 
525
        out.println("ok");
538
526
 
539
 
        System.out.print("testing per request binding with single endpoint... ");
540
 
        System.out.flush();
 
527
        out.print("testing per request binding with single endpoint... ");
 
528
        out.flush();
541
529
        {
542
530
            RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter41", "default");
543
531
 
557
545
                test(test3.ice_getConnection() == test1.ice_getConnection());
558
546
                test(false);
559
547
            }
560
 
            catch(Ice.ConnectionRefusedException ex)
 
548
            catch(Ice.ConnectFailedException ex)
561
549
            {
 
550
                //
 
551
                // Usually the actual type of this exception is ConnectionRefusedException,
 
552
                // but not always. See bug 3179.
 
553
                //
562
554
            }
563
555
        }
564
 
        System.out.println("ok");
 
556
        out.println("ok");
565
557
 
566
 
        System.out.print("testing per request binding with multiple endpoints... ");
567
 
        System.out.flush();
 
558
        out.print("testing per request binding with multiple endpoints... ");
 
559
        out.flush();
568
560
        {
569
561
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
570
562
            adapters.add(com.createObjectAdapter("Adapter51", "default"));
598
590
 
599
591
            deactivate(com, adapters);
600
592
        }
601
 
        System.out.println("ok");
 
593
        out.println("ok");
602
594
 
603
 
        System.out.print("testing per request binding with multiple endpoints and AMI... ");
604
 
        System.out.flush();
 
595
        out.print("testing per request binding with multiple endpoints and AMI... ");
 
596
        out.flush();
605
597
        {
606
598
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
607
599
            adapters.add(com.createObjectAdapter("AdapterAMI51", "default"));
635
627
 
636
628
            deactivate(com, adapters);
637
629
        }
638
 
        System.out.println("ok");
 
630
        out.println("ok");
639
631
 
640
 
        System.out.print("testing per request binding and ordered endpoint selection... ");
641
 
        System.out.flush();
 
632
        out.print("testing per request binding and ordered endpoint selection... ");
 
633
        out.flush();
642
634
        {
643
635
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
644
636
            adapters.add(com.createObjectAdapter("Adapter61", "default"));
671
663
            {
672
664
                test.getAdapterName();
673
665
            }
674
 
            catch(Ice.ConnectionRefusedException ex)
 
666
            catch(Ice.ConnectFailedException ex)
675
667
            {
 
668
                //
 
669
                // Usually the actual type of this exception is ConnectionRefusedException,
 
670
                // but not always. See bug 3179.
 
671
                //
676
672
            }
677
673
 
678
674
            Ice.Endpoint[] endpoints = test.ice_getEndpoints();
695
691
 
696
692
            deactivate(com, adapters);
697
693
        }
698
 
        System.out.println("ok");
 
694
        out.println("ok");
699
695
 
700
 
        System.out.print("testing per request binding and ordered endpoint selection and AMI... ");
701
 
        System.out.flush();
 
696
        out.print("testing per request binding and ordered endpoint selection and AMI... ");
 
697
        out.flush();
702
698
        {
703
699
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
704
700
            adapters.add(com.createObjectAdapter("AdapterAMI61", "default"));
731
727
            {
732
728
                test.getAdapterName();
733
729
            }
734
 
            catch(Ice.ConnectionRefusedException ex)
 
730
            catch(Ice.ConnectFailedException ex)
735
731
            {
 
732
                //
 
733
                // Usually the actual type of this exception is ConnectionRefusedException,
 
734
                // but not always. See bug 3179.
 
735
                //
736
736
            }
737
737
 
738
738
            Ice.Endpoint[] endpoints = test.ice_getEndpoints();
755
755
 
756
756
            deactivate(com, adapters);
757
757
        }
758
 
        System.out.println("ok");
 
758
        out.println("ok");
759
759
 
760
 
        System.out.print("testing endpoint mode filtering... ");
761
 
        System.out.flush();
 
760
        out.print("testing endpoint mode filtering... ");
 
761
        out.flush();
762
762
        {
763
763
            java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
764
764
            adapters.add(com.createObjectAdapter("Adapter71", "default"));
777
777
            {
778
778
            }
779
779
        }
780
 
        System.out.println("ok");
 
780
        out.println("ok");
781
781
 
782
782
        if(communicator.getProperties().getProperty("Ice.Plugin.IceSSL").length() > 0)
783
783
        {
784
 
            System.out.print("testing unsecure vs. secure endpoints... ");
785
 
            System.out.flush();
 
784
            out.print("testing unsecure vs. secure endpoints... ");
 
785
            out.flush();
786
786
            {
787
787
                java.util.List<RemoteObjectAdapterPrx> adapters = new java.util.ArrayList<RemoteObjectAdapterPrx>();
788
788
                adapters.add(com.createObjectAdapter("Adapter81", "ssl"));
826
826
                    testSecure.ice_ping();
827
827
                    test(false);
828
828
                }
829
 
                catch(Ice.ConnectionRefusedException ex)
 
829
                catch(Ice.ConnectFailedException ex)
830
830
                {
 
831
                    //
 
832
                    // Usually the actual type of this exception is ConnectionRefusedException,
 
833
                    // but not always. See bug 3179.
 
834
                    //
831
835
                }
832
836
 
833
837
                deactivate(com, adapters);
834
838
            }
835
 
            System.out.println("ok");
 
839
            out.println("ok");
836
840
        }
837
841
 
838
842
        com.shutdown();