1 24 package org.objectweb.jalisto.test.core.suite; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.exception.IdentityException; 28 import org.objectweb.jalisto.se.exception.remote.RemoteException; 29 import org.objectweb.jalisto.se.test.data.Book; 30 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase; 31 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 32 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 36 public class RollbackTestCase extends JalistoTestCase { 37 38 public RollbackTestCase() { 39 } 40 41 public RollbackTestCase(String name) { 42 super(name); 43 } 44 45 public static Test suite() { 46 JalistoTestSuite suite = new JalistoTestSuite(); 47 RollbackTestCase tc = (RollbackTestCase) newTestCase(suite, new RollbackTestCase()); 48 49 tc.define(); 50 tc.cleanUp(); 51 52 tc.populateRollback(700); 53 tc.checkCard(0); 54 55 tc.populate(1000); 56 tc.checkCard(1000); 57 58 tc.deleteRollback(500); 59 tc.checkCard(1000); 60 61 tc.delete(500); 62 tc.checkCard(500); 63 64 tc.cleanUp(); 65 tc.populateRollback(3000); 66 tc.checkCard(0); 67 68 tc.populate(3000); 69 tc.checkCard(3000); 70 71 tc.cleanUp(); 72 tc.testMakeOidRollback(1000); 73 74 tc.cleanUp(); 75 tc.createOverInstancePageSize(); 76 77 tc.cleanUp(); 78 tc.finishTests(); 79 80 return suite; 81 } 82 83 public void populateRollback(int nbr) { 84 tx.begin(); 85 for (int i = 0; i < nbr; i++) { 86 session.createObject(Book.newBook().toArray(), Book.class); 87 } 88 tx.rollback(); 89 } 90 91 public void checkCard(int card) { 92 tx.begin(); 93 assertEquals("should contains " + card + " books", card, session.getExtent(Book.class).readFully().size()); 94 tx.commit(); 95 } 96 97 public void deleteRollback(int card) { 98 tx.begin(); 99 Iterator extentIt = session.getExtent(Book.class).readFully().iterator(); 100 int i = 0; 101 while (extentIt.hasNext() && (i < card)) { 102 session.deleteObjectByOid(extentIt.next()); 103 i++; 104 } 105 tx.rollback(); 106 } 107 108 public void delete(int card) { 109 tx.begin(); 110 Iterator extentIt = session.getExtent(Book.class).readFully().iterator(); 111 int i = 0; 112 while (extentIt.hasNext() && (i < card)) { 113 session.deleteObjectByOid(extentIt.next()); 114 i++; 115 } 116 tx.commit(); 117 } 118 119 public void makeFloidRollback(int nbr) { 120 tx.begin(); 121 for (int i = 0; i < nbr; i++) { 122 session.makeNewFileOid(Book.class); 123 } 124 tx.rollback(); 125 } 126 127 public void testMakeOidRollback(int nbr) { 128 ArrayList oids = new ArrayList (); 129 tx.begin(); 130 for (int i = 0; i < nbr; i++) { 131 oids.add(session.makeNewFileOid(Book.class)); 132 } 133 tx.rollback(); 134 135 tx.begin(); 136 assertEquals("should be equal", 0, session.getExtent(Book.class).readFully().size()); 137 tx.commit(); 138 139 tx.begin(); 140 for (int i = 0; i < oids.size(); i++) { 141 Object oid = oids.get(i); 142 try { 143 session.deleteObjectByOid(oid); 144 if (!session.getInternalSession().isRemoteSession()) { 145 assertTrue("must raise exception", false); 146 } 147 } catch (IdentityException jalistoIdentityExc) { 148 assertEquals("should be equal", "the given oid " + oid + " doesn't exist in this Jalisto datastore", 149 jalistoIdentityExc.getMessage()); 150 } 151 } 152 try { 153 tx.commit(); 154 } catch (RemoteException jalistoRemoteExc) { 155 if (session.getInternalSession().isRemoteSession()) { 156 assertTrue("should be equal", jalistoRemoteExc.getMessage().startsWith("the given oid ") && 157 jalistoRemoteExc.getMessage().endsWith(" doesn't exist in this Jalisto datastore")); 158 tx.rollback(); 159 } 160 } 161 } 162 163 public void createOverInstancePageSize() { 164 int size = session.getInternalSession().getProperties().getInstancePageSize() * 2; 165 ArrayList oids = new ArrayList (); 166 tx.begin(); 167 for (int i = 0; i < size; i++) { 168 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 169 } 170 tx.rollback(); 171 172 tx.begin(); 173 for (int i = 0; i < oids.size(); i++) { 174 Object oid = oids.get(i); 175 try { 176 session.deleteObjectByOid(oid); 177 } catch (IdentityException jalistoIdentityExc) { 178 assertEquals("should be equal", "the given oid " + oid + " doesn't exist in this Jalisto datastore", 179 jalistoIdentityExc.getMessage()); 180 } 181 } 182 tx.commit(); 183 oids.clear(); 184 185 tx.begin(); 186 for (int i = 0; i < size; i++) { 187 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 188 } 189 tx.commit(); 190 191 tx.begin(); 192 for (int i = 0; i < oids.size(); i++) { 193 session.deleteObjectByOid(oids.get(i)); 194 } 195 tx.commit(); 196 } 197 198 199 202 203 public void define() { 204 super.initSession(false); 205 super.define(Book.getMetaDescription()); 206 } 207 208 public void cleanUp() { 209 super.cleanUp(Book.class); 210 } 211 212 public void populate(int nbr) { 213 super.populate(nbr); 214 } 215 216 public void finishTests() { 217 super.finishTests(); 218 } 219 } 220 | Popular Tags |