KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > invoker > ClientInvokerDisconnectTestCase


1 /**
2  * JBoss, the OpenSource J2EE WebOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.invoker;
8
9 import org.jboss.logging.Logger;
10 import org.jboss.remoting.Client;
11 import org.jboss.remoting.InvokerLocator;
12 import org.jboss.remoting.InvokerRegistry;
13 import org.jboss.remoting.RemoteClientInvoker;
14 import org.jboss.remoting.transport.ClientInvoker;
15 import org.jboss.remoting.transport.Connector;
16 import org.jboss.remoting.transport.local.LocalClientInvoker;
17
18 import junit.framework.TestCase;
19
20 /**
21  * @author <a HREF="mailto:ovidiu@jboss.org">Ovidiu Feodorov</a>
22  *
23  * @version <tt>$Revision: 1.2 $</tt>
24  *
25  * $Id: ClientInvokerDisconnectTestCase.java,v 1.2 2005/06/20 03:38:43 telrod Exp $
26  */

27 public class ClientInvokerDisconnectTestCase extends TestCase
28 {
29    // Constants -----------------------------------------------------
30

31    private static final Logger log = Logger.getLogger(ClientInvokerDisconnectTestCase.class);
32
33    // Static --------------------------------------------------------
34

35    // Attributes ----------------------------------------------------
36

37    private String JavaDoc serverURI = "socket://127.0.0.1:5555/";
38    private Connector server;
39
40    // Constructors --------------------------------------------------
41

42    public ClientInvokerDisconnectTestCase(String JavaDoc name)
43    {
44       super(name);
45    }
46
47    // Public --------------------------------------------------------
48

49    public void setUp() throws Exception JavaDoc
50    {
51       super.setUp();
52
53       server = new Connector();
54       server.setInvokerLocator(serverURI);
55       server.start();
56       log.info("Server " + serverURI + " started");
57    }
58
59    public void tearDown() throws Exception JavaDoc
60    {
61       server.stop();
62       server = null;
63       log.info("Server " + serverURI + " stopped");
64
65       super.tearDown();
66    }
67
68    public void testLocalClientInvokerDisconnect() throws Throwable JavaDoc
69    {
70       Client client = new Client(new InvokerLocator(serverURI));
71
72       ClientInvoker[] clientInvokers = InvokerRegistry.getClientInvokers();
73       assertEquals(1, clientInvokers.length);
74
75       LocalClientInvoker clientInvoker = (LocalClientInvoker)clientInvokers[0];
76       assertEquals(serverURI, clientInvoker.getLocator().getLocatorURI());
77
78
79       client.disconnect();
80
81
82       clientInvokers = InvokerRegistry.getClientInvokers();
83       assertEquals(0, clientInvokers.length);
84    }
85
86    public void testRemoteClientInvokerDisconnect() throws Throwable JavaDoc
87    {
88       String JavaDoc passByValueServerURI = serverURI + "?byvalue=true";
89       Client client = new Client(new InvokerLocator(passByValueServerURI));
90
91       ClientInvoker[] clientInvokers = InvokerRegistry.getClientInvokers();
92       assertEquals(1, clientInvokers.length);
93
94       RemoteClientInvoker clientInvoker = (RemoteClientInvoker)clientInvokers[0];
95       assertEquals(passByValueServerURI, clientInvoker.getLocator().getLocatorURI());
96
97
98       client.disconnect();
99
100
101       clientInvokers = InvokerRegistry.getClientInvokers();
102       assertEquals(0, clientInvokers.length);
103    }
104
105
106    // Package protected ---------------------------------------------
107

108    // Protected -----------------------------------------------------
109

110    // Private -------------------------------------------------------
111

112    // Inner classes -------------------------------------------------
113

114 }
115
Popular Tags