1 56 package org.opencrx.demo.kernel; 57 58 import java.util.Collection ; 59 import java.util.Iterator ; 60 61 import javax.naming.Context ; 62 import javax.naming.InitialContext ; 63 import javax.naming.NamingException ; 64 65 import org.opencrx.kernel.client.ClientHelper; 66 import org.openmdx.base.accessor.generic.cci.ObjectFactory_1_0; 67 import org.openmdx.base.accessor.jmi.cci.JmiServiceException; 68 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0; 69 import org.openmdx.base.accessor.jmi.spi.RefRootPackage_1; 70 import org.openmdx.base.exception.ServiceException; 71 72 public class StressTester { 73 74 public static void main( 76 String [] args 77 ) { 78 try { 79 Context componentEnvironment = (Context )new InitialContext ().lookup("java:comp/env"); 80 81 ObjectFactory_1_0 of = ClientHelper.createObjectFactory( 83 componentEnvironment, 84 "openmdx/data" 85 ); 86 87 RefPackage_1_0 rootPkg = new RefRootPackage_1( 91 of, 92 null, null, "cci", 95 false ); 97 98 ClientHelper.loadModels( 100 componentEnvironment, 101 rootPkg 102 ); 103 104 org.opencrx.kernel.account1.cci.account1Package accountPkg = 106 (org.opencrx.kernel.account1.cci.account1Package)rootPkg.refPackage( 107 org.opencrx.kernel.account1.cci.account1Package.class.getName() 108 ); 109 110 String providerName = (String )componentEnvironment.lookup("providerName"); 112 String segmentName = (String )componentEnvironment.lookup("segmentName"); 113 114 org.opencrx.kernel.account1.cci.Segment accountSegment = 116 (org.opencrx.kernel.account1.cci.Segment)rootPkg.refObject( 117 "xri:@openmdx:org.opencrx.kernel.account1/provider/" + providerName + "/segment/" + segmentName 118 ); 119 120 org.opencrx.kernel.home1.cci.Segment homeSegment = 122 (org.opencrx.kernel.home1.cci.Segment)rootPkg.refObject( 123 "xri:@openmdx:org.opencrx.kernel.home1/provider/" + providerName + "/segment/" + segmentName 124 ); 125 126 org.opencrx.kernel.product1.cci.Segment productSegment = 128 (org.opencrx.kernel.product1.cci.Segment)rootPkg.refObject( 129 "xri:@openmdx:org.opencrx.kernel.product1/provider/" + providerName + "/segment/" + segmentName 130 ); 131 132 org.opencrx.kernel.contract1.cci.Segment contractSegment = 134 (org.opencrx.kernel.contract1.cci.Segment)rootPkg.refObject( 135 "xri:@openmdx:org.opencrx.kernel.contract1/provider/" + providerName + "/segment/" + segmentName 136 ); 137 138 long startedAt = System.currentTimeMillis(); 140 System.out.println("Creating/Removing accounts"); 141 for( 142 int i = 0; 143 i < MAX_ITERATIONS; 144 i++ 145 ) { 146 for( 147 int j = 0; 148 j < 100; 149 j++ 150 ) { 151 if(j % 100 == 0) { 152 System.out.println(j + " accounts"); 153 } 154 org.opencrx.kernel.account1.cci.Contact contact = accountPkg.getContactClass().createContact(); 155 contact.refInitialize( 156 false, 157 false 158 ); 159 contact.setLastName("TEST"); 160 accountPkg.refBegin(); 161 accountSegment.addAccount("TEST", contact); 162 accountPkg.refCommit(); 163 accountPkg.refBegin(); 164 accountSegment.removeAccount("TEST"); 165 accountPkg.refCommit(); 166 } 167 } 168 System.out.println("Creating/removing accounts (ms): " + (System.currentTimeMillis() - startedAt)); 169 170 startedAt = System.currentTimeMillis(); 172 System.out.println("Retrieving accounts"); 173 int limit = 1000000; 174 Runtime runtime = Runtime.getRuntime(); 175 long initialMemoryUsage = runtime.totalMemory() - runtime.freeMemory(); 176 System.out.println("Initial memory usage " + initialMemoryUsage); 177 for( 178 int i = 0; 179 i < MAX_ITERATIONS; 180 i++ 181 ) { 182 System.out.println(" Step " + i); 183 Collection accounts = accountSegment.getAccount(); 184 int jj = 0; 185 for( 186 Iterator j = accounts.iterator(); 187 j.hasNext(); 188 jj++ 189 ) { 190 if(jj % 100 == 0) { 191 long currentMemoryUsage = runtime.totalMemory() - runtime.freeMemory(); 192 System.out.println(jj + " accounts retrieved. Current memory usage " + currentMemoryUsage); 193 long additionalMemoryUsage = currentMemoryUsage - initialMemoryUsage; 194 if(additionalMemoryUsage > limit) { 195 runtime.gc(); 196 currentMemoryUsage = runtime.totalMemory() - runtime.freeMemory(); 197 additionalMemoryUsage = currentMemoryUsage - initialMemoryUsage; 198 } 199 } 200 org.opencrx.kernel.account1.cci.Account account = (org.opencrx.kernel.account1.cci.Account)j.next(); 201 account.refRefresh(); 202 for( 204 Iterator k = account.getAddress().iterator(); 205 k.hasNext(); 206 ) { 207 org.opencrx.kernel.account1.cci.AccountAddress address = (org.opencrx.kernel.account1.cci.AccountAddress)k.next(); 208 address.refRefresh(); 209 } 210 } 211 System.out.println("Retrieving " + jj + " accounts (ms): " + (System.currentTimeMillis() - startedAt)); 212 } 213 214 startedAt = System.currentTimeMillis(); 216 System.out.println("Retrieving homes"); 217 for( 218 int i = 0; 219 i < MAX_ITERATIONS; 220 i++ 221 ) { 222 System.out.println(" Step " + i); 223 Collection homes = homeSegment.getUserHome(); 224 int jj = 0; 225 for( 226 Iterator j = homes.iterator(); 227 j.hasNext(); 228 jj++ 229 ) { 230 if(jj % 100 == 0) { 231 System.out.println(jj + " homes"); 232 } 233 org.opencrx.kernel.home1.cci.UserHome home = (org.opencrx.kernel.home1.cci.UserHome)j.next(); 234 home.refRefresh(); 235 for( 237 Iterator k = home.getAlert().iterator(); 238 k.hasNext(); 239 ) { 240 org.opencrx.kernel.home1.cci.Alert alert = (org.opencrx.kernel.home1.cci.Alert)k.next(); 241 alert.refRefresh(); 242 } 243 for( 245 Iterator k = home.getAssignedContract().iterator(); 246 k.hasNext(); 247 ) { 248 org.opencrx.kernel.contract1.cci.AbstractContract contract = (org.opencrx.kernel.contract1.cci.AbstractContract)k.next(); 249 contract.refRefresh(); 250 } 251 for( 253 Iterator k = home.getAssignedActivity().iterator(); 254 k.hasNext(); 255 ) { 256 org.opencrx.kernel.activity1.cci.Activity activity = (org.opencrx.kernel.activity1.cci.Activity)k.next(); 257 activity.refRefresh(); 258 } 259 } 260 System.out.println("Retrieving " + jj + " homes (ms): " + (System.currentTimeMillis() - startedAt)); 261 } 262 263 startedAt = System.currentTimeMillis(); 265 System.out.println("Retrieving contracts"); 266 for( 267 int i = 0; 268 i < MAX_ITERATIONS; 269 i++ 270 ) { 271 System.out.println(" Step " + i); 272 Collection leads = contractSegment.getLead(); 274 int jj = 0; 275 for( 276 Iterator j = leads.iterator(); 277 j.hasNext(); 278 jj++ 279 ) { 280 if(jj % 100 == 0) { 281 System.out.println(jj + " leads"); 282 } 283 org.opencrx.kernel.contract1.cci.Lead lead = (org.opencrx.kernel.contract1.cci.Lead)j.next(); 284 lead.refRefresh(); 285 } 286 System.out.println("Retrieving " + jj + " leads (ms): " + (System.currentTimeMillis() - startedAt)); 287 288 Collection opportunities = contractSegment.getOpportunity(); 290 jj = 0; 291 for( 292 Iterator j = opportunities.iterator(); 293 j.hasNext(); 294 ) { 295 if(jj % 100 == 0) { 296 System.out.println(jj + " opportunities"); 297 } 298 org.opencrx.kernel.contract1.cci.Opportunity opportunity = (org.opencrx.kernel.contract1.cci.Opportunity)j.next(); 299 opportunity.refRefresh(); 300 for( 302 Iterator k = opportunity.getPosition().iterator(); 303 k.hasNext(); 304 ) { 305 org.opencrx.kernel.contract1.cci.ContractPosition position = (org.opencrx.kernel.contract1.cci.ContractPosition)k.next(); 306 position.refRefresh(); 307 } 308 } 309 System.out.println("Retrieving " + jj + " opportunities (ms): " + (System.currentTimeMillis() - startedAt)); 310 311 Collection quotes = contractSegment.getQuote(); 313 jj = 0; 314 for( 315 Iterator j = quotes.iterator(); 316 j.hasNext(); 317 ) { 318 if(jj % 100 == 0) { 319 System.out.println(jj + " quotes"); 320 } 321 org.opencrx.kernel.contract1.cci.Quote quote = (org.opencrx.kernel.contract1.cci.Quote)j.next(); 322 quote.refRefresh(); 323 for( 325 Iterator k = quote.getPosition().iterator(); 326 k.hasNext(); 327 ) { 328 org.opencrx.kernel.contract1.cci.ContractPosition position = (org.opencrx.kernel.contract1.cci.ContractPosition)k.next(); 329 position.refRefresh(); 330 } 331 } 332 System.out.println("Retrieving " + jj + " quotes (ms): " + (System.currentTimeMillis() - startedAt)); 333 334 Collection salesOrders = contractSegment.getSalesOrder(); 336 jj = 0; 337 for( 338 Iterator j = salesOrders.iterator(); 339 j.hasNext(); 340 ) { 341 if(jj % 100 == 0) { 342 System.out.println(jj + " sales orders"); 343 } 344 org.opencrx.kernel.contract1.cci.SalesOrder salesOrder = (org.opencrx.kernel.contract1.cci.SalesOrder)j.next(); 345 salesOrder.refRefresh(); 346 for( 348 Iterator k = salesOrder.getPosition().iterator(); 349 k.hasNext(); 350 ) { 351 org.opencrx.kernel.contract1.cci.ContractPosition position = (org.opencrx.kernel.contract1.cci.ContractPosition)k.next(); 352 position.refRefresh(); 353 } 354 } 355 System.out.println("Retrieving " + jj + " sales orders (ms): " + (System.currentTimeMillis() - startedAt)); 356 357 Collection invoices = contractSegment.getInvoice(); 359 jj = 0; 360 for( 361 Iterator j = invoices.iterator(); 362 j.hasNext(); 363 ) { 364 if(jj % 100 == 0) { 365 System.out.println(jj + " invoices"); 366 } 367 org.opencrx.kernel.contract1.cci.Invoice invoice = (org.opencrx.kernel.contract1.cci.Invoice)j.next(); 368 invoice.refRefresh(); 369 for( 371 Iterator k = invoice.getPosition().iterator(); 372 k.hasNext(); 373 ) { 374 org.opencrx.kernel.contract1.cci.ContractPosition position = (org.opencrx.kernel.contract1.cci.ContractPosition)k.next(); 375 position.refRefresh(); 376 } 377 } 378 System.out.println("Retrieving " + jj + " invoices (ms): " + (System.currentTimeMillis() - startedAt)); 379 } 380 } 381 catch (NamingException e) { 382 e.printStackTrace(); 383 } 384 catch (ServiceException e) { 385 e.printStackTrace(); 386 } 387 catch (JmiServiceException e) { 388 e.printStackTrace(); 389 } 390 } 391 392 private static final int MAX_ITERATIONS = 2; 396 397 } 398 399 | Popular Tags |