KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > connection > ClientConnectionTimeoutTest


1 package org.jacorb.test.orb.connection;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2001 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import junit.framework.*;
24 import junit.extensions.*;
25
26 import org.jacorb.test.common.*;
27 import org.jacorb.test.*;
28 import org.omg.CORBA.*;
29 import org.jacorb.orb.iiop.ClientIIOPConnection;
30
31 import java.util.*;
32
33 public class ClientConnectionTimeoutTest extends ClientServerTestCase
34 {
35     private TestIf server;
36
37     public ClientConnectionTimeoutTest(String JavaDoc name, ClientServerSetup setup)
38     {
39         super(name, setup);
40     }
41
42     public void setUp() throws Exception JavaDoc
43     {
44         server = TestIfHelper.narrow( setup.getServerObject() );
45     }
46
47     public static Test suite()
48     {
49         TestSuite suite = new TestSuite( "Client connection idle-timeout tests" );
50
51         Properties client_props = new Properties();
52         client_props.setProperty( "jacorb.connection.client.idle_timeout", "1000" );
53
54         ClientServerSetup setup =
55             new ClientServerSetup( suite,
56                                    "org.jacorb.test.orb.connection.ConnectionTimeoutServerImpl",
57                                    client_props,
58                                    null );
59
60         suite.addTest( new ClientConnectionTimeoutTest( "testTimeout", setup ));
61
62         return setup;
63     }
64
65     public void testTimeout()
66     {
67
68         //call remote op with reply
69
server.op();
70
71         try
72         {
73             //wait 2 secs
74
Thread.sleep( 2000 );
75         }
76         catch( Exception JavaDoc e ){ e.printStackTrace(); }
77
78         //all transports must be down by now
79
//NOTE: if this doesn't compile, please check if
80
//openTransports is uncommented in ClientIIOPConnection
81
assertTrue( ClientIIOPConnection.openTransports == 0 );
82
83         //call oneway remote op
84
server.onewayOp();
85
86         try
87         {
88             //wait 2 secs
89
Thread.sleep( 2000 );
90         }
91         catch( Exception JavaDoc e ){ e.printStackTrace(); }
92
93         //all transports must be down by now
94
//NOTE: if this doesn't compile, please check if
95
//openTransports is uncommented in ClientIIOPConnection
96
assertTrue( ClientIIOPConnection.openTransports == 0 );
97     }
98 }
99
Popular Tags