[jboss-svn-commits] JBL Code SVN: r33069 - in labs/jbosstm/trunk: ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/tools and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue May 25 06:13:08 EDT 2010


Author: mmusgrov
Date: 2010-05-25 06:13:07 -0400 (Tue, 25 May 2010)
New Revision: 33069

Modified:
   labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/tools/ObjStoreBrowserTest.java
   labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/tools/ObjStoreBrowserTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/tools/JTSObjStoreBrowserTest.java
Log:
[JBTM-716] Use the RecoveryDriver to trigger a scan in order to guarantee that it runs

Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/tools/ObjStoreBrowserTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/tools/ObjStoreBrowserTest.java	2010-05-25 10:08:46 UTC (rev 33068)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/tools/ObjStoreBrowserTest.java	2010-05-25 10:13:07 UTC (rev 33069)
@@ -9,6 +9,8 @@
 import com.arjuna.ats.arjuna.coordinator.RecordType;
 import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeManager;
 import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap;
+import com.arjuna.ats.arjuna.recovery.RecoveryDriver;
+import com.arjuna.ats.arjuna.recovery.RecoveryManager;
 import com.arjuna.ats.arjuna.tools.osb.util.JMXServer;
 
 import com.arjuna.ats.arjuna.tools.osb.mbean.*;
@@ -24,218 +26,221 @@
 import com.arjuna.ats.arjuna.AtomicAction;
 
 public class ObjStoreBrowserTest {
-    private RecoveryManagerImple rcm;
+	private RecoveryManagerImple rcm;
+	private RecoveryDriver rd;
 
-    @Before
-    public void setUp () throws Exception
-    {
-        recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
+	@Before
+	public void setUp () throws Exception
+	{
+		recoveryPropertyManager.getRecoveryEnvironmentBean().setPeriodicRecoveryPeriod(1);
+		recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
 
-        rcm = new RecoveryManagerImple(true);
-        rcm.addModule(new AtomicActionRecoveryModule());
-    }
+		rcm = new RecoveryManagerImple(true);
+		rcm.addModule(new AtomicActionRecoveryModule());
+		rd = new RecoveryDriver(RecoveryManager.getRecoveryManagerPort(),
+				recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryAddress(), 100000);
+	}
 
-    @After
-    public void tearDown () throws Exception
-    {
-        rcm.removeAllModules(false);
-        rcm.stop(false);
-    }
+	@After
+	public void tearDown () throws Exception
+	{
+		rcm.removeAllModules(false);
+		rcm.stop(false);
+	}
 
-    /**
-     * create an MBean to represent an ObjectStore
-     * @return An object that maintains MBeans representing completing transactions
-     */
-    private ObjStoreBrowser createObjStoreBrowser() {
-        ObjStoreBrowser osb = new ObjStoreBrowser();
+	/**
+	 * create an MBean to represent an ObjectStore
+	 * @return An object that maintains MBeans representing completing transactions
+	 */
+	private ObjStoreBrowser createObjStoreBrowser() {
+		ObjStoreBrowser osb = new ObjStoreBrowser();
 
-        // define which object store types we are prepared to represent by mbeans
-        osb.setTypes( new HashMap<String, String>() {{
+		// define which object store types we are prepared to represent by mbeans
+		osb.setTypes( new HashMap<String, String>() {{
 			put("StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction", "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean");
 		}});
 
-        return osb;
-    }
+		return osb;
+	}
 
-    @Test
-    public void testOSEntryBean() throws Exception {
-        com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new OSEntryBean());
-    }
+	@Test
+	public void testOSEntryBean() throws Exception {
+		com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new OSEntryBean());
+	}
 
-    @Test
-    public void testLogRecordWrapper() throws Exception {
-        com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new LogRecordWrapper(Uid.nullUid()));
-    }
+	@Test
+	public void testLogRecordWrapper() throws Exception {
+		com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new LogRecordWrapper(Uid.nullUid()));
+	}
 
-    @Test
-    public void testObjectStoreBrowser() throws Exception {
-        com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(createObjStoreBrowser());
-    }
+	@Test
+	public void testObjectStoreBrowser() throws Exception {
+		com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(createObjStoreBrowser());
+	}
 
