KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > jmx > test > HAInvokerUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cluster.jmx.test;
23
24 import org.jboss.invocation.ServiceUnavailableException;
25 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
26 import org.jboss.test.JBossClusteredTestCase;
27 import org.jboss.test.jmx.ha.HAServiceRemote;
28
29 import junit.framework.Test;
30
31 /**
32  * Tests for ha invoker.
33  *
34  * @author <a HREF="mailto:brian.stansberry@jboss.com">Brian Stansberry</a>
35  * @version $Revision$
36  */

37 public class HAInvokerUnitTestCase
38    extends JBossClusteredTestCase
39 {
40    private boolean deployed0_ = true;
41    private boolean deployed1_ = true;
42    
43    public HAInvokerUnitTestCase(String JavaDoc name)
44    {
45       super(name);
46    }
47
48    public static Test suite()
49       throws Exception JavaDoc
50    {
51       return JBossClusteredTestCase.getDeploySetup(HAInvokerUnitTestCase.class, "ha-invoker.sar");
52    }
53
54    public void testHAProxyFailover()
55       throws Exception JavaDoc
56    {
57       getLog().debug("testHAProxyFailover");
58       
59       HAServiceRemote remote = (HAServiceRemote) getInitialContext().lookup("jmx/HAService");
60       assertEquals("Hello", remote.hello());
61       String JavaDoc nodeA = remote.getClusterNode();
62       assertNotNull("Got clusterNode", nodeA);
63       // Invoke again to check it works with load balancing
64
assertFalse("Requests load balanced", nodeA.equals(remote.getClusterNode()));
65       
66       // Undeploy from one node
67
reconfigureCluster();
68       
69       // Check it still works
70
try
71       {
72          assertEquals("Hello", remote.hello());
73       }
74       catch (ServiceUnavailableException sue)
75       {
76          fail("Known issue JBAS-3194: " + sue.getMessage());
77       }
78    }
79    
80    protected void setUp() throws Exception JavaDoc
81    {
82       super.setUp();
83       configureCluster();
84    }
85
86    protected String JavaDoc getDeploymentName()
87    {
88       return "ha-invoker.sar";
89    }
90
91    protected void configureCluster() throws Exception JavaDoc
92    {
93       RMIAdaptor[] adaptors = getAdaptors();
94       String JavaDoc warName = getDeploymentName();
95       if (!deployed0_)
96       {
97          deploy(adaptors[0], warName);
98          getLog().debug("Deployed " + warName + " on server0");
99          deployed0_ = true;
100       }
101       if (!deployed1_)
102       {
103          deploy(adaptors[1], warName);
104          getLog().debug("Deployed " + warName + " on server1");
105          deployed1_ = true;
106       }
107    
108       sleep(2000);
109    }
110    
111    protected void reconfigureCluster() throws Exception JavaDoc
112    {
113       RMIAdaptor[] adaptors = getAdaptors();
114       if (!deployed1_)
115       {
116          deploy(adaptors[1], getDeploymentName());
117          deployed1_ = true;
118          
119          sleep(2000);
120       }
121       
122       if (deployed0_)
123       {
124          undeploy(adaptors[0], getDeploymentName());
125          deployed0_ = false;
126          
127          sleep(2000);
128       }
129    }
130
131 }
132
Popular Tags