1 24 package org.objectweb.jalisto.test.core.suite; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.JalistoFactory; 28 import org.objectweb.jalisto.se.test.data.Book; 29 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase; 30 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 31 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.Random ; 35 36 public class RestructureTestCase extends JalistoTestCase { 37 38 public RestructureTestCase() { 39 } 40 41 public RestructureTestCase(String name) { 42 super(name); 43 } 44 45 public static Test suite() { 46 JalistoTestSuite suite = new JalistoTestSuite(); 47 RestructureTestCase tc = (RestructureTestCase) newTestCase(suite, new RestructureTestCase()); 48 49 tc.newSession(); 50 tc.define(); 51 52 tc.cleanUp(); 53 54 tc.populate(500); 55 56 tc.stabilityTest(50, 100); 57 tc.reorganize(); 58 59 tc.cleanUp(); 60 tc.reorganize(); 61 62 tc.finishTests(); 63 64 return suite; 65 } 66 67 70 71 public void newSession() { 72 System.gc(); 73 session = JalistoFactory.getSession(getJalistoPropertiesFilename()); 74 session.openSession(); 75 tx = session.currentTransaction(); 76 } 77 78 public void define() { 79 session.defineClass(Book.getMetaDescription()); 80 } 81 82 public void reorganize() { 83 if (session.getInternalSession().getProperties().allowsSpecialFunctionnalities()) { 84 session.closeSession(); 85 session.reorganize(); 86 session.openSession(); 87 } else { 88 System.out.println("not allows reorganize functionnality"); 89 } 90 } 91 92 public void cleanUp() { 93 oids = new ArrayList (); 94 tx.begin(); 95 Iterator extent = session.getExtent(Book.class).readFully().iterator(); 96 while (extent.hasNext()) { 97 Object oid = extent.next(); 98 session.deleteObjectByOid(oid); 99 } 100 tx.commit(); 101 } 102 103 public void populate(int nbrBook) { 104 tx.begin(); 105 for (int i = 0; i < nbrBook; i++) { 106 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 107 } 108 tx.commit(); 109 } 110 111 public void stabilityTest(int nbrCreate, int nbrIt) { 112 Random random = new Random (); 113 114 for (int c = 0; c < nbrIt; c++) { 115 tx.begin(); 116 for (int i = 0; i < nbrCreate; i++) { 117 Object [] bookInArray = Book.newBook().toArray(); 118 Object oid = session.createObject(bookInArray, Book.class); 119 oids.add(oid); 120 } 121 tx.commit(); 122 123 tx.begin(); 124 for (int i = 0; i < nbrCreate; i++) { 125 int index = random.nextInt(oids.size()); 126 Object oid = oids.get(index); 127 session.readObjectByOid(oid); 128 } 129 tx.commit(); 130 } 131 } 132 133 public void finishTests() { 134 if ((session != null) && (session.isOpen())) { 135 session.closeSession(); 136 } 137 } 138 139 ArrayList oids = null; 140 } 141 | Popular Tags |