1 64 65 package com.jcorporate.expresso.ext.tests; 66 67 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 68 import com.jcorporate.expresso.core.misc.ConfigManager; 69 import com.jcorporate.expresso.core.misc.ConfigurationException; 70 import com.jcorporate.expresso.services.dbobj.DefaultUserInfo; 71 import com.jcorporate.expresso.services.dbobj.MimeTypes; 72 import com.jcorporate.expresso.services.test.ExpressoTestCase; 73 import com.jcorporate.expresso.services.test.TestSystemInitializer; 74 import junit.framework.TestSuite; 75 76 85 86 public class RetrieveThroughputTest extends ExpressoTestCase { 87 static final int NUM_ITERATIONS = 1000; 88 private long startTime = 0; 89 90 91 public RetrieveThroughputTest(String testName) 92 throws Exception { 93 super(testName); 94 } 95 96 public static void main(String [] args) 97 throws Exception { 98 99 junit.textui.TestRunner.run(suite()); 101 } 102 103 108 public static junit.framework.Test suite() { 109 TestSuite suite = new TestSuite(RetrieveThroughputTest.class); 110 111 return suite; 112 } 113 114 118 protected void setUp() 119 throws Exception { 120 TestSystemInitializer.setUp(); 121 try { 122 ConfigManager.getContext(TestSystemInitializer.getTestContext()); 123 } catch (ConfigurationException ce) { 124 fail("There is no 'test' db/context set up - cannot run db object tests without a test context"); 125 } 126 127 startTime = new java.util.Date ().getTime(); 131 } 132 133 public void testRetrieve() { 134 try { 135 MimeTypes mt = new MimeTypes(SecuredDBObject.SYSTEM_ACCOUNT); 136 mt.setDataContext(TestSystemInitializer.getTestContext()); 137 mt.setField(MimeTypes.FLD_MIMENUMBER, 1); 138 mt.retrieve(); 139 startTime = System.currentTimeMillis(); 140 for (int i = 0; i < NUM_ITERATIONS; i++) { 141 mt.retrieve(); 142 } 143 long endTime = System.currentTimeMillis(); 144 System.out.println( 145 "Throughput for retrieving MimeTypes was: " + (endTime - startTime) / NUM_ITERATIONS + " ms per retrieval"); 146 147 148 DefaultUserInfo dui = new DefaultUserInfo(SecuredDBObject.SYSTEM_ACCOUNT); 149 dui.setDataContext(TestSystemInitializer.getTestContext()); 150 dui.setField(DefaultUserInfo.EXPUID, 3); 151 dui.retrieve(); 152 startTime = System.currentTimeMillis(); 153 for (int i = 0; i < NUM_ITERATIONS; i++) { 154 dui.retrieve(); 155 } 156 endTime = System.currentTimeMillis(); 157 System.out.println( 158 "Throughput for retrieving DefaultUserInfo was: " + (endTime - startTime) / NUM_ITERATIONS + " ms per retrieval"); 159 160 } catch (Exception e) { 161 e.printStackTrace(); 162 fail("Exception caught while testing"); 163 } 164 165 } 166 167 } | Popular Tags |