1 22 23 package org.jboss.test.ha.jmx.test; 24 25 import java.util.EmptyStackException ; 26 27 import javax.management.AttributeChangeNotification ; 28 import javax.management.Notification ; 29 30 import junit.framework.TestCase; 31 32 import org.jboss.test.ha.jmx.HAServiceMBeanSupportTester; 33 34 39 public class HAServiceMBeanSupportUnitTestCase extends TestCase 40 { 41 42 private HAServiceMBeanSupportTester haServiceMBeanSupportTester_ = null; 43 44 public HAServiceMBeanSupportUnitTestCase(String name) 45 { 46 super(name); 47 } 48 49 public void setUp() 50 { 51 haServiceMBeanSupportTester_ = new HAServiceMBeanSupportTester(); 52 } 53 54 55 public void tearDown() 56 { 57 haServiceMBeanSupportTester_ = null; 58 } 59 60 61 66 public void testSendNotificationBroadcastsToClusterAndLocally() 67 { 68 Notification notification = new Notification ("test.notification", "some:name=tester", 1); 69 haServiceMBeanSupportTester_.sendNotification( notification ); 70 71 assertEquals("sendNotificationToLocalListeners() was not handed the original notification", 72 haServiceMBeanSupportTester_.__invokationStack__.pop(), notification ); 73 74 assertEquals("method not invoked as expected", 75 haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners"); 76 77 assertEquals("sendNotificationRemote() was not handed the original notification", 78 haServiceMBeanSupportTester_.__invokationStack__.pop(), notification ); 79 80 assertEquals("method not invoked as expected", 81 haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationRemote"); 82 } 83 84 90 public void testSendNotificationAfterClusterFailureContinueWithLocal() 91 { 92 haServiceMBeanSupportTester_.__shouldSendNotificationRemoteFail__ = true; 93 94 Notification notification = new Notification ("test.notification", "some:name=tester", 1); 95 haServiceMBeanSupportTester_.sendNotification( notification ); 96 97 assertEquals("sendNotificationToLocalListeners() was not handed the original notification", 98 haServiceMBeanSupportTester_.__invokationStack__.pop(), notification ); 99 100 assertEquals("method not invoked as expected", 101 haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners"); 102 } 103 104 public void testSendLifecycleNotifications() 105 { 106 Notification notification = new AttributeChangeNotification ( 107 haServiceMBeanSupportTester_, 108 1, System.currentTimeMillis(), "test", 109 "State", "java.lang.Integer", 110 new Integer (0), new Integer (1) 111 ); 112 113 haServiceMBeanSupportTester_.setSendRemoteLifecycleNotifications(false); 114 115 haServiceMBeanSupportTester_.sendNotification( notification ); 116 117 assertEquals("sendNotificationToLocalListeners() was handed the original notification", 118 haServiceMBeanSupportTester_.__invokationStack__.pop(), notification ); 119 120 assertEquals("method invoked as expected", 121 haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners"); 122 123 try 124 { 125 haServiceMBeanSupportTester_.__invokationStack__.pop(); 126 fail("sendNotificationRemote() was not handed the original notification"); 127 } 128 catch (EmptyStackException good) {} 129 130 haServiceMBeanSupportTester_.setSendRemoteLifecycleNotifications(true); 131 haServiceMBeanSupportTester_.setSendLocalLifecycleNotifications(false); 132 133 haServiceMBeanSupportTester_.sendNotification( notification ); 134 135 assertEquals("sendNotificationRemote() was handed the original notification", 136 haServiceMBeanSupportTester_.__invokationStack__.pop(), notification ); 137 138 assertEquals("method invoked as expected", 139 haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationRemote"); 140 141 try 142 { 143 haServiceMBeanSupportTester_.__invokationStack__.pop(); 144 fail("sendNotificationToLocalListeners() was not handed the original notification"); 145 } 146 catch (EmptyStackException good) {} 147 } 148 149 } 150 | Popular Tags |