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 FixedSizeQueueTestCase.java QueueTestCase.java
Date Wed, 19 Dec 2001 21:53:48 GMT
bloritsch    01/12/19 13:53:48

  Modified:    src/scratchpad/org/apache/avalon/excalibur/event/test
                        FixedSizeQueueTestCase.java QueueTestCase.java
  Added:       src/scratchpad/org/apache/avalon/excalibur/event/test
                        AbstractQueueTestCase.java
  Log:
  create abstract test
  
  Revision  Changes    Path
  1.5       +6 -79     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/FixedSizeQueueTestCase.java
  
  Index: FixedSizeQueueTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/FixedSizeQueueTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FixedSizeQueueTestCase.java	2001/12/19 21:01:35	1.4
  +++ FixedSizeQueueTestCase.java	2001/12/19 21:53:47	1.5
  @@ -9,107 +9,34 @@
   
   import junit.framework.TestCase;
   import org.apache.avalon.excalibur.event.FixedSizeQueue;
  -import org.apache.avalon.excalibur.event.PreparedEnqueue;
  -import org.apache.avalon.excalibur.event.QueueElement;
  -import org.apache.avalon.excalibur.event.SourceException;
   
   /**
    * The default queue implementation is a variabl size queue.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  -public class FixedSizeQueueTestCase extends TestCase
  +public final class FixedSizeQueueTestCase extends AbstractQueueTestCase
   {
  -    QueueElement element = new TestQueueElement();
  -    QueueElement[] elements = new TestQueueElement[10];
  -
  -    private static final class TestQueueElement implements QueueElement
  -    {
  -    }
  -
       public FixedSizeQueueTestCase( String name )
       {
           super( name );
  -
  -        for ( int i = 0; i < 10; i++ )
  -        {
  -            elements[i] = new TestQueueElement();
  -        }
       }
   
       public void testMillionIterationOneElement()
           throws Exception
       {
  -        FixedSizeQueue queue = new FixedSizeQueue( 32 );
  -        assertEquals( queue.size(), 0 );
  -
  -        for ( int j = 0; j < 1000000; j++ )
  -        {
  -            queue.enqueue( element );
  -            assertEquals( 1, queue.size() );
  -
  -            assertNotNull( queue.dequeue() );
  -            assertEquals( 0, queue.size() );
  -        }
  +        this.performMillionIterationOneElement( new FixedSizeQueue( 32 ) );
       }
   
       public void testMillionIterationTenElements()
           throws Exception
       {
  -        FixedSizeQueue queue = new FixedSizeQueue( 32 );
  -        assertEquals( queue.size(), 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() );
  -        }
  +        this.performMillionIterationTenElements( new FixedSizeQueue( 32 ) );
       }
   
  -    public void testDefaultQueue()
  +    public void testFixedSizeQueue()
  +        throws Exception
       {
  -        FixedSizeQueue queue = new FixedSizeQueue( 32 );
  -        assertEquals( 0, queue.size() );
  -
  -        //test enqueue
  -        try
  -        {
  -            queue.enqueue( new TestQueueElement () );
  -            assertEquals( 1, queue.size() );
  -
  -            assertNotNull( queue.dequeue() );
  -            assertEquals( 0, queue.size() );
  -
  -            queue.enqueue( elements );
  -            assertEquals( 10, queue.size() );
  -
  -            QueueElement[] results = queue.dequeue( 3 );
  -            assertEquals( 3, results.length );
  -            assertEquals( 7, queue.size() );
  -
  -            results = queue.dequeueAll();
  -            assertEquals( 7, results.length );
  -            assertEquals( 0, queue.size() );
  -
  -            PreparedEnqueue prep = queue.prepareEnqueue( elements );
  -            assertEquals( 0, queue.size() );
  -            prep.abort();
  -            assertEquals( 0, queue.size() );
  -
  -            prep = queue.prepareEnqueue( elements );
  -            assertEquals( 0, queue.size() );
  -            prep.commit();
  -            assertEquals( 10, queue.size() );
  -
  -            results = queue.dequeue( queue.size() );
  -            assertEquals( 0, queue.size() );
  -        }
  -        catch ( SourceException se )
  -        {
  -        }
  +        this.performQueue( new FixedSizeQueue( 32 ) );
       }
   }
  
  
  
  1.5       +5 -78     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/QueueTestCase.java
  
  Index: QueueTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/QueueTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- QueueTestCase.java	2001/12/19 18:46:36	1.4
  +++ QueueTestCase.java	2001/12/19 21:53:47	1.5
  @@ -9,107 +9,34 @@
   
   import junit.framework.TestCase;
   import org.apache.avalon.excalibur.event.DefaultQueue;
  -import org.apache.avalon.excalibur.event.PreparedEnqueue;
  -import org.apache.avalon.excalibur.event.QueueElement;
  -import org.apache.avalon.excalibur.event.SourceException;
   
   /**
    * The default queue implementation is a variabl size queue.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  -public class QueueTestCase extends TestCase
  +public final class QueueTestCase extends AbstractQueueTestCase
   {
  -    QueueElement element = new TestQueueElement();
  -    QueueElement[] elements = new TestQueueElement[10];
  -
  -    private static final class TestQueueElement implements QueueElement
  -    {
  -    }
  -
       public QueueTestCase( String name )
       {
           super( name );
  -
  -        for ( int i = 0; i < 10; i++ )
  -        {
  -            elements[i] = new TestQueueElement();
  -        }
       }
   
       public void testMillionIterationOneElement()
           throws Exception
       {
  -        DefaultQueue queue = new DefaultQueue();
  -        assertEquals( 0, queue.size() );
  -
  -        for ( int j = 0; j < 1000000; j++ )
  -        {
  -            queue.enqueue( element );
  -            assertEquals( 1, queue.size() );
  -
  -            assertNotNull( queue.dequeue() );
  -            assertEquals( 0, queue.size() );
  -        }
  +        this.performMillionIterationOneElement( new DefaultQueue() );
       }
   
       public void testMillionIterationTenElements()
           throws Exception
       {
  -        DefaultQueue queue = new DefaultQueue();
  -        assertEquals( 0, queue.size() );
  -
  -        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() );
  -        }
  +        this.performMillionIterationTenElements( new DefaultQueue() );
       }
   
       public void testDefaultQueue()
  +        throws Exception
       {
  -        DefaultQueue queue = new DefaultQueue();
  -        assertEquals( 0, queue.size() );
  -
  -        //test enqueue
  -        try
  -        {
  -            queue.enqueue( new TestQueueElement () );
  -            assertEquals( 1, queue.size() );
  -
  -            assertNotNull( queue.dequeue() );
  -            assertEquals( 0, queue.size() );
  -
  -            queue.enqueue( elements );
  -            assertEquals( 10, queue.size() );
  -
  -            QueueElement[] results = queue.dequeue( 3 );
  -            assertEquals( 3, results.length );
  -            assertEquals( 7, queue.size() );
  -
  -            results = queue.dequeueAll();
  -            assertEquals( 7, results.length );
  -            assertEquals( 0, queue.size() );
  -
  -            PreparedEnqueue prep = queue.prepareEnqueue( elements );
  -            assertEquals( 0, queue.size() );
  -            prep.abort();
  -            assertEquals( 0, queue.size() );
  -
  -            prep = queue.prepareEnqueue( elements );
  -            assertEquals( 0, queue.size() );
  -            prep.commit();
  -            assertEquals( 10, queue.size() );
  -
  -            results = queue.dequeue( queue.size() );
  -            assertEquals( 0, queue.size() );
  -        }
  -        catch ( SourceException se )
  -        {
  -        }
  +        this.performQueue( new DefaultQueue() );
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/test/AbstractQueueTestCase.java
  
  Index: AbstractQueueTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.event.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.excalibur.event.Queue;
  import org.apache.avalon.excalibur.event.PreparedEnqueue;
  import org.apache.avalon.excalibur.event.QueueElement;
  import org.apache.avalon.excalibur.event.SourceException;
  
  /**
   * The default queue implementation is a variabl size queue.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   */
  public abstract class AbstractQueueTestCase extends TestCase
  {
      QueueElement element = new TestQueueElement();
      QueueElement[] elements = new TestQueueElement[10];
  
      private static final class TestQueueElement implements QueueElement
      {
      }
  
      public AbstractQueueTestCase( String name )
      {
          super( name );
  
          for ( int i = 0; i < 10; i++ )
          {
              elements[i] = new TestQueueElement();
          }
      }
  
      protected final void performMillionIterationOneElement( Queue queue )
          throws Exception
      {
          assertEquals( 0, queue.size() );
  
          for ( int j = 0; j < 1000000; j++ )
          {
              queue.enqueue( element );
              assertEquals( 1, queue.size() );
  
              assertNotNull( queue.dequeue() );
              assertEquals( 0, queue.size() );
          }
      }
  
      protected final void performMillionIterationTenElements( Queue queue )
          throws Exception
      {
          assertEquals( 0, queue.size() );
  
          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() );
          }
      }
  
      protected final void performQueue( Queue queue )
          throws Exception
      {
          assertEquals( 0, queue.size() );
  
          queue.enqueue( new TestQueueElement () );
          assertEquals( 1, queue.size() );
  
          assertNotNull( queue.dequeue() );
          assertEquals( 0, queue.size() );
  
          queue.enqueue( elements );
          assertEquals( 10, queue.size() );
  
          QueueElement[] results = queue.dequeue( 3 );
          assertEquals( 3, results.length );
          assertEquals( 7, queue.size() );
  
          results = queue.dequeueAll();
          assertEquals( 7, results.length );
          assertEquals( 0, queue.size() );
  
          PreparedEnqueue prep = queue.prepareEnqueue( elements );
          assertEquals( 0, queue.size() );
          prep.abort();
          assertEquals( 0, queue.size() );
  
          prep = queue.prepareEnqueue( elements );
          assertEquals( 0, queue.size() );
          prep.commit();
          assertEquals( 10, queue.size() );
  
          results = queue.dequeue( queue.size() );
          assertEquals( 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