1 22 package org.jboss.test.aop.bean; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.system.ServiceMBeanSupport; 26 27 import javax.management.MBeanRegistration ; 28 import javax.management.MBeanServer ; 29 import javax.management.ObjectName ; 30 31 36 public class TxLockTester 37 extends ServiceMBeanSupport 38 implements TxLockTesterMBean, MBeanRegistration 39 { 40 static Logger log = Logger.getLogger(TxLockTester.class); 43 MBeanServer m_mbeanServer; 44 45 47 public TxLockTester() 49 {} 50 51 53 public ObjectName preRegister(MBeanServer server, ObjectName name) 55 throws Exception 56 { 57 m_mbeanServer = server; 58 return name; 59 } 60 61 public void postRegister(Boolean registrationDone) 62 {} 63 64 public void preDeregister() throws Exception 65 {} 66 67 public void postDeregister() 68 {} 69 70 protected void startService() 71 throws Exception 72 { 73 } 74 75 protected void stopService() 76 { 77 } 78 79 boolean failed = false; 80 81 public class LockThread implements Runnable 82 { 83 TxLockedPOJO pojo; 84 85 public LockThread(TxLockedPOJO pojo) 86 { 87 this.pojo = pojo; 88 } 89 90 public void run() 91 { 92 try 93 { 94 pojo.setField(5); 96 } 97 catch (Exception ex) 98 { 99 failed = true; 100 log.error("thread failed", ex); 101 } 102 } 103 } 104 105 public class AnnotatedLockThread implements Runnable 106 { 107 AnnotatedTxLockedPOJO pojo; 108 109 public AnnotatedLockThread(AnnotatedTxLockedPOJO pojo) 110 { 111 this.pojo = pojo; 112 } 113 114 public void run() 115 { 116 try 117 { 118 pojo.setField(5); 120 } 121 catch (Exception ex) 122 { 123 failed = true; 124 log.error("thread failed", ex); 125 } 126 } 127 } 128 129 public void testXml() 130 { 131 failed = false; 132 try 133 { 134 log.info("TESTING TX LOCK"); 135 TxLockedPOJO pojo = new TxLockedPOJO(); 136 Thread t = new Thread (new LockThread(pojo)); 137 t.start(); 138 Thread.sleep(1000); 139 pojo.setField(6); 140 if (failed) throw new RuntimeException ("test failed"); 141 } 142 catch (Throwable ex) 143 { 144 log.error("failed", ex); 145 throw new RuntimeException (ex.getMessage()); 146 } 147 } 148 149 public void testAnnotated() 150 { 151 failed = false; 152 try 153 { 154 log.info("TESTING TX LOCK"); 155 AnnotatedTxLockedPOJO pojo = new AnnotatedTxLockedPOJO(); 156 Thread t = new Thread (new AnnotatedLockThread(pojo)); 157 t.start(); 158 Thread.sleep(1000); 159 pojo.setField(6); 160 if (failed) throw new RuntimeException ("test failed"); 161 } 162 catch (Throwable ex) 163 { 164 log.error("failed", ex); 165 throw new RuntimeException (ex.getMessage()); 166 } 167 } 168 169 } 170 171 | Popular Tags |