1 22 package org.jboss.test.cluster.partition.test; 23 24 import java.util.Vector ; 25 26 import javax.management.ObjectName ; 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 42 public class HAPartitionStateTransferTestCase extends JBossClusteredTestCase 43 { 44 45 public HAPartitionStateTransferTestCase(String name) 46 { 47 super(name); 48 } 49 50 public static Test suite() throws Exception 51 { 52 Test t1 = JBossClusteredTestCase.getDeploySetup(HAPartitionStateTransferTestCase.class, "partitionstatetransfer.sar"); 53 return t1; 54 } 55 56 protected void setUp() throws Exception 57 { 58 super.setUp(); 59 } 60 61 protected void tearDown() throws Exception 62 { 63 super.tearDown(); 64 } 65 66 public void testFailedStateProvider() throws Exception 67 { 68 RMIAdaptor[] adaptors = getAdaptors(); 69 70 ObjectName recorder = new ObjectName ("jboss:service=BadProviderPartitionRecorder"); 71 72 Exception e = (Exception ) adaptors[1].getAttribute(recorder, "StartupException"); 73 74 assertNotNull("Partition caught exception", e); 75 76 Throwable parent = e; 77 Throwable 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 ); 85 86 ObjectName partition = new ObjectName ("jboss:service=BadProviderPartition"); 88 Vector view = (Vector ) adaptors[0].getAttribute(partition, "CurrentView"); 89 assertEquals("View size after failure is correct", 1, view.size()); 90 } 91 92 public void testBadStateIntegration() throws Exception 93 { 94 RMIAdaptor[] adaptors = getAdaptors(); 95 96 ObjectName recorder = new ObjectName ("jboss:service=BadStatePartitionRecorder"); 97 98 Exception e = (Exception ) adaptors[1].getAttribute(recorder, "StartupException"); 99 100 assertNotNull("Partition caught exception", e); 101 102 Throwable parent = e; 103 Throwable 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 ObjectName partition = new ObjectName ("jboss:service=BadStatePartition"); 114 Vector view = (Vector ) adaptors[0].getAttribute(partition, "CurrentView"); 115 assertEquals("View size after failure is correct", 1, view.size()); 116 } 117 118 public void testNoStateTransfer() throws Exception 119 { 120 RMIAdaptor[] adaptors = getAdaptors(); 121 122 ObjectName partition = new ObjectName ("jboss:service=NoStatePartitionRecorder"); 123 124 Exception e = (Exception ) adaptors[1].getAttribute(partition, "StartupException"); 125 126 assertNull("Partition started successfully", e); 127 128 } 129 130 public void testGoodStateTransfer() throws Exception 131 { 132 RMIAdaptor[] adaptors = getAdaptors(); 133 134 ObjectName partition = new ObjectName ("jboss:service=GoodStatePartitionRecorder"); 135 136 Exception e = (Exception ) adaptors[1].getAttribute(partition, "StartupException"); 137 138 assertNull("Partition started successfully", e); 139 140 ObjectName simple = new ObjectName ("jboss.test:service=SimpleHAPartitionStateTransfer"); 141 142 Object simpleState = adaptors[1].getAttribute(simple, "TransferredState"); 143 144 assertEquals("Got simple state", SimpleHAPartitionStateTransfer.SIMPLE, simpleState); 145 146 ObjectName custom = new ObjectName ("jboss.test:service=CustomStateHAPartitionStateTransfer"); 147 148 Object 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 158 public void testServerFound() throws Exception 159 { 160 } 162 163 164 } 165 | Popular Tags |