KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > test > HASingletonElectionPolicyTestCase


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.test;
23
24 import javax.management.ObjectName JavaDoc;
25
26 import junit.framework.Test;
27
28 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
29 import org.jboss.test.JBossClusteredTestCase;
30
31 /**
32  * Unit tests for HASingletonElectionPolicy.
33  * The testing deployment is under resources/ha/electionpolicy.
34  *
35  * @author <a HREF="mailto:Alex.Fu@novell.com">Alex Fu</a>
36  * @version $Revision: 58536 $
37  *
38  */

39 public class HASingletonElectionPolicyTestCase extends JBossClusteredTestCase
40 {
41    public HASingletonElectionPolicyTestCase(String JavaDoc name)
42    {
43       super(name);
44    }
45    
46    public static Test suite() throws Exception JavaDoc
47    {
48       // Refer to jboss-service.xml under resources/ha/electionpolicy
49
Test t1 = JBossClusteredTestCase.getDeploySetup(HASingletonElectionPolicyTestCase.class, "ha-electionpolicy.sar");
50       return t1;
51    }
52    
53    public void testElectionPolicy() throws Exception JavaDoc
54    {
55       // Get MBeanServerConnections
56
RMIAdaptor[] adaptors = this.getAdaptors();
57       int size = adaptors.length;
58       assertTrue(size > 1); // cluster size must be at least 2
59

60       // First policy is to elect the oldest node (position = 0)
61
{
62          ObjectName JavaDoc mbean = new ObjectName JavaDoc("jboss.examples:service=HASingletonMBeanExample_1");
63          
64          Boolean JavaDoc n1 = (Boolean JavaDoc)adaptors[0].getAttribute(mbean, "MasterNode");
65          Boolean JavaDoc n2 = (Boolean JavaDoc)adaptors[size - 1].getAttribute(mbean, "MasterNode");
66          
67          assertEquals(Boolean.TRUE, n1);
68          assertEquals(Boolean.FALSE, n2);
69       }
70       // Second policy is the youngest (position = -1)
71
{
72          ObjectName JavaDoc mbean = new ObjectName JavaDoc("jboss.examples:service=HASingletonMBeanExample_2");
73          
74          Boolean JavaDoc n1 = (Boolean JavaDoc)adaptors[0].getAttribute(mbean, "MasterNode");
75          Boolean JavaDoc n2 = (Boolean JavaDoc)adaptors[size - 1].getAttribute(mbean, "MasterNode");
76          
77          assertEquals(Boolean.FALSE, n1);
78          assertEquals(Boolean.TRUE, n2);
79       }
80       // 3rd policy is the 2nd oldest (position = 1)
81
{
82          ObjectName JavaDoc mbean = new ObjectName JavaDoc("jboss.examples:service=HASingletonMBeanExample_3");
83          
84          Boolean JavaDoc n1 = (Boolean JavaDoc)adaptors[0].getAttribute(mbean, "MasterNode");
85          Boolean JavaDoc n2 = (Boolean JavaDoc)adaptors[1].getAttribute(mbean, "MasterNode");
86          
87          assertEquals(Boolean.FALSE, n1);
88          assertEquals(Boolean.TRUE, n2);
89       }
90       // 4th policy is not set, default is oldest
91
{
92          ObjectName JavaDoc mbean = new ObjectName JavaDoc("jboss.examples:service=HASingletonMBeanExample_4");
93          
94          Boolean JavaDoc n1 = (Boolean JavaDoc)adaptors[0].getAttribute(mbean, "MasterNode");
95          Boolean JavaDoc n2 = (Boolean JavaDoc)adaptors[size - 1].getAttribute(mbean, "MasterNode");
96          
97          assertEquals(Boolean.TRUE, n1);
98          assertEquals(Boolean.FALSE, n2);
99       }
100       
101       return;
102    }
103 }
104
Popular Tags