1 22 package org.jboss.test.jca.test; 23 24 import javax.transaction.Status ; 25 import javax.transaction.Transaction ; 26 27 33 public class AbstractContentiousRecyclingPoolingStressTest extends AbstractPoolingStressTest 34 { 35 TransactionState[] txStates; 36 37 public void runConcurrentTest(ConcurrentRunnable[] runnables, ConcurrentTestCallback callback) throws Throwable 38 { 39 int transactions = getBeanCount(); 41 int threads = getThreadCount(); 42 if (transactions >= threads) 43 transactions = threads / 2; 44 if (transactions == 0) 45 transactions = 1; 46 47 txStates = new TransactionState[transactions]; 48 for (int i = 0; i < txStates.length; ++i) 49 txStates[i] = new TransactionState(); 50 super.runConcurrentTest(runnables, callback); 51 } 52 53 public abstract class ContentiousRecyclingPoolingRunnable extends ConcurrentRunnable 54 { 55 TransactionState txState; 56 57 public ContentiousRecyclingPoolingRunnable() 58 { 59 } 60 61 public void doStart() throws Throwable 62 { 63 txState = txStates[id % txStates.length]; 64 } 65 66 public void doEnd() throws Throwable 67 { 68 } 69 70 public void doRun() throws Throwable 71 { 72 waitDone(); 73 txState.begin(); 74 try 75 { 76 doRun1(); 77 } 78 catch (Throwable t) 79 { 80 setFailure(t); 81 tm.setRollbackOnly(); 82 throw t; 83 } 84 finally 85 { 86 tm.suspend(); 87 waitDone(); 88 txState.commit(); 89 } 90 } 91 92 public abstract void doRun1() throws Throwable ; 93 } 94 95 public class TransactionState 96 { 97 Transaction tx; 98 99 public TransactionState() 100 { 101 } 102 103 public synchronized void begin() throws Throwable 104 { 105 if (tx == null) 106 { 107 tm.begin(); 108 tx = tm.getTransaction(); 109 } 110 else 111 { 112 tm.resume(tx); 113 } 114 } 115 116 public synchronized void commit() throws Throwable 117 { 118 if (tx != null) 119 { 120 tm.resume(tx); 121 if (tm.getStatus() == Status.STATUS_MARKED_ROLLBACK) 122 tm.rollback(); 123 else 124 tm.commit(); 125 tx = null; 126 } 127 } 128 } 129 130 public AbstractContentiousRecyclingPoolingStressTest(String name) 131 { 132 super(name); 133 } 134 } 135 | Popular Tags |