You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by do...@apache.org on 2001/02/24 08:28:22 UTC

cvs commit: jakarta-avalon/src/java/org/apache/avalon/util/datasource/test DataSourceTestlet.java

donaldp     01/02/23 23:28:22

  Modified:    src/java/org/apache/avalon/util/datasource/test
                        DataSourceTestlet.java
  Log:
  Fixed VAJavas inner class woes
  
  Revision  Changes    Path
  1.2       +116 -76   jakarta-avalon/src/java/org/apache/avalon/util/datasource/test/DataSourceTestlet.java
  
  Index: DataSourceTestlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/util/datasource/test/DataSourceTestlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataSourceTestlet.java	2001/02/24 03:59:39	1.1
  +++ DataSourceTestlet.java	2001/02/24 07:28:21	1.2
  @@ -7,16 +7,16 @@
    */
   package org.apache.avalon.util.datasource.test;
   
  -import org.apache.testlet.AbstractTestlet;
  +import java.sql.Connection;
  +import java.sql.SQLException;
  +import java.util.Random;
   import org.apache.avalon.Configuration;
   import org.apache.avalon.ConfigurationException;
   import org.apache.avalon.DefaultConfiguration;
   import org.apache.avalon.util.datasource.DataSourceComponent;
   import org.apache.avalon.util.datasource.JdbcDataSource;
   import org.apache.log.LogKit;
  -import java.sql.SQLException;
  -import java.sql.Connection;
  -import java.util.Random;
  +import org.apache.testlet.AbstractTestlet;
   
   /**
    * Test the DataSource Component.  I don't know how to make this generic,
  @@ -25,113 +25,153 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  -public class DataSourceTestlet extends AbstractTestlet {
  +public class DataSourceTestlet 
  +    extends AbstractTestlet
  +{
       static final Configuration conf;
       static final String LOCATION = "Testlet Framework";
   
  -    static {
  -        DefaultConfiguration dc = new DefaultConfiguration("", LOCATION);
  -        DefaultConfiguration pool = new DefaultConfiguration("pool-controller", LOCATION);
  -        DefaultConfiguration dburl = new DefaultConfiguration("dburl", LOCATION);
  -        DefaultConfiguration user = new DefaultConfiguration("user", LOCATION);
  -        DefaultConfiguration password = new DefaultConfiguration("password", LOCATION);
  -        pool.addAttribute("min", "5");
  -        pool.addAttribute("max", "10");
  -        dc.addChild(pool);
  -        dburl.appendValueData("jdbc:odbc://test");
  -        dc.addChild(dburl);
  -        user.appendValueData("test");
  -        dc.addChild(user);
  -        password.appendValueData("test");
  -        dc.addChild(password);
  +    static
  +    {
  +        DefaultConfiguration dc = new DefaultConfiguration( "", LOCATION );
  +        DefaultConfiguration pool = new DefaultConfiguration( "pool-controller", LOCATION );
  +        DefaultConfiguration dburl = new DefaultConfiguration( "dburl", LOCATION );
  +        DefaultConfiguration user = new DefaultConfiguration( "user", LOCATION );
  +        DefaultConfiguration password = new DefaultConfiguration( "password", LOCATION );
  +        pool.addAttribute( "min", "5" );
  +        pool.addAttribute( "max", "10" );
  +        dc.addChild( pool );
  +        dburl.appendValueData( "jdbc:odbc://test" );
  +        dc.addChild( dburl );
  +        user.appendValueData( "test" );
  +        dc.addChild( user );
  +        password.appendValueData( "test" );
  +        dc.addChild( password );
           conf = dc;
   
  -        LogKit.setGlobalPriority(org.apache.log.Priority.INFO);
  +        LogKit.setGlobalPriority( org.apache.log.Priority.INFO );
   
  -        try {
  -            Class.forName("Your Driver Class Here");
  -        } catch (Exception e) {
  -            LogKit.getLoggerFor("test").error(e.getMessage(), e);
  +        try 
  +        {
  +            Class.forName( "Your Driver Class Here" );
  +        } 
  +        catch( final Exception e )
  +        {
  +            LogKit.getLoggerFor( "test" ).error( e.getMessage(), e );
           }
       }
   
  -    public void testOverAllocation() {
  +    public void testOverAllocation() 
  +    {
           boolean result = false;
           JdbcDataSource ds = new JdbcDataSource();
  -        ds.setLogger(LogKit.getLoggerFor("test"));
  +        ds.setLogger( LogKit.getLoggerFor( "test" ) );
   
  -        try {
  -            ds.configure(conf);
  -        } catch (ConfigurationException ce) {
  -            assert("Over Allocation Test", false);
  +        try 
  +        {
  +            ds.configure( conf );
  +        } 
  +        catch( final ConfigurationException ce )
  +        {
  +            assert( "Over Allocation Test", false );
           }
   
  -        try {
  -            for (int i = 0; i < 11; i++) {
  +        try 
  +        {
  +            for( int i = 0; i < 11; i++ )
  +            {
                   ds.getConnection();
               }
  -        } catch (SQLException se) {
  +        } 
  +        catch( final SQLException se ) 
  +        {
               result = true;
  -            LogKit.getLoggerFor("test").info("The test was successful");
  +            LogKit.getLoggerFor( "test" ).info( "The test was successful" );
           }
   
  -        assert("Over Allocation Test", result);
  +        assert( "Over Allocation Test", result );
       }
   
  -    public void testNormalUse() {
  +    public void testNormalUse() 
  +    {
           boolean result = true;
           JdbcDataSource ds = new JdbcDataSource();
  -        ds.setLogger(LogKit.getLoggerFor("test"));
  +        ds.setLogger( LogKit.getLoggerFor( "test" ) );
   
  -        try {
  -            ds.configure(conf);
  -        } catch (ConfigurationException ce) {
  -            LogKit.getLoggerFor("test").error(ce.getMessage(), ce);
  -            assert("Over Allocation Test", false);
  +        try 
  +        {
  +            ds.configure( conf );
  +        } 
  +        catch( final ConfigurationException ce )
  +        {
  +            LogKit.getLoggerFor( "test" ).error( ce.getMessage(), ce );
  +            assert( "Over Allocation Test", false );
           }
   
  -        Thread one = new Thread(new ConnectionThread(ds));
  -        Thread two = new Thread(new ConnectionThread(ds));
  +        Thread one = new Thread( new ConnectionThread( this, ds ) );
  +        Thread two = new Thread( new ConnectionThread( this, ds ) );
   
  -
           one.start();
           two.start();
   
  -        while (one.isAlive() || two.isAlive()) {
  -            try {
  -                Thread.sleep(100);
  -            } catch (InterruptedException ie) {
  +        while( one.isAlive() || two.isAlive() )
  +        {
  +            try
  +            {
  +                Thread.sleep( 100 );
  +            } 
  +            catch( final InterruptedException ie )
  +            {
                   // Ignore
               }
           }
  -
  -        LogKit.getLoggerFor("test").info("If you saw no failure messages, then the test passed");
  -        assert("Normal Use Test", result);
  +        
  +        LogKit.getLoggerFor( "test" ).
  +            info( "If you saw no failure messages, then the test passed" );
  +        assert( "Normal Use Test", result );
       }
   
  -    class ConnectionThread implements Runnable {
  -        DataSourceComponent datasource;
  -
  -        ConnectionThread(DataSourceComponent dc) {
  -            this.datasource = dc;
  -        }
  -
  -        public void run() {
  -            long end = System.currentTimeMillis() + 5000; // run for 5 seconds
  -
  -            while (System.currentTimeMillis() < end) {
  -                try {
  -                    Connection con = datasource.getConnection();
  -                    long sleeptime = (long) (Math.random() * 100.0);
  -                    Thread.sleep(sleeptime);
  -                    con.close();
  -                } catch (SQLException se) {
  -                    LogKit.getLoggerFor("test").info("Failed to get Connection, test failed");
  -                    assert("Normal Use Test", false);
  -                } catch (InterruptedException ie) {
  -                    // Ignore
  -                }
  +    public void runDBTest( final DataSourceComponent datasource )
  +    {
  +        long end = System.currentTimeMillis() + 5000; // run for 5 seconds
  +        
  +        while( System.currentTimeMillis() < end )
  +        {
  +            try 
  +            {
  +                Connection con = datasource.getConnection();
  +                long sleeptime = (long)(Math.random() * 100.0);
  +                Thread.sleep( sleeptime );
  +                con.close();
  +            } 
  +            catch( final SQLException se )
  +            {
  +                LogKit.getLoggerFor( "test" ).info( "Failed to get Connection, test failed" );
  +                assert( "Normal Use Test", false );
  +            }
  +            catch( final InterruptedException ie ) 
  +            {
  +                // Ignore
               }
           }
  +    }
  +}
  +
  +class ConnectionThread 
  +    implements Runnable
  +{
  +    protected DataSourceComponent datasource;
  +    protected DataSourceTestlet testlet;
  +
  +    ConnectionThread( final DataSourceTestlet testlet, 
  +                      final DataSourceComponent datasource ) 
  +    {
  +        this.datasource = datasource;
  +        this.testlet = testlet;
  +    }
  +    
  +    public void run() 
  +    {
  +        testlet.runDBTest( datasource );
       }
  -}
  \ No newline at end of file
  +}