1 18 19 package org.objectweb.speedo.stress; 20 21 import org.objectweb.speedo.Alea; 22 import org.objectweb.speedo.pobjects.userid.LinkedIntUserId; 23 import org.objectweb.util.monolog.api.BasicLevel; 24 25 import javax.jdo.Extent; 26 import javax.jdo.PersistenceManager; 27 import javax.jdo.JDOFatalException; 28 import javax.jdo.Query; 29 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 33 import junit.framework.TestSuite; 34 import junit.textui.TestRunner; 35 import junit.framework.Assert; 36 37 42 public class TestQuery extends LinkedIntUserIdHelper { 43 public static int RESULT_MAX = 1000; 44 45 public TestQuery(String s) { 46 super(s); 47 } 48 49 protected String getLoggerName() { 50 return STRESS_LOG_NAME + ".TestQuery"; 51 } 52 53 public static void main(String [] args) { 54 TestRunner.run(new TestSuite(TestQuery.class)); 55 } 56 57 protected void perform(StressHelper.Task task, 58 int threadId, 59 int txId, 60 Object _ctx, 61 StressHelper.PerformResult res) { 62 LIUICtx ctx = (LIUICtx) _ctx; 63 PersistenceManager pm = getPM(task, threadId, txId); 64 try { 65 res.beginTest(); 66 beginTx(pm, task, threadId, txId); 67 int min = Alea.rand(0, ctx.dbSize - RESULT_MAX); 68 if (min > ctx.dbSize - 1) { 69 min = 0; 70 } 71 int max = Alea.rand(min + 1, min + RESULT_MAX); 72 if (max > ctx.dbSize - 1) { 73 max = ctx.dbSize - 1; 74 } 75 if (debug) { 76 logger.log(BasicLevel.DEBUG, "Thread " + threadId 77 + " min = " + min + " / max = " + max); 78 } 79 Extent liui = pm.getExtent(LinkedIntUserId.class, false); 80 String filter = "((name>min) && (name<max))"; 81 Query query = pm.newQuery(liui, filter); 82 query.declareParameters("Integer min, Integer max"); 83 Collection cLinkedUsers = (Collection ) query.execute(new Integer (min), new Integer (max)); 84 Iterator iterator = cLinkedUsers.iterator(); 85 while (iterator.hasNext()) { 86 LinkedIntUserId lLinkedIntUserId = (LinkedIntUserId) iterator.next(); 87 int i = lLinkedIntUserId.getName(); 88 if (debug) { 89 logger.log(BasicLevel.DEBUG, "Thread " + threadId 90 + " Name = " + i); 91 } 92 } 93 Assert.assertEquals("Bad query result size", max - min - 1, cLinkedUsers.size()); 94 query.closeAll(); 95 commitTx(pm, task, threadId, txId); 96 res.endTest(); 97 } catch (JDOFatalException e) { 98 rollbackOnException(pm, e, res, task, threadId, txId); 99 } catch (Throwable e) { 100 stopOnError(pm, e, res, task, threadId, txId); 101 } finally { 102 closePM(pm, threadId, txId, task, res); 103 } 104 } 105 106 protected void performQuery(int nbThread, 107 int dbSize, 108 int nbTx, 109 int threadTimeout) { 110 perform(nbThread, nbTx, threadTimeout, new LIUICtx(dbSize)); 111 } 112 113 114 118 public void testQuery() { 119 if (interactive) { 120 perform(Integer.getInteger(THREAD, 10).intValue(), 121 Integer.getInteger(TX, 100).intValue(), 122 Integer.getInteger(TIMEOUT, 200000).intValue(), 123 new LIUICtx( 124 Integer.getInteger(DBSIZE, 100000).intValue())); 125 } 126 } 127 128 131 public void testQueryTh1Tx100Qu1() { 132 if (!interactive) { 133 performQuery(1, 10000, 100, 1000000); 134 } 135 } 136 137 140 141 public void testQueryTh1Tx1000Qu1() { 142 if (!interactive) { 143 performQuery(1, 10000, 1000, 1000000); 144 } 145 } 146 147 150 151 public void testQueryTh1Tx10000Qu1() { 152 if (!interactive) { 153 performQuery(1, 10000, 10000, 1000000); 154 } 155 } 156 157 160 161 public void testQueryTh1Tx100000Qu1() { 162 if (!interactive) { 163 performQuery(1, 10000, 100000, 1000000); 164 } 165 } 166 167 170 public void testQueryTh10Tx100Qu1() { 171 if (!interactive) { 172 performQuery(10, 10000, 100, 1000000); 173 } 174 } 175 176 179 180 public void testQueryTh10Tx1000Qu1() { 181 if (!interactive) { 182 performQuery(10, 1000, 1000, 1000000); 183 } 184 } 185 186 189 190 public void testQueryTh10Tx10000Qu1() { 191 if (!interactive) { 192 performQuery(10, 10000, 10000, 1000000); 193 } 194 } 195 196 199 200 public void testQueryTh10Tx100000Qu1() { 201 if (!interactive) { 202 performQuery(10, 10000, 100000, 1000000); 203 } 204 } 205 } 206 | Popular Tags |