avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test AbstractQueueTestCase.java
Date Tue, 08 Jan 2002 18:06:07 GMT
bloritsch    02/01/08 10:06:07

  Modified:    src/java/org/apache/avalon/excalibur/collections
                        VariableSizeBuffer.java
               src/java/org/apache/avalon/excalibur/component
                        ExcaliburComponentManager.java
               src/java/org/apache/avalon/excalibur/datasource
                        AbstractJdbcConnection.java
               src/scratchpad/org/apache/avalon/excalibur/event/test
                        AbstractQueueTestCase.java
  Log:
  Fix spurious NullPointerError with VariableSizedBuffer, and changed the DefaultQueueProfile
to be more harsh to variable sized queues
  
  Revision  Changes    Path
  1.2       +45 -35    jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/VariableSizeBuffer.java
  
  Index: VariableSizeBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/VariableSizeBuffer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VariableSizeBuffer.java	20 Dec 2001 18:28:33 -0000	1.1
  +++ VariableSizeBuffer.java	8 Jan 2002 18:06:07 -0000	1.2
  @@ -9,19 +9,17 @@
   
   /**
    * VariableSizeBuffer is a <strong>very</strong> efficient buffer implementation.
  - * According to performance testing, it exhibits a linear access time, but it
  + * According to performance testing, it exhibits a constant access time, but it
    * also outperforms ArrayList when used for the same purpose.
    *
    * @author  <a href="fede@apache.org">Federico Barbieri</a>
    * @author  <a href="bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/12/20 18:28:33 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/01/08 18:06:07 $
    * @since 4.0
    */
   public final class VariableSizeBuffer implements Buffer
   {
       protected Object[]   m_buffer;
  -    protected int        m_bufferSize;
  -    protected int        m_contentSize;
       protected int        m_head;
       protected int        m_tail;
   
  @@ -31,9 +29,7 @@
        */
       public VariableSizeBuffer( int size )
       {
  -        m_buffer = new Object[size];
  -        m_bufferSize = size;
  -        m_contentSize = 0;
  +        m_buffer = new Object[size + 1];
           m_head = 0;
           m_tail = 0;
       }
  @@ -54,49 +50,54 @@
       /**
        * Tests to see if the CircularBuffer is empty.
        */
  -    public boolean isEmpty()
  +    public final boolean isEmpty()
       {
  -        return (m_contentSize == 0);
  +        return (size() == 0);
       }
   
       /**
        * Returns the number of elements stored in the buffer.
        */
  -    public int size()
  +    public final int size()
       {
  -        return m_contentSize;
  +        int size = 0;
  +
  +        if ( m_tail < m_head )
  +        {
  +            size = m_buffer.length - m_head + m_tail;
  +        }
  +        else
  +        {
  +            size = m_tail - m_head;
  +        }
  +
  +        return size;
       }
   
       /**
        * Add an object into the buffer
        */
  -    public void add( final Object o )
  +    public final void add( final Object o )
       {
  -        if( m_contentSize >= m_bufferSize )
  +        if( size() + 1 >= m_buffer.length )
           {
  -            int j = 0;
  -            int i = m_tail;
  -            Object[] tmp = new Object[ m_bufferSize * 2 ];
  +            Object[] tmp = new Object[ ( (m_buffer.length - 1) * 2) + 1 ];
   
  -            while( m_contentSize > 0 )
  +            for ( int i = 0; i < m_buffer.length; i++ )
               {
  -                i++;
  -                i %= m_bufferSize;
  -                j++;
  -                m_contentSize--;
  -                tmp[ j ] = m_buffer[ i ];
  +                tmp[i] = m_buffer[i];
  +                m_buffer[i] = null;
               }
  +
               m_buffer = tmp;
  -            m_tail = 0;
  -            m_head = j;
  -            m_contentSize = j;
  -            m_bufferSize *= 2;
           }
   
  -        m_buffer[ m_head ] = o;
  -        m_head++;
  -        m_head %= m_bufferSize;
  -        m_contentSize++;
  +        m_buffer[ m_tail ] = o;
  +        m_tail++;
  +        if (m_tail >= m_buffer.length)
  +        {
  +            m_tail = 0;
  +        }
       }
   
       /**
  @@ -109,11 +110,20 @@
               throw new BufferUnderflowException( "The buffer is already empty" );
           }
   
  -        Object o = m_buffer[ m_tail ];
  -        m_tail++;
  -        m_tail %= m_bufferSize;
  -        m_contentSize--;
  -        return o;
  +        Object element = m_buffer[ m_head ];
  +
  +        if ( null != element )
  +        {
  +            m_buffer[ m_head ] = null;
  +
  +            m_head++;
  +            if (m_head >= m_buffer.length)
  +            {
  +                m_head = 0;
  +            }
  +        }
  +
  +        return element;
       }
   }
   
  
  
  
  1.15      +36 -29    jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentManager.java
  
  Index: ExcaliburComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentManager.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ExcaliburComponentManager.java	28 Dec 2001 02:35:04 -0000	1.14
  +++ ExcaliburComponentManager.java	8 Jan 2002 18:06:07 -0000	1.15
  @@ -33,7 +33,7 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.14 $ $Date: 2001/12/28 02:35:04 $
  + * @version CVS $Revision: 1.15 $ $Date: 2002/01/08 18:06:07 $
    * @since 4.0
    */
   public class ExcaliburComponentManager
  @@ -261,43 +261,50 @@
                   }
               }
   
  -            final String className = m_roles.getDefaultClassNameForRole( role );
  -
  -            if ( null != className )
  +            if ( null != m_roles )
               {
  -                if (getLogger().isDebugEnabled())
  -                {
  -                    getLogger().debug( "Could not find ComponentHandler, attempting to
create one for role: " + role );
  -                }
  +                final String className = m_roles.getDefaultClassNameForRole( role );
   
  -                try
  +                if ( null != className )
                   {
  -                    final Class componentClass = m_loader.loadClass( className );
  +                    if (getLogger().isDebugEnabled())
  +                    {
  +                        getLogger().debug( "Could not find ComponentHandler, attempting
to create one for role: " + role );
  +                    }
   
  -                    final Configuration configuration = new DefaultConfiguration( "", "-"
);
  +                    try
  +                    {
  +                        final Class componentClass = m_loader.loadClass( className );
   
  -                    handler =
  -                            ComponentHandler.getComponentHandler( componentClass,
  -                                                                  configuration,
  -                                                                  this,
  -                                                                  m_context,
  -                                                                  m_roles,
  -                                                                  m_logkit);
  +                        final Configuration configuration = new DefaultConfiguration( "",
"-" );
   
  -                    handler.setLogger( getLogger() );
  -                    handler.initialize();
  -                }
  -                catch( final Exception e )
  -                {
  -                    final String message = "Could not find component";
  -                    if( getLogger().isErrorEnabled() )
  +                        handler =
  +                                ComponentHandler.getComponentHandler( componentClass,
  +                                                                      configuration,
  +                                                                      this,
  +                                                                      m_context,
  +                                                                      m_roles,
  +                                                                      m_logkit);
  +
  +                        handler.setLogger( getLogger() );
  +                        handler.initialize();
  +                    }
  +                    catch( final Exception e )
                       {
  -                        getLogger().debug( message + " for role: " + role, e );
  +                        final String message = "Could not find component";
  +                        if( getLogger().isDebugEnabled() )
  +                        {
  +                            getLogger().debug( message + " for role: " + role, e );
  +                        }
  +                        throw new ComponentException( message, e );
                       }
  -                    throw new ComponentException( message, e );
  -                }
   
  -                m_componentHandlers.put( role, handler );
  +                    m_componentHandlers.put( role, handler );
  +                }
  +            }
  +            else
  +            {
  +                getLogger().debug("Component requested without a RoleManager set.\nThat
means this ComponentManager was not configured.");
               }
           }
   
  
  
  
  1.4       +9 -1      jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/AbstractJdbcConnection.java
  
  Index: AbstractJdbcConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/AbstractJdbcConnection.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractJdbcConnection.java	11 Dec 2001 09:53:28 -0000	1.3
  +++ AbstractJdbcConnection.java	8 Jan 2002 18:06:07 -0000	1.4
  @@ -29,7 +29,7 @@
    * total number of Connection objects that are created.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2001/12/11 09:53:28 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/01/08 18:06:07 $
    * @since 4.1
    */
   public abstract class AbstractJdbcConnection
  @@ -106,6 +106,14 @@
       public void recycle() {
           this.m_num_uses--;
           this.m_test_exception = null;
  +        try
  +        {
  +            m_connection.clearWarnings();
  +        }
  +        catch ( SQLException se )
  +        {
  +            // ignore
  +        }
       }
   
       public boolean isClosed()
  
  
  
  1.2       +49 -11    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/AbstractQueueTestCase.java
  
  Index: AbstractQueueTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/AbstractQueueTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractQueueTestCase.java	19 Dec 2001 21:53:47 -0000	1.1
  +++ AbstractQueueTestCase.java	8 Jan 2002 18:06:07 -0000	1.2
  @@ -42,13 +42,33 @@
       {
           assertEquals( 0, queue.size() );
   
  -        for ( int j = 0; j < 1000000; j++ )
  +        if (queue.maxSize() > 0)
           {
  -            queue.enqueue( element );
  -            assertEquals( 1, queue.size() );
  +            for ( int j = 0; j < 1000000; j++ )
  +            {
  +                queue.enqueue( element );
  +                assertEquals( 1, queue.size() );
   
  -            assertNotNull( queue.dequeue() );
  -            assertEquals( 0, queue.size() );
  +                assertNotNull( queue.dequeue() );
  +                assertEquals( 0, queue.size() );
  +            }
  +        }
  +        else
  +        {
  +            for ( int i = 0; i < 1000; i++ )
  +            {
  +                for ( int j = 0; j < 1000; j++ )
  +                {
  +                    queue.enqueue( element );
  +                    assertEquals( "Queue Size: " + queue.size(), j + 1, queue.size() );
  +                }
  +
  +                for ( int j = 0; j < 1000; j++ )
  +                {
  +                    assertNotNull( "Queue Size: " + queue.size(), queue.dequeue() );
  +                    assertEquals( "Queue Size: " + queue.size(), 999 - j, queue.size()
);
  +                }
  +            }
           }
       }
   
  @@ -57,14 +77,32 @@
       {
           assertEquals( 0, queue.size() );
   
  -        for ( int j = 0; j < 1000000; j++ )
  +        if (queue.maxSize() > 0)
  +        {
  +            for ( int j = 0; j < 1000000; j++ )
  +            {
  +                queue.enqueue( elements );
  +                assertEquals( 10, queue.size() );
  +
  +                QueueElement[] results = queue.dequeueAll();
  +                assertEquals( 10, results.length );
  +                assertEquals( 0, queue.size() );
  +            }
  +        }
  +        else
           {
  -            queue.enqueue( elements );
  -            assertEquals( 10, queue.size() );
  +            for ( int i = 0; i < 1000; i++ )
  +            {
  +                for ( int j = 0; j < 1000; j++ )
  +                {
  +                    queue.enqueue( elements );
  +                    assertEquals( "Queue Size: " + queue.size(), 10 * ( j + 1 ), queue.size()
);
  +                }
   
  -            QueueElement[] results = queue.dequeueAll();
  -            assertEquals( 10, results.length );
  -            assertEquals( 0, queue.size() );
  +                QueueElement[] results = queue.dequeueAll();
  +                assertEquals( "Queue Size: " + queue.size(), 10 * 1000, results.length
);
  +                assertEquals( "Queue Size: " + queue.size(), 0, queue.size() );
  +            }
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message