1 24 package org.objectweb.jalisto.test.core.single; 25 26 import org.objectweb.jalisto.se.JalistoFactory; 27 import org.objectweb.jalisto.se.api.Session; 28 import org.objectweb.jalisto.se.api.Transaction; 29 import org.objectweb.jalisto.se.test.data.Book; 30 import org.objectweb.jalisto.se.test.workbench.JalistoTimer; 31 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.Random ; 35 36 public class OneClientTest { 37 public static void main(String [] args) { 38 String jalistoPropertiesFilename = args[0]; 39 int nbrIteration = Integer.parseInt(args[1]); 40 int nbrBook = Integer.parseInt(args[2]); 41 int nbrRead = Integer.parseInt(args[3]); 42 int nbrCreate = Integer.parseInt(args[4]); 43 int nbrDelete = Integer.parseInt(args[5]); 44 45 OneClientTest client = new OneClientTest(jalistoPropertiesFilename, nbrBook, 0, nbrIteration); 46 client.setWithTimer(true); 47 client.setNbrRead(nbrRead); 48 client.setNbrCreate(nbrCreate); 49 client.setNbrDelete(nbrDelete); 50 client.define(true); 51 client.populate(); 52 53 client.stabilityTest(); 54 } 55 56 public OneClientTest(String jalistoPropertiesFilename, int nbrBook, int nbrAction, int nbrIteration) { 57 this.jalistoPropertiesFilename = jalistoPropertiesFilename; 58 this.nbrBook = nbrBook; 59 this.nbrCreate = nbrAction; 60 this.nbrRead = nbrAction; 61 this.nbrDelete = nbrAction; 62 this.nbrIteration = nbrIteration; 63 oids = new ArrayList (); 64 } 65 66 public void define(boolean withDefineClass) { 67 System.out.println("OneClientTest : define"); 68 session = JalistoFactory.getSession(jalistoPropertiesFilename); 69 session.openSession(); 70 tx = session.currentTransaction(); 71 if (withDefineClass) { 72 session.defineClass(Book.getMetaDescription()); 73 } 74 } 75 76 public void cleanUp() { 77 tx.begin(); 78 Iterator extent = session.getExtent(Book.class).readFully().iterator(); 79 while (extent.hasNext()) { 80 session.deleteObjectByOid(extent.next()); 81 } 82 tx.commit(); 83 session.reorganize(); 84 } 85 86 public void populate() { 87 System.out.println("OneClientTest : populate " + nbrBook); 88 tx.begin(); 89 if (nbrBook > 0) { 90 for (int i = 0; i < nbrBook; i++) { 91 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 92 } 93 } else { 94 oids.addAll(session.getExtent(Book.class).readFully().collection()); 95 } 96 tx.commit(); 97 } 98 99 public void stabilityTest() { 100 System.out.println("OneClientTest "); 101 102 JalistoFactory.launchJMXServer(session); 103 104 String timerNameCreate = "BookClientBasic execution cycle - create " + nbrCreate; 105 String timerNameRead = "BookClientBasic execution cycle - read " + nbrRead; 106 String timerNameDelete = "BookClientBasic execution cycle - delete " + nbrDelete; 107 if (withTimer) { 108 JalistoTimer.createTimer(timerNameCreate); 109 JalistoTimer.createTimer(timerNameDelete); 110 JalistoTimer.createTimer(timerNameRead); 111 } 112 JalistoTimer.createTimer("get floid"); 113 JalistoTimer.createTimer("read"); 114 115 Random random = new Random (); 116 117 for (int c = 0; (nbrIteration < 0) || (c < nbrIteration); c++) { 118 if (withTimer && (c != 0) && ((c % 50) == 0)) { 119 System.out.println(""); 120 JalistoTimer.summary(); 121 JalistoTimer.clean(timerNameCreate); 122 JalistoTimer.clean(timerNameRead); 123 JalistoTimer.clean(timerNameDelete); 124 } 125 126 if (nbrCreate > 0) { 127 if (withTimer) { 128 JalistoTimer.timerStart(timerNameCreate); 129 } 130 tx.begin(); 131 for (int i = 0; i < nbrCreate; i++) { 132 Object [] bookInArray = Book.newBook().toArray(); 133 Object oid = session.createObject(bookInArray, Book.class); 134 oids.add(oid); 135 } 136 tx.commit(); 137 if (withTimer) { 138 JalistoTimer.timerStop(timerNameCreate, false); 139 } 140 } 141 142 if (nbrRead > 0) { 143 if (withTimer) { 144 JalistoTimer.timerStart(timerNameRead); 145 } 146 tx.begin(); 147 for (int i = 0; i < nbrRead; i++) { 148 int index = random.nextInt(oids.size()); 149 Object oid = oids.get(index); 150 session.readObjectByOid(oid); 151 } 152 tx.commit(); 153 if (withTimer) { 154 JalistoTimer.timerStop(timerNameRead, false); 155 } 156 } 157 158 if (nbrDelete > 0) { 159 if (withTimer) { 160 JalistoTimer.timerStart(timerNameDelete); 161 } 162 tx.begin(); 163 for (int i = 0; i < nbrDelete; i++) { 164 int index = random.nextInt(oids.size()); 165 Object oid = oids.get(index); 166 session.deleteObjectByOid(oid); 167 oids.remove(index); 168 } 169 tx.commit(); 170 if (withTimer) { 171 JalistoTimer.timerStop(timerNameDelete, false); 172 } 173 } 174 } 175 176 session.closeSession(); 177 } 178 179 180 public void setWithTimer(boolean withTimer) { 181 this.withTimer = withTimer; 182 } 183 184 public void setWithRead(boolean withRead) { 185 this.withRead = withRead; 186 } 187 188 public void setNbrCreate(int nbrCreate) { 189 this.nbrCreate = nbrCreate; 190 } 191 192 public void setNbrDelete(int nbrDelete) { 193 this.nbrDelete = nbrDelete; 194 } 195 196 public void setNbrRead(int nbrRead) { 197 this.nbrRead = nbrRead; 198 } 199 200 201 protected ArrayList oids; 202 203 protected int nbrBook; 204 protected int nbrIteration; 205 protected int nbrCreate; 206 protected int nbrRead; 207 protected int nbrDelete; 208 209 protected boolean withTimer = true; 210 protected boolean withRead = false; 211 212 protected String jalistoPropertiesFilename; 213 protected Session session; 214 protected Transaction tx; 215 } 216 | Popular Tags |