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.exception.JalistoException; 29 import org.objectweb.jalisto.se.test.data.Book; 30 import org.objectweb.jalisto.se.test.threads.BookClientBasic; 31 32 import java.util.ArrayList ; 33 34 public class ReadOnlyMultiUsersTest { 35 public static void main(String [] args) { 36 String jalistoPropertiesFilename = args[0]; 37 String jalistoPropertiesFilenamePre = args[1]; 38 int nbrInstance = Integer.parseInt(args[2]); 39 int nbrClient = Integer.parseInt(args[3]); 40 int nbrRead = Integer.parseInt(args[4]); 41 int nbrIteration = Integer.parseInt(args[5]); 42 43 ArrayList threads = new ArrayList (); 44 ArrayList oids = new ArrayList (); 45 46 System.out.println("ReadOnlyMultiUsersTest : use " + jalistoPropertiesFilename); 47 48 System.out.println("get extent..."); 49 Session session = getSession(jalistoPropertiesFilename, jalistoPropertiesFilenamePre, nbrInstance); 50 session.currentTransaction().begin(); 51 oids.addAll(session.getExtent(Book.class).readFully().collection()); 52 session.currentTransaction().commit(); 53 54 System.out.println("reduce oids collection size to " + nbrInstance + " books..."); 55 if (oids.size() > nbrInstance) { 56 ArrayList tmp = new ArrayList (); 57 while (tmp.size() < nbrInstance) { 58 tmp.add(oids.remove(0)); 59 } 60 oids = tmp; 61 System.gc(); 62 System.runFinalization(); 63 System.gc(); 64 } 65 66 System.out.println("test : " + nbrRead + " for each of the " + nbrIteration + " iteration"); 67 68 System.out.println("create " + nbrClient + " clients..."); 69 for (int i = 0; i < nbrClient; i++) { 70 BookClientBasic c = new BookClientBasic( 71 jalistoPropertiesFilename, i, -1, nbrRead, nbrIteration); 72 c.setNbrCreate(-1); 73 c.setNbrDelete(-1); 74 c.setNbrUpdate(-1); 75 threads.add(c); 76 c.define(false); 77 c.setOids(oids); 78 } 79 80 System.out.println("start clients..."); 81 try { 82 for (int i = 0; i < nbrClient; i++) { 83 ((BookClientBasic) threads.get(i)).start(); 84 } 85 } catch (Exception e) { 86 e.printStackTrace(); 87 } 88 } 89 90 91 private static Session getSession(String propFileName, String propFileNamePre, int nbrInstance) { 92 try { 93 return JalistoFactory.getSession(propFileName); 94 } catch (JalistoException jalistoExc) { 95 System.out.println("need to create datas..."); 96 Session prepareSession = JalistoFactory.getSession(propFileNamePre); 97 prepareSession.defineClass(Book.getMetaDescription()); 98 prepareSession.currentTransaction().begin(); 99 for (int i = 0; i < nbrInstance; i++) { 100 prepareSession.createObject(Book.newBook().toArray(), Book.class); 101 } 102 prepareSession.currentTransaction().commit(); 103 System.out.println("datas created !"); 104 return JalistoFactory.getSession(propFileName); 105 } 106 } 107 } 108 | Popular Tags |