11package com .hp .mwtests .ts .jta .tools ;
22
33import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertFalse ;
45import static org .junit .Assert .assertNotNull ;
56import static org .junit .Assert .assertNull ;
67import static org .junit .Assert .assertTrue ;
78import static org .junit .Assert .fail ;
89
9- import java .io .IOException ;
1010import java .util .Collection ;
1111import java .util .HashSet ;
1212import java .util .Set ;
1313
1414import javax .management .MBeanException ;
1515import javax .management .MalformedObjectNameException ;
1616import javax .management .ObjectName ;
17-
18- import com .arjuna .ats .arjuna .exceptions .ObjectStoreException ;
19- import com .arjuna .ats .internal .jta .resources .arjunacore .XAResourceRecord ;
20- import org .jboss .tm .XAResourceWrapper ;
21- import com .arjuna .ats .internal .jta .resources .arjunacore .XAResourceRecordWrappingPlugin ;
22- import com .arjuna .ats .jta .common .JTAEnvironmentBean ;
23- import com .arjuna .ats .jta .common .jtaPropertyManager ;
2417import jakarta .transaction .HeuristicMixedException ;
2518import javax .transaction .xa .XAException ;
2619import javax .transaction .xa .XAResource ;
5245 * provide a better separation between public and internal classes.
5346 */
5447@ Deprecated // in order to provide a better separation between public and internal classes.
55- class ExtendedFailureXAResource extends FailureXAResource implements XAResourceWrapper {
48+ class ExtendedFailureXAResource extends FailureXAResource {
5649 private boolean forgotten ;
57- private String productName ;
58-
59- public ExtendedFailureXAResource (FailLocation loc ) {
60- super (loc );
61- }
6250
6351 @ Override
6452 public void commit (Xid id , boolean onePhase ) throws XAException {
@@ -71,35 +59,19 @@ public void forget(Xid xid) throws XAException {
7159 super .forget (xid );
7260 forgotten = true ;
7361 }
74-
75- @ Override
76- public XAResource getResource () {
77- return null ;
78- }
79-
80- public void setProductName (String productName ) {
81- this .productName = productName ;
82- }
83-
84- @ Override
85- public String getProductName () {
86- return productName ;
87- }
88-
89- @ Override
90- public String getProductVersion () {
91- return null ;
92- }
93-
94- @ Override
95- public String getJndiName () {
96- return null ;
97- }
9862}
9963
10064public class ObjStoreBrowserTest {
10165 private ObjStoreBrowser osb ;
10266
67+ private ObjStoreBrowser createObjStoreBrowser () {
68+ ObjStoreBrowser osb = new ObjStoreBrowser ();
69+
70+ osb .setType ("com.arjuna.ats.arjuna.AtomicAction" , "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean" );
71+
72+ return osb ;
73+ }
74+
10375 @ BeforeClass
10476 public static void setUp () {
10577 }
@@ -135,16 +107,9 @@ public void testCommitMarkableResourceRecordBean() throws Exception {
135107 @ Test
136108 public void testMBeanHeuristic () throws Exception
137109 {
138- // generates a heuristic on commit
139- ExtendedFailureXAResource failureXAResource =
140- new ExtendedFailureXAResource (FailureXAResource .FailLocation .commit );
141- String productName = "P" ;
142-
143- failureXAResource .setProductName (productName );
144-
145- XAResourceRecordBeanMBean mbean = getHeuristicMBean (osb , new TransactionImple (1000000000 ), failureXAResource );
110+ FailureXAResource failureXAResource = new FailureXAResource (FailureXAResource .FailLocation .commit ); // generates a heuristic on commit
146111
147- assertEquals ( productName , mbean . getEisProductName () );
112+ getHeuristicMBean ( osb , new TransactionImple ( 1000000000 ), failureXAResource );
148113 }
149114
150115 /**
@@ -373,61 +338,25 @@ private JTAActionBean getTransactionBean(ObjStoreBrowser osb, TransactionImple t
373338 }
374339
375340 private XAResourceRecordBeanMBean getHeuristicMBean (ObjStoreBrowser osb , TransactionImple tx , FailureXAResource failureXAResource ) throws Exception {
376- // use the wrapper plugin because we'd also like to test resource metadata
377- XAResourceRecordWrappingPlugin xarWrapperPlugin = new XAResourceRecordWrappingPlugin () {
378- String productName = "" ;
379- @ Override
380- public void transcribeWrapperData (XAResourceRecord xaResourceRecord ) {
381- final XAResource xaResource = (XAResource ) xaResourceRecord .value ();
382-
383- if (xaResource instanceof XAResourceWrapper ) {
384- XAResourceWrapper xaResourceWrapper = (XAResourceWrapper ) xaResource ;
385- productName = xaResourceWrapper .getProductName ();
386-
387- xaResourceRecord .setProductName (xaResourceWrapper .getProductName ());
388- xaResourceRecord .setProductVersion (xaResourceWrapper .getProductVersion ());
389- xaResourceRecord .setJndiName (xaResourceWrapper .getJndiName ());
390- }
391- }
392-
393- @ Override
394- public Integer getEISName (XAResource xaResource ) throws IOException , ObjectStoreException {
395- return 0 ;
396- }
397-
398- @ Override
399- public String getEISName (Integer eisName ) {
400- return productName ;
401- }
402- };
403-
404- JTAEnvironmentBean env = jtaPropertyManager .getJTAEnvironmentBean ();
405- XAResourceRecordWrappingPlugin prevWrappingPlugin = env .getXAResourceRecordWrappingPlugin ();
341+ generateHeuristic (tx , failureXAResource );
406342
407- try {
408- env .setXAResourceRecordWrappingPlugin (xarWrapperPlugin );
409- generateHeuristic (tx , failureXAResource );
410- osb .probe ();
411- // there should be one MBean corresponding to the Transaction
412- JTAActionBean actionBean = getTransactionBean (osb , tx , true );
343+ osb .probe ();
344+ // there should be one MBean corresponding to the Transaction
345+ JTAActionBean actionBean = getTransactionBean (osb , tx , true );
413346
414- assertNotNull (actionBean );
347+ assertNotNull (actionBean );
415348
416- // and the transaction should contain only one participant
417- // (namely the FailureXAResource that generated the heuristic):
418- Collection <LogRecordWrapper > participants = actionBean .getParticipants ();
349+ // and the transaction should contain only one participant (namely the FailureXAResource that generated the heuristic):
350+ Collection <LogRecordWrapper > participants = actionBean .getParticipants ();
419351
420- assertEquals (1 , participants .size ());
421- assertNotNull (failureXAResource .getXid ());
352+ assertEquals (1 , participants .size ());
353+ assertNotNull (failureXAResource .getXid ());
422354
423- LogRecordWrapper participant = participants .iterator ().next ();
355+ LogRecordWrapper participant = participants .iterator ().next ();
424356
425- assertTrue (participant .isHeuristic ());
426- assertTrue (participant instanceof XAResourceRecordBeanMBean );
357+ assertTrue (participant .isHeuristic ());
358+ assertTrue (participant instanceof XAResourceRecordBeanMBean );
427359
428- return (XAResourceRecordBeanMBean ) participant ;
429- } finally {
430- env .setXAResourceRecordWrappingPlugin (prevWrappingPlugin );
431- }
360+ return (XAResourceRecordBeanMBean ) participant ;
432361 }
433362}
0 commit comments