-    @Test
+	@Test
 	public void basicOSBTest () throws Exception
 	{
-        ObjStoreBrowser osb = new ObjStoreBrowser("os");
+		ObjStoreBrowser osb = new ObjStoreBrowser("os");
 
-        Properties p = ObjStoreBrowser.loadProperties("invalid property file");
+		Properties p = ObjStoreBrowser.loadProperties("invalid property file");
 
-        assertTrue(p.size() == 0);
-        osb.start();
+		assertTrue(p.size() == 0);
+		osb.start();
 
-        // there should not be any MBeans
-        assertNull(osb.findUid(Uid.nullUid()));
+		// there should not be any MBeans
+		assertNull(osb.findUid(Uid.nullUid()));
 
-        // listing beans of an invalid type returns null
-        assertNull(osb.probe("InvalidType", "BeanClass"));
+		// listing beans of an invalid type returns null
+		assertNull(osb.probe("InvalidType", "BeanClass"));
 
-        // listing beans of a valid type returns an empty list
-        assertNotNull(osb.probe("Recovery",
-                "com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean"));
+		// listing beans of a valid type returns an empty list
+		assertNotNull(osb.probe("Recovery",
+				"com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean"));
 
-        osb.stop();
-    }
+		osb.stop();
+	}
 
-    /**
-     * Create an atomic action with two participants, one of which will generate a heuristic during phase 2.
-     * The test will move the heuristic back into the prepared state and trigger recovery to replay phase 2.
-     * The test then asserts that the corresponding MBeans have been unregistered.
-     * @throws Exception if test fails unexpectedly
-     */
-    @Test
-    public void aaReplayTest() throws Exception {
-        aaTest(true);
-    }
-    
-    /**
-     * Similar to aaReplayTest except that the whole transaction record is removed from the object store
-     * (instead of replaying the record that generates a heuristic).
-     * @throws Exception if test fails unexpectedly
-     */
-    @Test
-    public void aaRemoveTest() throws Exception {
-        aaTest(false);
-    }
-    
+	/**
+	 * Create an atomic action with two participants, one of which will generate a heuristic during phase 2.
+	 * The test will move the heuristic back into the prepared state and trigger recovery to replay phase 2.
+	 * The test then asserts that the corresponding MBeans have been unregistered.
+	 * @throws Exception if test fails unexpectedly
+	 */
+	@Test
+	public void aaReplayTest() throws Exception {
+		aaTest(true);
+	}
+	
+	/**
+	 * Similar to aaReplayTest except that the whole transaction record is removed from the object store
+	 * (instead of replaying the record that generates a heuristic).
+	 * @throws Exception if test fails unexpectedly
+	 */
+	@Test
+	public void aaRemoveTest() throws Exception {
+		aaTest(false);
+	}
+
 	public void aaTest(boolean replay) throws Exception {
 		ObjStoreBrowser osb = createObjStoreBrowser();
-        AtomicAction A = new AtomicAction();
-        CrashRecord recs[] = {
-                new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal),
-                new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard)
-        };
+		AtomicAction A = new AtomicAction();
+		CrashRecord recs[] = {
+				new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal),
+				new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard)
+		};
 
-        // register CrashRecord record type so that it is persisted in the object store correctly
-        RecordTypeManager.manager().add(new RecordTypeMap() {
-            public Class<? extends AbstractRecord> getRecordClass () { return CrashRecord.class;}
-            public int getType () {return RecordType.USER_DEF_FIRST0;}
-        });
+		// register CrashRecord record type so that it is persisted in the object store correctly
+		RecordTypeManager.manager().add(new RecordTypeMap() {
+			public Class<? extends AbstractRecord> getRecordClass () { return CrashRecord.class;}
+			public int getType () {return RecordType.USER_DEF_FIRST0;}
+		});
 
-        // create an atomic action, register crash records with it and then commit
-        A.begin();
+		// create an atomic action, register crash records with it and then commit
+		A.begin();
 
-        for (CrashRecord rec : recs)
-            A.add(rec);
+		for (CrashRecord rec : recs)
+			A.add(rec);
 
-        int outcome = A.commit();
+		int outcome = A.commit();
 
-        // the second participant should have generated a heuristic during commit
-        assertEquals(ActionStatus.H_HAZARD, outcome);
+		// the second participant should have generated a heuristic during commit
+		assertEquals(ActionStatus.H_HAZARD, outcome);
 
-        // generate MBeans representing the atomic action that was just committed
+		// generate MBeans representing the atomic action that was just committed
 		osb.start();
 
