geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound ConnectionManagerStressTest.java ConnectionManagerTestUtils.java ConnectionManagerTest.java
Date Thu, 22 Apr 2004 17:06:30 GMT
djencks     2004/04/22 10:06:30

  Modified:    modules/connector/src/test/org/apache/geronimo/connector/mock
                        MockManagedConnectionFactory.java
               modules/connector/src/test/org/apache/geronimo/connector/outbound
                        ConnectionManagerTest.java
  Added:       modules/connector/src/test/org/apache/geronimo/connector/outbound
                        ConnectionManagerStressTest.java
                        ConnectionManagerTestUtils.java
  Log:
  start on some performance tests
  
  Revision  Changes    Path
  1.5       +4 -2      incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/mock/MockManagedConnectionFactory.java
  
  Index: MockManagedConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/mock/MockManagedConnectionFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MockManagedConnectionFactory.java	10 Mar 2004 09:58:34 -0000	1.4
  +++ MockManagedConnectionFactory.java	22 Apr 2004 17:06:30 -0000	1.5
  @@ -21,6 +21,8 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Set;
  +import java.util.Collections;
  +
   import javax.resource.ResourceException;
   import javax.resource.spi.ConnectionManager;
   import javax.resource.spi.ConnectionRequestInfo;
  @@ -40,7 +42,7 @@
       private MockResourceAdapter resourceAdapter;
       private PrintWriter logWriter;
   
  -    private final Set managedConnections = new HashSet();
  +    private final Set managedConnections = Collections.synchronizedSet(new HashSet());
   
       private boolean reauthentication;
   
  
  
  
  1.9       +2 -74     incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java
  
  Index: ConnectionManagerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ConnectionManagerTest.java	7 Apr 2004 22:37:10 -0000	1.8
  +++ ConnectionManagerTest.java	22 Apr 2004 17:06:30 -0000	1.9
  @@ -50,62 +50,7 @@
    * @version $Revision$ $Date$
    *
    * */
  -public class ConnectionManagerTest extends TestCase implements DefaultInterceptor, RealmBridge
{
  -
  -    protected boolean useConnectionRequestInfo = false;
  -    protected boolean useSubject = true;
  -    protected boolean useTransactionCaching = true;
  -    protected boolean useLocalTransactions = false;
  -    protected boolean useTransactions = true;
  -    protected int maxSize = 5;
  -    protected int blockingTimeout = 100;
  -    protected String name = "testCF";
  -    //dependencies
  -    protected RealmBridge realmBridge = this;
  -    protected ConnectionTrackingCoordinator connectionTrackingCoordinator;
  -
  -    protected TransactionManager transactionManager;
  -    protected ConnectionManagerDeployment connectionManagerDeployment;
  -    protected MockConnectionFactory connectionFactory;
  -    protected MockManagedConnectionFactory mockManagedConnectionFactory;
  -    protected DefaultComponentContext defaultComponentContext;
  -    protected DefaultComponentInterceptor defaultComponentInterceptor;
  -    protected Set unshareableResources = new HashSet();
  -    protected MockManagedConnection mockManagedConnection;
  -    protected Subject subject;
  -
  -    protected UserTransactionImpl userTransaction;
  -
  -    protected void setUp() throws Exception {
  -        connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
  -        transactionManager = new TransactionManagerImpl();
  -        mockManagedConnectionFactory = new MockManagedConnectionFactory();
  -        subject = new Subject();
  -        ContextManager.setCurrentCaller(subject);
  -        connectionManagerDeployment = new ConnectionManagerDeployment(useConnectionRequestInfo,
  -                useSubject,
  -                useTransactionCaching,
  -                useLocalTransactions,
  -                useTransactions,
  -                maxSize,
  -                blockingTimeout,
  -                //name,
  -                realmBridge,
  -                connectionTrackingCoordinator);
  -        connectionManagerDeployment.doStart();
  -        connectionFactory = (MockConnectionFactory) connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory);
  -        defaultComponentContext = new DefaultComponentContext();
  -        defaultComponentInterceptor = new DefaultComponentInterceptor(this, connectionTrackingCoordinator,
unshareableResources);
  -    }
  -
  -    protected void tearDown() throws Exception {
  -        connectionTrackingCoordinator = null;
  -        transactionManager = null;
  -        mockManagedConnectionFactory = null;
  -        connectionManagerDeployment = null;
  -        connectionFactory = null;
  -        defaultComponentContext = null;
  -    }
  +public class ConnectionManagerTest extends ConnectionManagerTestUtils {
   
   
       public void testSingleTransactionCall() throws Throwable {
  @@ -155,22 +100,5 @@
           assertNotNull("Should be committed", mockXAResource.getCommitted());
       }
   
  -    public Object invoke(InstanceContext newInstanceContext) throws Throwable {
  -        MockConnection mockConnection = (MockConnection) connectionFactory.getConnection();
  -        mockManagedConnection = mockConnection.getManagedConnection();
  -        if (userTransaction != null) {
  -            userTransaction.begin();
  -            MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
  -            assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
  -            assertNull("Should not be committed", mockXAResource.getCommitted());
  -            userTransaction.commit();
  -            assertNotNull("Should be committed", mockXAResource.getCommitted());
  -        }
  -        mockConnection.close();
  -        return null;
  -    }
   
  -    public Subject mapSubject(Subject sourceSubject) {
  -        return subject;
  -    }
   }
  
  
  
  1.1                  incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerStressTest.java
  
  Index: ConnectionManagerStressTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import org.apache.geronimo.transaction.TransactionContext;
  import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.logging.Log;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/04/22 17:06:30 $
   *
   * */
  public class ConnectionManagerStressTest extends ConnectionManagerTestUtils {
  
      private static final Log log = LogFactory.getLog(ConnectionManagerStressTest.class);
  
      protected int repeatCount = 100;
      protected int threadCount = 50;
      private Object startBarrier = new Object();
      private Object stopBarrier = new Object();
      private int startedThreads = 0;
      private int stoppedThreads = 0;
      private long totalDuration = 0;
      private Object mutex = new Object();
  
      private Exception e = null;
  
      public void testNoTransactionCallOneThread() throws Throwable {
          TransactionContext.setContext(new UnspecifiedTransactionContext());
          for (int i = 0; i < repeatCount; i++) {
              defaultComponentInterceptor.invoke(defaultComponentContext);
          }
      }
  
      public void testNoTransactionCallMultiThread() throws Throwable {
          startedThreads = 0;
          stoppedThreads = 0;
          for (int t = 0; t < threadCount; t++) {
              new Thread() {
                  public void run() {
                      TransactionContext.setContext(new UnspecifiedTransactionContext());
                      long localStartTime = 0;
                      try {
                          synchronized (startBarrier) {
                              ++startedThreads;
                              startBarrier.notifyAll();
                              while (startedThreads < (threadCount + 1)) {
                                  startBarrier.wait();
                              }
                          }
                          localStartTime = System.currentTimeMillis();
                          for (int i = 0; i < repeatCount; i++) {
                              try {
                                  defaultComponentInterceptor.invoke(new DefaultComponentContext());
                              } catch (Throwable throwable) {
                                  throwable.printStackTrace();
                              }
                          }
                      } catch (Exception e) {
                          log.info(e);
                          ConnectionManagerStressTest.this.e = e;
                      } finally {
                          synchronized (stopBarrier) {
                              ++stoppedThreads;
                              stopBarrier.notifyAll();
                          }
                          long localDuration = System.currentTimeMillis() - localStartTime;
                          synchronized (mutex) {
                               totalDuration += localDuration;
                          }
                      }
                  }
              }.start();
          }
          // Wait for all the workers to be ready..
          long startTime = 0;
          synchronized (startBarrier) {
              while (startedThreads < threadCount) startBarrier.wait();
              ++startedThreads;
              startBarrier.notifyAll();
              startTime = System.currentTimeMillis();
          }
  
          // Wait for all the workers to finish.
          synchronized (stopBarrier) {
              while (stoppedThreads < threadCount) stopBarrier.wait();
          }
          long duration = System.currentTimeMillis() - startTime;
          log.info("no tx run, thread count: " + threadCount + ", connection count: " + repeatCount
+ ", duration: " + duration + ", total duration: " + totalDuration + ", ms per cx request:
" + (totalDuration/(threadCount * repeatCount)));
          //return startTime;
          if (e != null) {
              throw e;
          }
      }
  }
  
  
  
  1.7       +78 -147   incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java
  
  
  
  

Mime
View raw message