1 24 package org.objectweb.jalisto.se.test.threads; 25 26 import org.objectweb.jalisto.se.test.data.Book; 27 import org.objectweb.jalisto.se.test.workbench.JalistoTimer; 28 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import java.util.Random ; 32 33 public class BookClientBasic extends BookClientThread { 34 35 public BookClientBasic(String jalistoPropertiesFilename, int numClient, 36 int nbrBook, int nbrAction, int nbrIteration) { 37 super(jalistoPropertiesFilename, numClient, nbrBook, nbrAction, nbrIteration); 38 } 39 40 41 public void stabilityTest() { 42 System.out.println("BookClientBasic " + numClient + " starts stability test"); 43 44 String timerNameCreate = "BookClientBasic - create " + nbrCreate + " - " + numClient; 45 String timerNameRead = "BookClientBasic - read " + nbrRead + " - " + numClient; 46 String timerNameUpdate = "BookClientBasic - update " + nbrUpdate + " - " + numClient; 47 String timerNameDelete = "BookClientBasic - delete " + nbrDelete + " - " + numClient; 48 if (withTimer) { 49 if (nbrCreate > 0) { 50 JalistoTimer.createTimer(timerNameCreate); 51 } 52 if (nbrDelete > 0) { 53 JalistoTimer.createTimer(timerNameDelete); 54 } 55 if (nbrRead > 0) { 56 JalistoTimer.createTimer(timerNameRead); 57 } 58 if (nbrUpdate > 0) { 59 JalistoTimer.createTimer(timerNameUpdate); 60 } 61 } 62 63 Random random = new Random (); 64 65 for (int c = 0; ((nbrIteration < 0) || (c < nbrIteration)) && continueWorking; c++) { 66 if (withTimer && (c != 0) && ((c % 50) == 0)) { 67 System.out.println(""); 68 if (nbrCreate > 0) { 69 JalistoTimer.summary(timerNameCreate); 70 JalistoTimer.clean(timerNameCreate); 71 } 72 if (nbrRead > 0) { 73 JalistoTimer.summary(timerNameRead); 74 JalistoTimer.clean(timerNameRead); 75 } 76 if (nbrUpdate > 0) { 77 JalistoTimer.summary(timerNameUpdate); 78 JalistoTimer.clean(timerNameUpdate); 79 } 80 if (nbrDelete > 0) { 81 JalistoTimer.summary(timerNameDelete); 82 JalistoTimer.clean(timerNameDelete); 83 } 84 } 85 86 if (withExtent) { 87 tx.begin(); 88 oids = new ArrayList (); 89 oids.addAll(session.getExtent(Book.class).readFully().collection()); 90 tx.commit(); 91 } 92 93 if (nbrCreate > 0) { 94 if (withTimer) { 95 JalistoTimer.timerStart(timerNameCreate); 96 } 97 List newOids = new ArrayList (); 98 tx.begin(); 99 for (int i = 0; i < nbrCreate; i++) { 100 Object [] bookInArray = Book.newBook().toArray(); 101 Object oid = session.createObject(bookInArray, Book.class); 102 newOids.add(oid); 103 } 104 tx.commit(); 105 if (withTimer) { 106 JalistoTimer.timerStop(timerNameCreate, false); 107 } 108 synchronized (oids) { 109 oids.addAll(newOids); 110 } 111 } 112 113 if (nbrRead > 0) { 114 if (withTimer) { 115 JalistoTimer.timerStart(timerNameRead); 116 } 117 tx.begin(); 118 Object oid; 119 for (int i = 0; i < nbrRead; i++) { 120 synchronized (oids) { 121 int index = random.nextInt(oids.size()); 122 oid = oids.get(index); 123 session.readObjectByOid(oid); 124 } 125 } 126 tx.commit(); 127 if (withTimer) { 128 JalistoTimer.timerStop(timerNameRead, false); 129 } 130 } 131 132 if (nbrUpdate > 0) { 133 if (withTimer) { 134 JalistoTimer.timerStart(timerNameUpdate); 135 } 136 tx.begin(); 137 Object oid; 138 for (int i = 0; i < nbrUpdate; i++) { 139 synchronized (oids) { 140 int index = random.nextInt(oids.size()); 141 oid = oids.get(index); 142 Object [] book = session.readObjectByOid(oid); 143 book[0] = book[0] + "u_" + numClient; 144 session.updateObjectByOid(oid, book); 145 } 146 } 147 tx.commit(); 148 if (withTimer) { 149 JalistoTimer.timerStop(timerNameUpdate, false); 150 } 151 } 152 153 if (nbrDelete > 0) { 154 if (withTimer) { 155 JalistoTimer.timerStart(timerNameDelete); 156 } 157 tx.begin(); 158 Object oid; 159 for (int i = 0; i < nbrDelete; i++) { 160 synchronized (oids) { 161 int index = random.nextInt(oids.size()); 162 oid = oids.remove(index); 163 } 164 session.deleteObjectByOid(oid); 165 } 166 tx.commit(); 167 if (withTimer) { 168 JalistoTimer.timerStop(timerNameDelete, false); 169 } 170 } 171 } 172 173 System.out.println("BookClientBasic " + numClient + " ends stability test"); 174 } 175 176 177 } 178 | Popular Tags |