-        // there should be one MBean corresponding to the AtomicAction A
-        UidWrapper w = osb.findUid(A.get_uid());
-        assertNotNull(w);
-        OSEntryBean ai = w.getMBean();
-        assertNotNull(ai);
+		// there should be one MBean corresponding to the AtomicAction A
+		UidWrapper w = osb.findUid(A.get_uid());
+		assertNotNull(w);
+		OSEntryBean ai = w.getMBean();
+		assertNotNull(ai);
 
-        // the MBean should wrap an ActionBean
-        assertTrue(ai instanceof ActionBean);
-        ActionBean actionBean = (ActionBean) ai;
+		// the MBean should wrap an ActionBean
+		assertTrue(ai instanceof ActionBean);
+		ActionBean actionBean = (ActionBean) ai;
 
-        // and there should be one MBean corresponding to the CrashRecord that got the heuristic:
-        int recCount = 0;
-        for (CrashRecord rec : recs) {
-            LogRecordWrapper lw = actionBean.getParticipant(rec);
+		// and there should be one MBean corresponding to the CrashRecord that got the heuristic:
+		int recCount = 0;
+		for (CrashRecord rec : recs) {
+			LogRecordWrapper lw = actionBean.getParticipant(rec);
 
-            if (lw != null) {
-                recCount += 1;
+			if (lw != null) {
+				recCount += 1;
 
-                assertTrue(lw.isHeuristic());
+				assertTrue(lw.isHeuristic());
 
-                // put the participant back onto the pending list
-                lw.setStatus("PREPARED");
-                // and check that the record is no longer in a heuristic state
-                assertFalse(lw.isHeuristic());
-            }
-        }
+				// put the participant back onto the pending list
+				lw.setStatus("PREPARED");
+				// and check that the record is no longer in a heuristic state
+				assertFalse(lw.isHeuristic());
+			}
+		}
 
-        assertEquals(1, recCount);
+		assertEquals(1, recCount);
 
-        if (!replay) {
-            actionBean.remove();
-        } else {
-            /*
-            * prompt the recovery manager to replay the record that was
-            * moved off the heuristic list and back onto the prepared list
-            */
-            Thread.sleep(1000); // TODO why does sleep cause the scan to recognise the record can be replayed
-            rcm.scan();
-        }
+		if (!replay) {
+			actionBean.remove();
+		} else {
+			/*
+			* prompt the recovery manager to replay the record that was
+			* moved off the heuristic list and back onto the prepared list
+			*/
+			rd.synchronousScan();
+		}
 
-        /*
-         * Since the recovery scan (or explicit remove request) will have successfully removed the record from
-         * the object store another probe should cause the MBean representing the record to be unregistered
-         */
-        osb.probe();
+		/*
+		 * Since the recovery scan (or explicit remove request) will have successfully removed the record from
+		 * the object store another probe should cause the MBean representing the record to be unregistered
+		 */
+		osb.probe();
 
-        // look up the MBean and verify that it no longer exists
-        w = osb.findUid(A.get_uid());
-        assertNull(w);
+		// look up the MBean and verify that it no longer exists
+		w = osb.findUid(A.get_uid());
+		assertNull(w);
 
 		osb.dump(new StringBuilder());
-        osb.stop();
+		osb.stop();
 	}
 
-    // define an MBean interface for use in the next test
-    public interface NotAnotherMBean extends ObjStoreItemMBean {}
+	// define an MBean interface for use in the next test
+	public interface NotAnotherMBean extends ObjStoreItemMBean {}
 
