1 25 26 package org.objectweb.jonas.stests.bank; 27 28 import javax.rmi.PortableRemoteObject ; 29 import org.objectweb.jonas.stests.util.JTestCase; 30 31 32 public abstract class A_bank extends JTestCase { 33 34 protected static final int OP_READ = 1; 35 protected static final int OP_MOVE = 2; 36 protected static final int OP_CREATE = 3; 37 protected static final int OP_REMOVE = 4; 38 protected static final int OP_ONEMOVE = 5; 39 protected static final int OP_READTX = 6; 40 protected static final int OP_ONEMOVETX = 7; 41 protected static final int OP_MOVETO = 8; 42 43 static final int initialValue = 1000; 44 static final int accountNb = 20; 45 46 protected static ManagerHome home = null; 47 protected static Manager manager = null; 48 public static boolean threadfail; 49 50 public A_bank(String name) { 51 super(name); 52 } 53 54 public abstract String getManagerHomeName(); 55 public abstract boolean getPrefetch(); 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 if (home == null) { 60 useBeans("bank"); 61 home = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(getManagerHomeName()), ManagerHome.class); 62 } 63 if (manager == null) { 64 manager = home.create(initialValue, getPrefetch()); 65 } 66 manager.createAll(accountNb); 68 threadfail = false; 69 } 70 71 protected void tearDown() throws Exception { 72 super.tearDown(); 73 if (threadfail && manager != null) { 74 manager.reinitAll(); 75 manager.remove(); 76 manager = null; 77 } 78 } 79 80 public void ope(int action, int accmin, int accmax, int loops, int threads) throws Exception { 81 ope(action, accmin, accmax, loops, threads, 10, true); 82 } 83 84 public void ope(int action, int accmin, int accmax, int loops, int threads, int amount) throws Exception { 85 ope(action, accmin, accmax, loops, threads, amount, true); 86 } 87 88 95 public void ope(int action, int accmin, int accmax, int loops, int threads, int amount, boolean verify) throws Exception { 96 97 stopTxAt(20); 99 100 A_thread[] t_thr = new A_thread[threads]; 102 for (int i = 0; i < threads; i++) { 103 t_thr[i] = new A_thread(getManagerHomeName(), i, ictx, action, accmin, accmax, loops, amount, getPrefetch()); 104 t_thr[i].start(); 105 } 106 107 for (int p = 0; p < threads; p++) { 109 t_thr[p].join(); 110 } 111 112 if (threadfail) { 114 fail("Error in a thread"); 115 } 116 if (verify && !manager.checkAll()) { 117 threadfail = true; fail("Bad global state"); 119 } 120 } 121 122 public void testBasicRead() throws Exception { 123 ope(OP_READ, 0, 9, 1, 1, 10, false); 124 } 125 126 public void testPrefetch() throws Exception { 127 ope(OP_READ, 0, 9, 50, 8); 128 } 129 130 public void testDeadlock() throws Exception { 131 ope(OP_MOVETO, 3, 5, 1, 2, 20); 132 } 133 134 public void testSameAccount() throws Exception { 135 ope(OP_MOVETO, 2, 2, 10, 1, 10); 136 } 137 138 public void testMultiSameAccount() throws Exception { 139 ope(OP_MOVETO, 6, 6, 1, 10, 10); 140 } 141 142 public void testBasicReadTx() throws Exception { 143 ope(OP_READTX, 0, 9, 1, 1, 10, false); 144 } 145 146 public void testLongRead() throws Exception { 147 ope(OP_READ, 0, 9, 100, 1); 148 } 149 150 public void testLongReadTx() throws Exception { 151 ope(OP_READTX, 0, 9, 100, 1); 152 } 153 154 public void testMultiRead() throws Exception { 155 ope(OP_READ, 0, 9, 1, 10); 156 } 157 158 public void testMultiReadTx() throws Exception { 159 ope(OP_READTX, 0, 9, 1, 10); 160 } 161 162 163 public void testMultiShortReadTx() throws Exception { 164 ope(OP_READTX, 0, 9, 10, 10); 165 } 166 167 public void testMultiOneMove() throws Exception { 168 ope(OP_ONEMOVE, 0, 5, 1, 20); 169 } 170 171 public void testTh3OneMoveTx() throws Exception { 172 ope(OP_ONEMOVETX, 0, 5, 100, 3); 173 } 174 175 public void testTh5OneMoveTx() throws Exception { 176 ope(OP_ONEMOVETX, 0, 5, 100, 5); 177 } 178 179 public void testTh7OneMoveTx() throws Exception { 180 ope(OP_ONEMOVETX, 0, 5, 100, 7); 181 } 182 183 public void testMultiOneMoveTx() throws Exception { 184 ope(OP_ONEMOVETX, 0, 5, 1, 20); 185 } 186 187 191 public void testMultiLongRead() throws Exception { 192 ope(OP_READ, 0, 9, 200, 12); 193 } 194 195 199 public void testMultiLongReadTx() throws Exception { 200 ope(OP_READTX, 0, 19, 200, 12, 1); 201 } 202 203 207 public void testMultiLongOneMove() throws Exception { 208 ope(OP_ONEMOVE, 0, 19, 200, 12, 1); 209 } 210 211 215 public void testMultiLongOneMoveTx() throws Exception { 216 ope(OP_ONEMOVETX, 0, 19, 200, 12, 1); 217 } 218 219 } 220 | Popular Tags |