1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import java.util.HashSet ; 21 22 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContextImpl; 23 24 29 public class ConnectionManagerStressTest extends ConnectionManagerTestUtils { 30 31 protected int repeatCount = 200; 32 protected int threadCount = 10; 33 private Object startBarrier = new Object (); 34 private Object stopBarrier = new Object (); 35 private int startedThreads = 0; 36 private int stoppedThreads = 0; 37 private long totalDuration = 0; 38 private int slowCount = 0; 39 private Object mutex = new Object (); 40 41 private Exception e = null; 42 43 public void testNoTransactionCallOneThread() throws Throwable { 44 for (int i = 0; i < repeatCount; i++) { 45 defaultComponentInterceptor.invoke(connectorInstanceContext); 46 } 47 } 48 49 public void testNoTransactionCallMultiThread() throws Throwable { 50 startedThreads = 0; 51 stoppedThreads = 0; 52 for (int t = 0; t < threadCount; t++) { 53 new Thread () { 54 public void run() { 55 long localStartTime = 0; 56 int localSlowCount = 0; 57 try { 58 synchronized (startBarrier) { 59 ++startedThreads; 60 startBarrier.notifyAll(); 61 while (startedThreads < (threadCount + 1)) { 62 startBarrier.wait(); 63 } 64 } 65 localStartTime = System.currentTimeMillis(); 66 for (int i = 0; i < repeatCount; i++) { 67 try { 68 long start = System.currentTimeMillis(); 69 defaultComponentInterceptor.invoke(new ConnectorInstanceContextImpl(new HashSet (), new HashSet ())); 70 long duration = System.currentTimeMillis() - start; 71 if (duration > 100) { 72 localSlowCount++; 73 log.debug("got a cx: " + i + ", time: " + (duration)); 74 } 75 } catch (Throwable throwable) { 76 log.debug(throwable.getMessage(), throwable); 77 } 78 } 79 } catch (Exception e) { 80 log.info(e.getMessage(), e); 81 ConnectionManagerStressTest.this.e = e; 82 } finally { 83 synchronized (stopBarrier) { 84 ++stoppedThreads; 85 stopBarrier.notifyAll(); 86 } 87 long localDuration = System.currentTimeMillis() - localStartTime; 88 synchronized (mutex) { 89 totalDuration += localDuration; 90 slowCount += localSlowCount; 91 } 92 } 93 } 94 }.start(); 95 } 96 long startTime = 0; 98 synchronized (startBarrier) { 99 while (startedThreads < threadCount) startBarrier.wait(); 100 ++startedThreads; 101 startBarrier.notifyAll(); 102 startTime = System.currentTimeMillis(); 103 } 104 105 synchronized (stopBarrier) { 107 while (stoppedThreads < threadCount) stopBarrier.wait(); 108 } 109 long duration = System.currentTimeMillis() - startTime; 110 log.debug("no tx run, thread count: " + threadCount + ", connection count: " + repeatCount + ", duration: " + duration + ", total duration: " + totalDuration + ", ms per cx request: " + (totalDuration / (threadCount * repeatCount)) + ", slow cx request count: " + slowCount); 111 if (e != null) { 113 throw e; 114 } 115 } 116 } 117 | Popular Tags |