KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > partition > test > HAPartitionStateTransferTestCase


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.partition.test;
23
24 import java.util.Vector JavaDoc;
25
26 import javax.management.ObjectName JavaDoc;
27
28 import junit.framework.Test;
29
30 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
31 import org.jboss.test.JBossClusteredTestCase;
32 import org.jboss.test.cluster.partition.BadHAPartitionStateException;
33 import org.jboss.test.cluster.partition.CustomStateHAPartitionStateTransfer;
34 import org.jboss.test.cluster.partition.SimpleHAPartitionStateTransfer;
35
36 /**
37  * Tests of HAPartitionImpl's state transfer.
38  *
39  * @author <a HREF="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
40  * @version $Revision$
41  */

42 public class HAPartitionStateTransferTestCase extends JBossClusteredTestCase
43 {
44
45    public HAPartitionStateTransferTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    public static Test suite() throws Exception JavaDoc
51    {
52       Test t1 = JBossClusteredTestCase.getDeploySetup(HAPartitionStateTransferTestCase.class, "partitionstatetransfer.sar");
53       return t1;
54    }
55
56    protected void setUp() throws Exception JavaDoc
57    {
58       super.setUp();
59    }
60
61    protected void tearDown() throws Exception JavaDoc
62    {
63       super.tearDown();
64    }
65    
66    public void testFailedStateProvider() throws Exception JavaDoc
67    {
68       RMIAdaptor[] adaptors = getAdaptors();
69       
70       ObjectName JavaDoc recorder = new ObjectName JavaDoc("jboss:service=BadProviderPartitionRecorder");
71       
72       Exception JavaDoc e = (Exception JavaDoc) adaptors[1].getAttribute(recorder, "StartupException");
73
74       assertNotNull("Partition caught exception", e);
75       
76       Throwable JavaDoc parent = e;
77       Throwable JavaDoc cause = e.getCause();
78       while (cause != null)
79       {
80          parent = cause;
81          cause = parent.getCause();
82       }
83       
84       assertTrue("Correct type of Exception caught", parent instanceof IllegalStateException JavaDoc);
85       
86       // Confirm the bad partition is removed from the current view
87
ObjectName JavaDoc partition = new ObjectName JavaDoc("jboss:service=BadProviderPartition");
88       Vector JavaDoc view = (Vector JavaDoc) adaptors[0].getAttribute(partition, "CurrentView");
89       assertEquals("View size after failure is correct", 1, view.size());
90    }
91
92    public void testBadStateIntegration() throws Exception JavaDoc
93    {
94       RMIAdaptor[] adaptors = getAdaptors();
95       
96       ObjectName JavaDoc recorder = new ObjectName JavaDoc("jboss:service=BadStatePartitionRecorder");
97       
98       Exception JavaDoc e = (Exception JavaDoc) adaptors[1].getAttribute(recorder, "StartupException");
99
100       assertNotNull("Partition caught exception", e);
101       
102       Throwable JavaDoc parent = e;
103       Throwable JavaDoc cause = e.getCause();
104       while (cause != null)
105       {
106          parent = cause;
107          cause = parent.getCause();
108       }
109       
110       assertTrue("Correct type of Exception caught", parent instanceof BadHAPartitionStateException);
111       
112       // Confirm the bad partition is removed from the current view
113
ObjectName JavaDoc partition = new ObjectName JavaDoc("jboss:service=BadStatePartition");
114       Vector JavaDoc view = (Vector JavaDoc) adaptors[0].getAttribute(partition, "CurrentView");
115       assertEquals("View size after failure is correct", 1, view.size());
116    }
117    
118    public void testNoStateTransfer() throws Exception JavaDoc
119    {
120       RMIAdaptor[] adaptors = getAdaptors();
121       
122       ObjectName JavaDoc partition = new ObjectName JavaDoc("jboss:service=NoStatePartitionRecorder");
123       
124       Exception JavaDoc e = (Exception JavaDoc) adaptors[1].getAttribute(partition, "StartupException");
125
126       assertNull("Partition started successfully", e);
127       
128    }
129    
130    public void testGoodStateTransfer() throws Exception JavaDoc
131    {
132       RMIAdaptor[] adaptors = getAdaptors();
133       
134       ObjectName JavaDoc partition = new ObjectName JavaDoc("jboss:service=GoodStatePartitionRecorder");
135       
136       Exception JavaDoc e = (Exception JavaDoc) adaptors[1].getAttribute(partition, "StartupException");
137
138       assertNull("Partition started successfully", e);
139       
140       ObjectName JavaDoc simple = new ObjectName JavaDoc("jboss.test:service=SimpleHAPartitionStateTransfer");
141       
142       Object JavaDoc simpleState = adaptors[1].getAttribute(simple, "TransferredState");
143       
144       assertEquals("Got simple state", SimpleHAPartitionStateTransfer.SIMPLE, simpleState);
145       
146       ObjectName JavaDoc custom = new ObjectName JavaDoc("jboss.test:service=CustomStateHAPartitionStateTransfer");
147       
148       Object JavaDoc customState = adaptors[1].getAttribute(custom, "TransferredState");
149       
150       assertNotNull("Got custom state", customState);
151       assertEquals("Got correct custom state", CustomStateHAPartitionStateTransfer.CUSTOM, customState.toString());
152    }
153
154    /**
155     * In this subclass this is a no-op because we are deliberately
156     * deploying a sar that will fail in deployment
157     */

158    public void testServerFound() throws Exception JavaDoc
159    {
160       // do nothing
161
}
162    
163    
164 }
165
Popular Tags