-    @Test
-    public void testJMXServer() throws Exception {
+	@Test
+	public void testJMXServer() throws Exception {
 
-        class NonCompliantBean implements NotAnotherMBean {}
-        
-        ObjStoreBrowser osb = createObjStoreBrowser();
-        OSEntryBean bean;
-        String validName = "jboss.jta:type=TestObjectStore";
+		class NonCompliantBean implements NotAnotherMBean {}
+		
+		ObjStoreBrowser osb = createObjStoreBrowser();
+		OSEntryBean bean;
+		String validName = "jboss.jta:type=TestObjectStore";
 
-        osb.start();
+		osb.start();
 
-        bean = new OSEntryBean();
+		bean = new OSEntryBean();
 
-        // MalformedObjectNameException
-        assertNull(JMXServer.getAgent().registerMBean("InvalidName", bean));
-        assertFalse(JMXServer.getAgent().unregisterMBean("InvalidName"));
+		// MalformedObjectNameException
+		assertNull(JMXServer.getAgent().registerMBean("InvalidName", bean));
+		assertFalse(JMXServer.getAgent().unregisterMBean("InvalidName"));
 
-        // InstanceNotFoundException
-        assertFalse(JMXServer.getAgent().unregisterMBean(validName));
+		// InstanceNotFoundException
+		assertFalse(JMXServer.getAgent().unregisterMBean(validName));
 
-        // NotCompliantMBeanException
-        assertNull(JMXServer.getAgent().registerMBean(validName, new NonCompliantBean()));
+		// NotCompliantMBeanException
+		assertNull(JMXServer.getAgent().registerMBean(validName, new NonCompliantBean()));
 
-        // Do it right this time
-        int cnt = JMXServer.getAgent().queryNames(validName, null).size();
-        assertNotNull(JMXServer.getAgent().registerMBean(validName, bean));
-        assertEquals(cnt + 1, JMXServer.getAgent().queryNames(validName, null).size());
+		// Do it right this time
+		int cnt = JMXServer.getAgent().queryNames(validName, null).size();
+		assertNotNull(JMXServer.getAgent().registerMBean(validName, bean));
+		assertEquals(cnt + 1, JMXServer.getAgent().queryNames(validName, null).size());
 
-        // InstanceAlreadyExistsException
-        assertNull(JMXServer.getAgent().registerMBean(validName, bean));
+		// InstanceAlreadyExistsException
+		assertNull(JMXServer.getAgent().registerMBean(validName, bean));
 
-        // Make sure unregistering a valid bean works
-        assertTrue(JMXServer.getAgent().unregisterMBean(validName));
-        assertEquals(0, JMXServer.getAgent().queryNames(validName, null).size());
+		// Make sure unregistering a valid bean works
+		assertTrue(JMXServer.getAgent().unregisterMBean(validName));
+		assertEquals(0, JMXServer.getAgent().queryNames(validName, null).size());
 
-        osb.stop();
-    }
+		osb.stop();
+	}
 }

Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/tools/ObjStoreBrowserTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/tools/ObjStoreBrowserTest.java	2010-05-25 10:08:46 UTC (rev 33068)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/tools/ObjStoreBrowserTest.java	2010-05-25 10:13:07 UTC (rev 33069)
@@ -22,92 +22,92 @@
 import static org.junit.Assert.*;
 
 class ExtendedFailureXAResource extends FailureXAResource {
-    boolean forgotten;
+	boolean forgotten;
 
-    @Override
-    public void commit(Xid id, boolean onePhase) throws XAException {
-        if (!forgotten)
-            super.commit(id, onePhase);
-    }
+	@Override
+	public void commit(Xid id, boolean onePhase) throws XAException {
+		if (!forgotten)
+			super.commit(id, onePhase);
+	}
 
-    @Override
-    public void forget(Xid xid) throws XAException {
-        super.forget(xid);
-        forgotten = true;
-    }
+	@Override
+	public void forget(Xid xid) throws XAException {
+		super.forget(xid);
+		forgotten = true;
+	}
 }
 
 public class ObjStoreBrowserTest {
 
-    private ObjStoreBrowser createObjStoreBrowser() {
-        ObjStoreBrowser osb = new ObjStoreBrowser();
+	private ObjStoreBrowser createObjStoreBrowser() {
+		ObjStoreBrowser osb = new ObjStoreBrowser();
 
-        osb.setTypes( new HashMap<String, String>() {{
-            put("StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple", "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean");
-            put("StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction", "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean");
-        }});
+		osb.setTypes( new HashMap<String, String>() {{
+			put("StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple", "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean");
+			put("StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction", "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean");
+		}});
 
-        return osb;
-    }
+		return osb;
+	}
 
-    @BeforeClass
-    public static void setUp() {
-    }
+	@BeforeClass
+	public static void setUp() {
+	}
 
-    @Test
-    public void testXAResourceRecordBean() throws Exception {
-        com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new XAResourceRecordBean(new UidWrapper(Uid.nullUid())));
-    }
+	@Test
+	public void testXAResourceRecordBean() throws Exception {
+		com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new XAResourceRecordBean(new UidWrapper(Uid.nullUid())));
+	}
 
