1 2 package org.objectweb.jonas.stests.manyops; 3 4 import java.rmi.RemoteException ; 5 6 import javax.naming.NamingException ; 7 import javax.rmi.PortableRemoteObject ; 8 9 import org.objectweb.jonas.stests.util.JTestCase; 10 11 12 public abstract class A_manyops extends JTestCase { 13 14 private static final int NB_PRODUCTS = 2500; 16 private static final int NB_CREATE = 20; 18 19 protected static InitDBHome idbHome = null; 21 protected static InitDB idb = null; 22 protected static ProductHome pHome = null; 23 protected static boolean initialized = false; 24 25 public A_manyops(String name) { 26 super(name); 27 } 28 29 protected void setUp() throws Exception { 30 super.setUp(); 31 if (idbHome == null) { 32 useBeans("manyops"); 33 idbHome = (InitDBHome) PortableRemoteObject.narrow(ictx.lookup("manyopsInitDBHome"), InitDBHome.class); 34 } 35 if (idb == null) { 36 idb = idbHome.create(); 37 } 38 if (pHome == null) { 39 pHome = getProductHome(); 40 } 41 if (!initialized) { 42 idb.createTable(); 44 for (int i=1; i<=NB_PRODUCTS; i++) { 45 pHome.create("p"+i, i, 0); 46 } 47 initialized = true; 48 } 49 } 50 51 54 abstract ProductHome getProductHome() throws NamingException ; 55 56 protected void tearDown() throws Exception { 57 super.tearDown(); 58 } 59 60 71 public void manyops(int opNb, String opType) throws Exception { 72 if (opNb > NB_PRODUCTS) { 73 throw new Exception ("Operation number must be less than the initial product number"); 74 } 75 for (int i=1; i<=opNb; i++) { 77 Product bean; 78 int p; 79 if ("create".equals(opType)) { 80 int ipk = NB_PRODUCTS+i; 81 String spk = "p"+ipk; 82 bean = pHome.create(spk, ipk, 1); 83 } else if ("createmany".equals(opType)) { 84 for (int ii=1; ii<=NB_CREATE; ii++) { 85 int iipk = NB_PRODUCTS+ii; 86 bean = pHome.create("p"+iipk, iipk, 1); 87 } 88 for (int ii=1; ii<=NB_CREATE; ii++) { 89 int iipk = NB_PRODUCTS+ii; 90 pHome.remove("p"+iipk); 91 } 92 } else if ("delete".equals(opType)) { 93 String spk = "p"+i; 94 pHome.remove(spk); 95 } else { 96 int ipk = random(NB_PRODUCTS)+1; 98 String spk = "p"+ipk; 99 if ("get".equals(opType)) { 100 bean = pHome.findByPrimaryKey(spk); 101 p = bean.getPrice(); 102 } else if ("set".equals(opType)) { 103 bean = pHome.findByPrimaryKey(spk); 104 bean.setPrice(2); 105 } else if ("findByPk".equals(opType)) { 106 bean = pHome.findByPrimaryKey(spk); 107 } else if ("findByNumber".equals(opType)) { 108 bean = pHome.findByNumber(ipk); 109 } else { 110 throw new Exception ("Invalid operation name ("+opType+")"); 111 } 112 } 113 } 114 for (int i=1; i<=opNb; i++) { 116 if ("create".equals(opType)) { 117 int ipk = NB_PRODUCTS+i; 118 String spk = "p"+ipk; 119 pHome.remove(spk); 120 } else if ("createmany".equals(opType)) { 121 } else if ("get".equals(opType)) { 123 } else if ("set".equals(opType)) { 125 } else if ("findByPk".equals(opType)) { 127 } else if ("delete".equals(opType)) { 129 String spk = "p"+i; 130 pHome.create(spk, i, 0); 131 } 132 } 133 } 134 135 138 private int random(int max) throws RemoteException { 139 double d = Math.random(); 140 int ret = (int) (max * d); 141 return ret; 142 } 143 144 public void test_100_create() throws Exception { 145 manyops(100, "create"); 146 } 147 public void test_100_get() throws Exception { 148 manyops(100, "get"); 149 } 150 public void test_100_set() throws Exception { 151 manyops(100, "set"); 152 } 153 public void test_100_findByPk() throws Exception { 154 manyops(100, "findByPk"); 155 } 156 public void test_100_findByNumber() throws Exception { 157 manyops(100, "findByNumber"); 158 } 159 public void test_100_delete() throws Exception { 160 manyops(100, "delete"); 161 } 162 public void test_100_createmany() throws Exception { 163 manyops(100, "createmany"); 164 } 165 166 public void test_250_create() throws Exception { 167 manyops(250, "create"); 168 } 169 public void test_250_get() throws Exception { 170 manyops(250, "get"); 171 } 172 public void test_250_set() throws Exception { 173 manyops(250, "set"); 174 } 175 public void test_250_findByPk() throws Exception { 176 manyops(250, "findByPk"); 177 } 178 public void test_250_findByNumber() throws Exception { 179 manyops(250, "findByNumber"); 180 } 181 public void test_250_delete() throws Exception { 182 manyops(100, "delete"); 183 } 184 public void test_250_createmany() throws Exception { 185 manyops(250, "createmany"); 186 } 187 188 public void test_500_create() throws Exception { 189 manyops(500, "create"); 190 } 191 public void test_500_get() throws Exception { 192 manyops(500, "get"); 193 } 194 public void test_500_set() throws Exception { 195 manyops(500, "set"); 196 } 197 public void test_500_findByPk() throws Exception { 198 manyops(500, "findByPk"); 199 } 200 public void test_500_findByNumber() throws Exception { 201 manyops(500, "findByNumber"); 202 } 203 public void test_500_delete() throws Exception { 204 manyops(100, "delete"); 205 } 206 public void test_500_createmany() throws Exception { 207 manyops(500, "createmany"); 208 } 209 210 } 211 | Popular Tags |