1 64 65 package com.jcorporate.expresso.ext.tests; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 69 import com.jcorporate.expresso.core.misc.ConfigManager; 70 import com.jcorporate.expresso.core.misc.ConfigurationException; 71 import com.jcorporate.expresso.kernel.ConsoleInstallLog; 72 import com.jcorporate.expresso.kernel.InstallLog; 73 import com.jcorporate.expresso.services.test.ExpressoTestCase; 74 import com.jcorporate.expresso.services.test.SchemaCreator; 75 import com.jcorporate.expresso.services.test.TestSystemInitializer; 76 import junit.framework.TestSuite; 77 78 import java.util.ArrayList ; 79 import java.util.Iterator ; 80 81 82 88 public class DBObjStressTest 89 extends ExpressoTestCase { 90 static final int NUM_THREADS = 1; 91 static final int NUM_ITERATIONS = 10; 92 private long startTime = 0; 93 private ArrayList threadList = new ArrayList (NUM_THREADS); 94 95 public DBObjStressTest(String testName) 96 throws Exception { 97 super(testName); 98 } 99 100 public static void main(String [] args) 101 throws Exception { 102 103 junit.textui.TestRunner.run(suite()); 105 } 106 107 112 public static junit.framework.Test suite() { 113 TestSuite suite = new TestSuite(DBObjStressTest.class); 114 115 return suite; 116 } 117 118 119 public void testStressDBObjects() { 120 System.out.println("Starting testStressDBObjects()"); 121 122 for (int i = 0; i < NUM_THREADS; i++) { 123 StressThread st = new StressThread(NUM_ITERATIONS, 124 SecuredDBObject.SYSTEM_ACCOUNT); 125 threadList.add(st); 126 st.start(); 127 } 128 129 boolean successfullOperation = true; 130 131 for (Iterator i = threadList.iterator(); i.hasNext();) { 132 System.out.println("Waiting for thread"); 133 134 StressThread st = (StressThread) i.next(); 135 136 try { 137 if (st.isAlive()) { 138 st.join(); 139 } 140 } catch (InterruptedException ie) { 141 } 142 143 assertTrue("Thread is dead", !st.isAlive()); 144 successfullOperation &= st.getSuccess(); 145 } 146 147 assertTrue("All Threads Successfull", successfullOperation == true); 148 149 try { 150 StressTestObject sto = new StressTestObject(SecuredDBObject.SYSTEM_ACCOUNT); 151 sto.setDataContext(TestSystemInitializer.getTestContext()); 152 assertTrue("Check all records deleted", sto.count() == 0); 153 } catch (DBException dbe) { 154 dbe.printStackTrace(); 155 fail("Caught DBException trying to count records. " + 156 dbe.getMessage()); 157 } 158 } 159 160 164 protected void setUp() 165 throws Exception { 166 TestSystemInitializer.setUp(); 167 try { 168 ConfigManager.getContext(TestSystemInitializer.getTestContext()); 169 } catch (ConfigurationException ce) { 170 fail("There is no 'test' db/context set up - cannot run db object tests without a test context"); 171 } 172 173 InstallLog installLog = new ConsoleInstallLog(); 174 175 StressTestSchema ts = new StressTestSchema(); 176 SchemaCreator.ensureSchemaExists(new com.jcorporate.expresso.core.ExpressoSchema(), installLog); 177 SchemaCreator.ensureSchemaExists(ts, installLog); 178 startTime = new java.util.Date ().getTime(); 179 } 180 181 182 186 protected void tearDown() 187 throws Exception { 188 long endTime = new java.util.Date ().getTime(); 189 System.out.println("Current Threading Tests Took: " + 190 Long.toString(endTime - startTime) + " ms."); 191 192 ConfigManager.destroy(); 194 195 } 203 204 205 } | Popular Tags |