1 4 5 package org.objectweb.perseus.fos; 6 7 import junit.framework.Test; 8 import junit.framework.TestSuite; 9 import junit.textui.TestRunner; 10 import org.objectweb.perseus.LogBoot; 11 import org.objectweb.perseus.fos.api.FosException; 12 import org.objectweb.perseus.fos.api.FosTransaction; 13 import org.objectweb.perseus.fos.lib.FosTxContextFactory; 14 15 import java.util.Iterator ; 16 17 21 public class TestTxOpsUniqMan extends TestTxOps { 22 24 27 protected void setUp() { 28 } 29 30 33 protected void tearDown() { 34 } 35 36 39 public void testRollbackCreation() { 40 try { 41 FosTransaction ft = fm.createTxContext(); 42 ft.begin(); 43 if (ft.exist(POBJDIR, pobjId[0])) 44 ft.delete(POBJDIR, pobjId[0]); 45 ft.commit(); 46 ft.begin(); 47 ft.write(POBJDIR, pobjId[0], pobjVal[0], null); 48 ft.rollback(); 49 ft.begin(); 50 boolean ex = ft.exist(POBJDIR, pobjId[0]); 51 ft.commit(); 52 fm.releaseTxContext(ft); 53 if (ex) 54 fail("Object should not exist: creation rolled back!"); 55 } catch (FosException fe) { 56 if (fe.getNestedException() != null) 57 fe.getNestedException().printStackTrace(); 58 fe.printStackTrace(); 59 fail(); 60 } 61 } 62 63 66 public void testRollbackCreations() { 67 try { 68 FosTransaction ft = fm.createTxContext(); 69 ft.begin(); 70 for (int i = 0; i < pobjId.length; i++) 71 if (ft.exist(POBJDIR, pobjId[i])) 72 ft.delete(POBJDIR, pobjId[i]); 73 ft.commit(); 74 ft.begin(); 75 for (int i = 0; i < pobjId.length; i++) 76 ft.write(POBJDIR, pobjId[i], pobjVal[i], null); 77 ft.rollback(); 78 ft.begin(); 79 boolean ex = false; 80 for (int i = 0; i < pobjId.length; i++) 81 ex |= ft.exist(POBJDIR, pobjId[i]); 82 ft.commit(); 83 fm.releaseTxContext(ft); 84 if (ex) 85 fail("Objects should not exist: creations rolled back!"); 86 } catch (FosException fe) { 87 if (fe.getNestedException() != null) 88 fe.getNestedException().printStackTrace(); 89 fe.printStackTrace(); 90 fail(); 91 } 92 } 93 94 97 public void testExistNoObj() { 98 try { 99 FosTransaction ft = fm.createTxContext(); 100 ft.begin(); 101 try { 102 ft.delete(POBJDIR, pobjId[0]); 103 } catch (FosException fe) { 104 } 105 ft.commit(); 106 ft.begin(); 107 boolean ex = ft.exist(POBJDIR, pobjId[0]); 108 ft.commit(); 109 fm.releaseTxContext(ft); 110 if (ex) 111 fail("Objects should not exist: no object!"); 112 } catch (FosException fe) { 113 if (fe.getNestedException() != null) 114 fe.getNestedException().printStackTrace(); 115 fe.printStackTrace(); 116 fail(); 117 } 118 } 119 120 123 public void testScanNoObj() { 124 try { 125 FosTransaction ft = fm.createTxContext(); 126 ft.begin(); 127 for (int i = 0; i < pobjId.length; i++) 128 if (ft.exist(POBJDIR, pobjId[i])) 129 ft.delete(POBJDIR, pobjId[i]); 130 ft.commit(); 131 ft.begin(); 132 Iterator it = ft.scan(POBJDIR); 133 ft.commit(); 134 fm.releaseTxContext(ft); 135 if (it.hasNext()) 136 fail("Extension is not composed as required."); 137 } catch (FosException fe) { 138 if (fe.getNestedException() != null) 139 fe.getNestedException().printStackTrace(); 140 fe.printStackTrace(); 141 fail(); 142 } 143 } 144 145 147 151 public static Test suite() { 152 return new TestSuite(TestTxOpsUniqMan.class); 153 } 154 155 158 public static void main(String args[]) { 159 TestRunner.run(suite()); 160 } 161 162 165 public TestTxOpsUniqMan(String tn) throws Exception { 166 super(tn); 167 try { 168 fm = new FosTxContextFactory(); 169 fm.setDbDir(dbDir); 170 fm.setMonologFactory(LogBoot.getLoggerFactory()); 171 fm.initialize(); 172 fm.start(); 173 } catch (FosException fe) { 174 System.out.println("Error during setUp - 1"); 175 if (fe.getNestedException() != null) 176 fe.getNestedException().printStackTrace(); 177 fe.printStackTrace(); 178 System.exit(0); 179 } catch (Exception e) { 180 System.out.println("Error during setUp - 2"); 181 e.printStackTrace(); 182 System.exit(0); 183 } 184 } 185 } | Popular Tags |