1 22 package org.jboss.test.ha.singleton.test; 23 24 import java.util.ArrayList ; 25 26 import junit.framework.TestCase; 27 28 import org.jboss.test.ha.singleton.HASingletonSupportTester; 29 30 31 public class HASingletonSupportUnitTestCase extends TestCase 32 { 33 34 private HASingletonSupportTester singletonSupportTester = null; 35 36 public HASingletonSupportUnitTestCase(String testCaseName) 37 { 38 super(testCaseName); 39 } 40 41 42 public void setUp() 43 { 44 singletonSupportTester = new HASingletonSupportTester(); 45 } 46 47 public void tearDown() 48 { 49 singletonSupportTester = null; 50 } 51 52 public void testStartService() throws Exception 53 { 54 singletonSupportTester.start(); 55 56 assertEquals("method not invoked as expected", 58 singletonSupportTester.__invokationStack__.pop(), "registerDRMListener"); 59 assertEquals("method not invoked as expected", 60 singletonSupportTester.__invokationStack__.pop(), "registerRPCHandler"); 61 assertEquals("method not invoked as expected", 62 singletonSupportTester.__invokationStack__.pop(), "setupPartition"); 63 64 } 65 66 public void testStopService() throws Exception 67 { 68 singletonSupportTester.start(); 69 singletonSupportTester.stop(); 70 71 assertEquals("method not invoked as expected", 72 singletonSupportTester.__invokationStack__.pop(), "unregisterRPCHandler"); 73 assertEquals("method not invoked as expected", 74 singletonSupportTester.__invokationStack__.pop(), "unregisterDRMListener"); 75 76 } 77 78 public void testBecomeMasterNode() throws Exception 79 { 80 singletonSupportTester.start(); 81 82 singletonSupportTester.__isDRMMasterReplica__ = true; 84 singletonSupportTester.partitionTopologyChanged( new ArrayList (2), 1); 85 86 assertTrue("expected to become master", singletonSupportTester.isMasterNode()); 88 89 assertEquals("method not invoked as expected", 91 singletonSupportTester.__invokationStack__.pop(), "startSingleton"); 92 assertEquals("method not invoked as expected", 95 singletonSupportTester.__invokationStack__.pop(), "makeThisNodeMaster"); 96 } 97 98 public void testBecomeSlaveNodeWithAnotherMaster() throws Exception 99 { 100 singletonSupportTester.start(); 101 102 boolean savedIsMasterNode = singletonSupportTester.isMasterNode(); 103 104 singletonSupportTester.__isDRMMasterReplica__ = false; 106 singletonSupportTester.partitionTopologyChanged(new ArrayList (2), 1); 107 108 assertEquals("expected to be still in old master/slave state", singletonSupportTester.isMasterNode(), savedIsMasterNode ); 110 111 singletonSupportTester._stopOldMaster(); 113 114 if (savedIsMasterNode) 115 { 116 assertEquals("this node was the old master, but method not invoked as expected", 117 singletonSupportTester.__invokationStack__.pop(), "stopSingleton"); 118 } 119 120 assertTrue("expected to be slave", !singletonSupportTester.isMasterNode()); 122 123 } 124 125 public void testStopOnlyNode() throws Exception 126 { 127 singletonSupportTester.start(); 128 129 singletonSupportTester.__isDRMMasterReplica__ = true; 131 singletonSupportTester.partitionTopologyChanged( new ArrayList (2), 1); 132 133 assertTrue("expected to become master", singletonSupportTester.isMasterNode()); 135 136 singletonSupportTester.stop(); 137 138 singletonSupportTester.__isDRMMasterReplica__ = false; 140 singletonSupportTester.partitionTopologyChanged(new ArrayList (0), 1); 142 143 assertTrue("expected to have made a call to _stopOldMater(), thus become slave", !singletonSupportTester.isMasterNode() ); 144 145 assertEquals("method not invoked as expected", 146 singletonSupportTester.__invokationStack__.pop(), "stopSingleton"); 147 148 } 149 150 } 151 | Popular Tags |