1 25 26 package org.objectweb.jonas.jtests.clients.distribution; 27 28 import javax.rmi.PortableRemoteObject ; 29 import org.objectweb.jonas.jtests.beans.bank.Manager; 30 import org.objectweb.jonas.jtests.beans.bank.ManagerHome; 31 import org.objectweb.jonas.jtests.util.JTestCase; 32 33 public abstract class A_bankRead extends JTestCase { 34 35 protected static final int OP_READ = 1; 36 protected static final int OP_MOVE = 2; 37 protected static final int OP_CREATE = 3; 38 protected static final int OP_REMOVE = 4; 39 protected static final int OP_ONEMOVE = 5; 40 protected static final int OP_READTX = 6; 41 protected static final int OP_ONEMOVETX = 7; 42 protected static final int OP_MOVETO = 8; 43 44 static final int initialValue = 1000; 45 static final int accountNb = 20; 46 47 protected static ManagerHome home = null; 48 protected static Manager manager = null; 49 public static boolean threadfail; 50 51 public A_bankRead(String name) { 52 super(name); 53 } 54 55 public abstract String getManagerHomeName(); 56 public abstract boolean getPrefetch(); 57 58 protected void setUp() { 59 super.setUp(); 60 try { 61 if (home == null) { 62 useBeans("bank", false); 63 home = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(getManagerHomeName()), ManagerHome.class); 64 } 65 if (manager == null) { 66 manager = home.create(initialValue, getPrefetch()); 67 } 68 manager.createAll(accountNb); 70 threadfail = false; 71 } catch (Exception e) { 72 fail("Exception raised in setup: " + e); 73 } 74 } 75 76 protected void tearDown() throws Exception { 77 super.tearDown(); 78 if (threadfail && manager != null) { 79 manager.reinitAll(); 80 manager.remove(); 81 manager = null; 82 } 83 } 84 public void ope(int action, int accmin, int accmax, int loops, int threads) throws Exception { 85 ope(action, accmin, accmax, loops, threads, 10, true); 86 } 87 88 public void ope(int action, int accmin, int accmax, int loops, int threads, int amount) throws Exception { 89 ope(action, accmin, accmax, loops, threads, amount, true); 90 } 91 92 99 public void ope(int action, int accmin, int accmax, int loops, int threads, int amount, boolean verify) throws Exception { 100 101 if (amount > 10) { 103 stopTxAt(20); 104 } 105 106 A_thread[] t_thr = new A_thread[threads]; 108 for (int i = 0; i < threads; i++) { 109 t_thr[i] = new A_thread(getManagerHomeName(), i, ictx, action, accmin, accmax, loops, amount, getPrefetch()); 110 t_thr[i].start(); 111 } 112 113 for (int p = 0; p < threads; p++) { 115 t_thr[p].join(); 116 } 117 118 if (threadfail) { 120 fail("Error in a thread"); 121 } 122 if (verify) { 123 stopTxAt(600); 124 if (!manager.checkAll()) { 125 threadfail = true; fail("Bad global state"); 127 } 128 } 129 } 130 131 132 public void testCheckAll() throws Exception { 133 if (!manager.checkAll()) { 134 fail("Bad state in database"); 135 } 136 } 137 138 147 public void testBasicRead() throws Exception { 148 ope(OP_READ, 0, 9, 1, 1, 10, false); 149 } 150 151 160 public void testBasicReadTx() throws Exception { 161 ope(OP_READTX, 0, 9, 1, 1, 10, false); 162 } 163 172 public void test3Readers() throws Exception { 173 ope(OP_READ, 0, 9, 10, 3); 174 } 175 176 185 public void test4Readers() throws Exception { 186 ope(OP_READ, 0, 9, 10, 4); 187 } 188 197 public void test5Readers() throws Exception { 198 ope(OP_READ, 0, 9, 10, 5); 199 } 200 209 public void test8Readers() throws Exception { 210 ope(OP_READ, 0, 9, 10, 8); 211 } 212 213 222 public void test3ReadersTx() throws Exception { 223 ope(OP_READTX, 0, 9, 10, 3); 224 } 225 234 public void test4ReadersTx() throws Exception { 235 ope(OP_READTX, 0, 9, 10, 4); 236 } 237 246 public void test5ReadersTx() throws Exception { 247 ope(OP_READTX, 0, 9, 10, 5); 248 } 249 250 259 public void test8ReadersTx() throws Exception { 260 ope(OP_READTX, 0, 9, 10, 8); 261 } 262 263 272 273 public void testMultiRead() throws Exception { 274 ope(OP_READ, 0, 9, 1, 10); 275 } 276 285 286 public void testMultiReadTx() throws Exception { 287 ope(OP_READTX, 0, 9, 1, 10); 288 } 289 290 299 300 public void testMultiShortReadTx() throws Exception { 301 ope(OP_READTX, 0, 9, 10, 10); 302 } 303 304 } 305 | Popular Tags |