-    @Test
-    public void testMBeanHeuristic () throws Exception
-    {
-        ThreadActionData.purgeActions();
-        ObjStoreBrowser osb = createObjStoreBrowser();
-        XAResource[] resources = {
-                new DummyXA(false),
-                new FailureXAResource(FailureXAResource.FailLocation.commit) // generates a heuristic on commit
-        };
+	@Test
+	public void testMBeanHeuristic () throws Exception
+	{
+		ThreadActionData.purgeActions();
+		ObjStoreBrowser osb = createObjStoreBrowser();
+		XAResource[] resources = {
+				new DummyXA(false),
+				new FailureXAResource(FailureXAResource.FailLocation.commit) // generates a heuristic on commit
+		};
 
-        TransactionImple tx = new TransactionImple(0);
+		TransactionImple tx = new TransactionImple(0);
 
-        // enlist the XA resources into the transaction
-        for (XAResource resource : resources) {
+		// enlist the XA resources into the transaction
+		for (XAResource resource : resources) {
 
-            tx.enlistResource(resource);
-        }
+			tx.enlistResource(resource);
+		}
 
-        try {
-            tx.commit();
+		try {
+			tx.commit();
 
-            fail("Expected a mixed heuristic");
-        } catch (final HeuristicMixedException ex) {
-        }
+			fail("Expected a mixed heuristic");
+		} catch (final HeuristicMixedException ex) {
+		}
 
-        osb.start();
-        // there should be one MBean corresponding to the Transaction
-        UidWrapper w = osb.findUid(tx.get_uid());
-        assertNotNull(w);
-        OSEntryBean ai = w.getMBean();
-        assertNotNull(ai);
+		osb.start();
+		// there should be one MBean corresponding to the Transaction
+		UidWrapper w = osb.findUid(tx.get_uid());
+		assertNotNull(w);
+		OSEntryBean ai = w.getMBean();
+		assertNotNull(ai);
 
-        // the MBean should wrap a JTAActionBean
-        assertTrue(ai instanceof JTAActionBean);
-        JTAActionBean actionBean = (JTAActionBean) ai;
+		// the MBean should wrap a JTAActionBean
+		assertTrue(ai instanceof JTAActionBean);
+		JTAActionBean actionBean = (JTAActionBean) ai;
 
-        // and the transaction should contain only one participant (namely the FailureXAResource that generated the heuristic):
-        Collection<LogRecordWrapper> participants = actionBean.getParticipants();
+		// and the transaction should contain only one participant (namely the FailureXAResource that generated the heuristic):
+		Collection<LogRecordWrapper> participants = actionBean.getParticipants();
 
-        assertEquals(1, participants.size());
+		assertEquals(1, participants.size());
 
-        for (LogRecordWrapper participant : participants) {
-            assertTrue(participant.isHeuristic());
-            // put the participant back onto the pending list
-            participant.setStatus("PREPARED");
-            // and check that the record is no longer in a heuristic state
-            assertFalse(participant.isHeuristic());
-        }
+		for (LogRecordWrapper participant : participants) {
+			assertTrue(participant.isHeuristic());
+			// put the participant back onto the pending list
+			participant.setStatus("PREPARED");
+			// and check that the record is no longer in a heuristic state
+			assertFalse(participant.isHeuristic());
+		}
 
-        osb.stop();
-    }
+		osb.stop();
+	}
 }

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/tools/JTSObjStoreBrowserTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/tools/JTSObjStoreBrowserTest.java	2010-05-25 10:08:46 UTC (rev 33068)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/tools/JTSObjStoreBrowserTest.java	2010-05-25 10:13:07 UTC (rev 33069)
@@ -8,6 +8,8 @@
 import com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator;
 import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeManager;
 import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap;
+import com.arjuna.ats.arjuna.recovery.RecoveryDriver;
+import com.arjuna.ats.arjuna.recovery.RecoveryManager;
 import com.arjuna.ats.arjuna.tools.osb.mbean.*;
 import com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule;
 import com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple;
@@ -30,203 +32,211 @@
  * Test the the ObjStoreBrowser MBean in a JTS environment.
  */
 public class JTSObjStoreBrowserTest extends TestBase {
-    private RecoveryManagerImple rcm;
+	private RecoveryManagerImple rcm;
+	private RecoveryDriver rd;
 
-    @Before
-    public void setUp () throws Exception
-    {
-//        recoveryPropertyManager.getRecoveryEnvironmentBean().setPeriodicRecoveryPeriod(1);
-        recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
+	@Before
+	public void setUp () throws Exception
+	{
+		recoveryPropertyManager.getRecoveryEnvironmentBean().setPeriodicRecoveryPeriod(1);
+		recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
 
-        rcm = new RecoveryManagerImple(true);
-        rcm.addModule(new XARecoveryModule());
-        rcm.addModule(new AtomicActionRecoveryModule());
-    }
+		rcm = new RecoveryManagerImple(true);
+		rcm.addModule(new XARecoveryModule());
+		rcm.addModule(new AtomicActionRecoveryModule());
+		rd = new RecoveryDriver(RecoveryManager.getRecoveryManagerPort(),
+				recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryAddress(), 100000);
+	}
 
-    @After
-    public void tearDown () throws Exception
-    {
-        rcm.removeAllModules(false);
-        rcm.stop(false);
-    }
+	@After
+	public void tearDown () throws Exception
+	{
+		rcm.removeAllModules(false);
+		rcm.stop(false);
+	}
 
-    private ObjStoreBrowser createObjStoreBrowser() {
-        ObjStoreBrowser osb = new ObjStoreBrowser();
+	private ObjStoreBrowser createObjStoreBrowser() {
+		ObjStoreBrowser osb = new ObjStoreBrowser();
 
-        osb.setTypes( new HashMap<String, String>() {{
+		osb.setTypes( new HashMap<String, String>() {{
 			put("StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple", "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean");
 			put("StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction", "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean");
 		}});
 
-        return osb;
-    }
+		return osb;
+	}
 
-    /*
-         TODO JTS test-compile doesn't pull in com.arjuna.common.tests.simple
-    @Test
-    public void testXAResourceRecordBean() throws Exception {
-        com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new XAResourceRecordBean(new UidWrapper(Uid.nullUid())));
-    }
-    */
+	/*
+		 TODO JTS test-compile doesn't pull in com.arjuna.common.tests.simple
+	@Test
+	public void testXAResourceRecordBean() throws Exception {
+		com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new XAResourceRecordBean(new UidWrapper(Uid.nullUid())));
+	}
+	*/
 
-    /**
-     * Create an atomic action with two participants, one of which will generate a heuristic during phase 2.
-     * The test will move the heuristic back into the prepared state and trigger recovery to replay phase 2.
-     * The test then asserts that the corresponding MBeans have been unregistered.
-     * @throws Exception if test fails unexpectedly
-     */
-    @Test
-    public void aaReplayTest() throws Exception {
-        AtomicAction A = new AtomicAction();
-        ExtendedCrashRecord recs[] = startTest(A);
+	/**
+	 * Create an atomic action with two participants, one of which will generate a heuristic during phase 2.
+	 * The test will move the heuristic back into the prepared state and trigger recovery to replay phase 2.
+	 * The test then asserts that the corresponding MBeans have been unregistered.
+	 * @throws Exception if test fails unexpectedly
+	 */
+	@Test
+	public void aaReplayTest() throws Exception {
+		AtomicAction A = new AtomicAction();
+		ExtendedCrashRecord recs[] = startTest(A);
 
-        int outcome = A.commit();
+		int outcome = A.commit();
 
 		assertEquals(ActionStatus.H_HAZARD, outcome);
 
-        finishTest(A, true, recs);
-    }
+		finishTest(A, true, recs);
+	}
 
-    /**
-     * Similar to @aaReplayTest except that the whole transaction record is removed from the object store
-     * (instead of replaying the record that generates a heuristic).
-     * @throws Exception if test fails unexpectedly
-     */
-    @Test
-    public void aaRemoveTest() throws Exception {
-        AtomicAction A = new AtomicAction();
-        ExtendedCrashRecord recs[] = startTest(A);
+	/**
+	 * Similar to @aaReplayTest except that the whole transaction record is removed from the object store
+	 * (instead of replaying the record that generates a heuristic).
+	 * @throws Exception if test fails unexpectedly
+	 */
+	@Test
+	public void aaRemoveTest() throws Exception {
+		AtomicAction A = new AtomicAction();
+		ExtendedCrashRecord recs[] = startTest(A);
 
-        int outcome = A.commit();
+		int outcome = A.commit();
 
 		assertEquals(ActionStatus.H_HAZARD, outcome);
 
-        finishTest(A, false, recs);
-    }
+		finishTest(A, false, recs);
+	}
 
-    /**
-     * Similar to aaReplayTest but uses a JTS transaction instead of an AtomicAction
-     * @throws Exception if test fails unexpectedly
-     */
-    // TODO for replay to work on JTS participants ExtendedCrashReocrd wou needs to extend XAResourceRecord
-    // TODO @Test
-    public void jtsReplayTest() throws Exception {
-        ArjunaTransactionImple A = new ArjunaTransactionImple(null);
-        ExtendedCrashRecord recs[] = startTest(A);
+	/**
+	 * Similar to aaReplayTest but uses a JTS transaction instead of an AtomicAction
+	 * @throws Exception if test fails unexpectedly
+	 */
+	// TODO for replay to work on JTS participants ExtendedCrashReocrd needs to extend XAResourceRecord
+	// TODO @Test
+	public void jtsReplayTest() throws Exception {
+		ArjunaTransactionImple A = new ArjunaTransactionImple(null);
+		ExtendedCrashRecord recs[] = startTest(A);
 
-        int outcome = ActionStatus.COMMITTED;
+		int outcome = ActionStatus.COMMITTED;
 
 		try {
-            A.commit(true);
-        } catch (HeuristicHazard e) {
-            outcome = ActionStatus.H_HAZARD;
-        }
+			A.commit(true);
+		} catch (HeuristicHazard e) {
+			outcome = ActionStatus.H_HAZARD;
+		}
 
 		assertEquals(ActionStatus.H_HAZARD, outcome);
 
-        finishTest(A, true, recs);
-    }
+		finishTest(A, true, recs);
+	}
 
-    /**
-     * Similar to aaRemoveTest but uses a JTS transaction instead of an AtomicAction
-     * @throws Exception if test fails unexpectedly
-     */
-    @Test
-    public void jtsRemoveTest() throws Exception {
-        ArjunaTransactionImple A = new ArjunaTransactionImple(null);
-        ExtendedCrashRecord recs[] = startTest(A);
+	/**
+	 * Similar to aaRemoveTest but uses a JTS transaction instead of an AtomicAction
+	 * @throws Exception if test fails unexpectedly
+	 */
+	@Test
+	public void jtsRemoveTest() throws Exception {
+		ArjunaTransactionImple A = new ArjunaTransactionImple(null);
+		ExtendedCrashRecord recs[] = startTest(A);
 
-        int outcome = ActionStatus.COMMITTED;
+		int outcome = ActionStatus.COMMITTED;
 
 		try {
-            A.commit(true);
-        } catch (HeuristicHazard e) {
-            outcome = ActionStatus.H_HAZARD;
-        }
+			A.commit(true);
+		} catch (HeuristicHazard e) {
+			outcome = ActionStatus.H_HAZARD;
+		}
 
 		assertEquals(ActionStatus.H_HAZARD, outcome);
 
-        finishTest(A, false, recs);
-    }
+		finishTest(A, false, recs);
+	}
 
-    private ExtendedCrashRecord[] startTest(TwoPhaseCoordinator A) throws Exception {
-        ThreadActionData.purgeActions();
+	// create 2 participants, start the action and enlist both participants
+	private ExtendedCrashRecord[] startTest(TwoPhaseCoordinator A) throws Exception {
+		ThreadActionData.purgeActions();
 
-        ExtendedCrashRecord recs[] = {
-                new ExtendedCrashRecord(ExtendedCrashRecord.CrashLocation.NoCrash, ExtendedCrashRecord.CrashType.Normal),
-                new ExtendedCrashRecord(ExtendedCrashRecord.CrashLocation.CrashInCommit, ExtendedCrashRecord.CrashType.HeuristicHazard)
-        };
+		ExtendedCrashRecord recs[] = {
+				new ExtendedCrashRecord(ExtendedCrashRecord.CrashLocation.NoCrash, ExtendedCrashRecord.CrashType.Normal),
+				new ExtendedCrashRecord(ExtendedCrashRecord.CrashLocation.CrashInCommit, ExtendedCrashRecord.CrashType.HeuristicHazard)
+		};
 
-        RecordTypeManager.manager().add(new RecordTypeMap() {
-            public Class<? extends AbstractRecord> getRecordClass () { return ExtendedCrashRecord.class;}
-            public int getType () {return RecordType.USER_DEF_FIRST0;}
-        });
+		RecordTypeManager.manager().add(new RecordTypeMap() {
+			public Class<? extends AbstractRecord> getRecordClass () { return ExtendedCrashRecord.class;}
+			public int getType () {return RecordType.USER_DEF_FIRST0;}
+		});
 
-        A.start();
+		A.start();
 
-        for (ExtendedCrashRecord rec : recs)
+		for (ExtendedCrashRecord rec : recs)
 			A.add(rec);
-        
-        return recs;
-    }
+		
+		return recs;
+	}
 
-    private void finishTest(TwoPhaseCoordinator A, boolean replay, ExtendedCrashRecord ... recs) throws Exception {
-        ObjStoreBrowser osb = createObjStoreBrowser();
+	/*
+	 * Make sure there is an MBean corresponding to A and that at least one of recs has a heuristic.
+	 * Then either remove the action or replay (via the MBean) the record that got the heuristic
+	 * checking that the MBeans have all been unregistered from the MBeanServer.
+	 */
+	private void finishTest(TwoPhaseCoordinator A, boolean replay, ExtendedCrashRecord ... recs) throws Exception {
+		ObjStoreBrowser osb = createObjStoreBrowser();
 
-        // there should now be an entry in the object store containing two participants
-        osb.start();
+		// there should now be an entry in the object store containing two participants
+		osb.start();
 
-        // there should be one MBean corresponding to the AtomicAction A
-        UidWrapper w = osb.findUid(A.get_uid());
-        assertNotNull(w);
-        OSEntryBean ai = w.getMBean();
-        assertNotNull(ai);
+		// there should be one MBean corresponding to the AtomicAction A
+		UidWrapper w = osb.findUid(A.get_uid());
+		assertNotNull(w);
+		OSEntryBean ai = w.getMBean();
+		assertNotNull(ai);
 
-        // the MBean should wrap an ActionBean
-        assertTrue(ai instanceof ActionBean);
-        ActionBean actionBean = (ActionBean) ai;
+		// the MBean should wrap an ActionBean
+		assertTrue(ai instanceof ActionBean);
+		ActionBean actionBean = (ActionBean) ai;
 
-        // and there should be one MBean corresponding to the CrashRecord that got the heuristic:
-        int recCount = 0;
-        for (ExtendedCrashRecord rec : recs) {
-            LogRecordWrapper lw = actionBean.getParticipant(rec);
+		// and there should be one MBean corresponding to the CrashRecord that got the heuristic:
+		int recCount = 0;
+		for (ExtendedCrashRecord rec : recs) {
+			LogRecordWrapper lw = actionBean.getParticipant(rec);
 
-            if (lw != null) {
-                recCount += 1;
+			if (lw != null) {
+				recCount += 1;
 
-                if (lw.isHeuristic()) {
-                    if (replay) {
-                        rec.forget();
-                        lw.setStatus("PREPARED");
-                        // the participant record should no longer be on the heuristic list
-                        assertFalse(lw.isHeuristic());
-                    }
-                }
-            }
-        }
+				if (lw.isHeuristic()) {
+					if (replay) {
+						rec.forget();
+						lw.setStatus("PREPARED");
+						// the participant record should no longer be on the heuristic list
+						assertFalse(lw.isHeuristic());
+					}
+				}
+			}
+		}
 
-        assertEquals(1, recCount);
+		assertEquals(1, recCount);
 
-        if (!replay) {
-            actionBean.remove();
-        } else {
-            /*
-            * prompt the recovery manager to have a go at replaying the record that was
-            * moved off the heuristic list and back onto the prepared list
-            */
-            Thread.sleep(1000); // TODO why does sleep cause the scan to recognise the record can be replayed
-            rcm.scan();
-        }
+		if (!replay) {
+			actionBean.remove();
+		} else {
+			/*
+			* prompt the recovery manager to have a go at replaying the record that was
+			* moved off the heuristic list and back onto the prepared list
+			*/
+			rd.synchronousScan();
+		}
 
-        // another probe should no longer find the record that got the heuristic
-        // (since it was either removed or the RecoveryManager replayed the commit
-        // phase) so its corresponding MBean will have been unregistered
-        osb.probe();
+		// another probe should no longer find the record that got the heuristic
+		// (since it was either removed or the RecoveryManager replayed the commit
+		// phase) so its corresponding MBean will have been unregistered
+		osb.probe();
 
-        // look up the MBean and verify that it no longer exists
-        w = osb.findUid(A.get_uid());
-        assertNull(w);
+		// look up the MBean and verify that it no longer exists
+		w = osb.findUid(A.get_uid());
+		assertNull(w);
 
-        osb.stop();
-    }
-}
\ No newline at end of file
+		osb.stop();
+	}
+}



More information about the jboss-svn-commits mailing list