You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2004/07/10 05:50:13 UTC

cvs commit: jakarta-turbine-jcs/src/test/org/apache/jcs TestBDBJE.java TestBDBJEDiskCacheConcurrent.java

asmuts      2004/07/09 20:50:13

  Modified:    src/test/org/apache/jcs TestBDBJEDiskCacheConcurrent.java
  Added:       src/test/org/apache/jcs TestBDBJE.java
  Log:
  Better BDBJE tests.  I may need to make one a little less intensive.
  Split to test shutdown.
  
  Revision  Changes    Path
  1.2       +105 -147  jakarta-turbine-jcs/src/test/org/apache/jcs/TestBDBJEDiskCacheConcurrent.java
  
  Index: TestBDBJEDiskCacheConcurrent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/test/org/apache/jcs/TestBDBJEDiskCacheConcurrent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestBDBJEDiskCacheConcurrent.java	8 Jul 2004 00:50:25 -0000	1.1
  +++ TestBDBJEDiskCacheConcurrent.java	10 Jul 2004 03:50:13 -0000	1.2
  @@ -1,6 +1,5 @@
   package org.apache.jcs;
   
  -
   /*
    * Copyright 2001-2004 The Apache Software Foundation.
    *
  @@ -17,7 +16,6 @@
    * limitations under the License.
    */
   
  -import org.apache.jcs.engine.control.CompositeCache;
   import org.apache.jcs.engine.control.CompositeCacheManager;
   
   import junit.extensions.ActiveTestSuite;
  @@ -30,151 +28,111 @@
    *
    * @version $Id$
    */
  -public class TestBDBJEDiskCacheConcurrent extends TestCase
  -{
  -    /**
  -     * Constructor for the TestDiskCache object.
  -     */
  -    public TestBDBJEDiskCacheConcurrent( String testName )
  -    {
  -        super( testName );
  -    }
  -
  -    /**
  -     * Main method passes this test to the text test runner.
  -     */
  -    public static void main( String args[] )
  -    {
  -        String[] testCaseName = {TestDiskCacheConcurrent.class.getName()};
  -        junit.textui.TestRunner.main( testCaseName );
  -    }
  -
  -    /**
  -     * A unit test suite for JUnit
  -     *
  -     * @return    The test suite
  -     */
  -    public static Test suite()
  -    {
  -        ActiveTestSuite suite = new ActiveTestSuite();
  -
  -        suite.addTest( new TestBDBJEDiskCacheConcurrent( "testIndexedDiskCache1" )
  -        {
  -            public void runTest() throws Exception
  -            {
  -                this.runTestForRegion( "indexedRegion4", 0, 200 );
  -            }
  -        } );
  -
  -        suite.addTest( new TestBDBJEDiskCacheConcurrent( "testIndexedDiskCache2" )
  -        {
  -            public void runTest() throws Exception
  -            {
  -                this.runTestForRegion( "indexedRegion4", 1000, 1200 );
  -            }
  -        } );
  -
  -        suite.addTest( new TestBDBJEDiskCacheConcurrent( "testIndexedDiskCache3" )
  -        {
  -            public void runTest() throws Exception
  -            {
  -                this.runTestForRegion( "indexedRegion4", 2000, 3200 );
  -            }
  -        });
  -
  -        suite.addTest( new TestBDBJEDiskCacheConcurrent( "testIndexedDiskCache4" )
  -        {
  -            public void runTest() throws Exception
  -            {
  -                this.runTestForRegion( "indexedRegion4", 2200, 5200 );
  -            }
  -        });
  -
  -        suite.addTest( new TestBDBJEDiskCacheConcurrent( "testIndexedDiskCache5" )
  -        {
  -            public void runTest() throws Exception
  -            {
  -                this.runTestForRegion( "indexedRegion4", 0, 10000 );
  -            }
  -        });
  -
  -
  -        return suite;
  +public class TestBDBJEDiskCacheConcurrent
  +    extends TestCase {
  +  /**
  +   * Constructor for the TestDiskCache object.
  +   */
  +  public TestBDBJEDiskCacheConcurrent(String testName) {
  +    super(testName);
  +  }
  +
  +  /**
  +   * Main method passes this test to the text test runner.
  +   */
  +  public static void main(String args[]) {
  +    String[] testCaseName = {
  +        TestBDBJEDiskCacheConcurrent.class.getName()};
  +    junit.textui.TestRunner.main(testCaseName);
  +  }
  +
  +  /**
  +   * A unit test suite for JUnit
  +   *
  +   * @return    The test suite
  +   */
  +  public static Test suite() {
  +    ActiveTestSuite suite = new ActiveTestSuite();
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache1") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion4", 0, 200);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache2") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion4", 1000, 1200);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache3") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion4", 2000, 3200);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache4") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion4", 2200, 5200);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache5") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion4", 0, 10000);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache5") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion3", 0, 5000);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache5") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion2", 0, 5000);
  +      }
  +    });
  +
  +    suite.addTest(new TestBDBJE("testIndexedDiskCache5") {
  +      public void runTest() throws Exception {
  +        runTestForRegion("indexedRegion1", 0, 5000);
  +      }
  +    });
  +
  +    return suite;
  +  }
  +
  +  /**
  +   * Test setup
  +   */
  +  public void setUp() {
  +    JCS.setConfigFilename("/TestBDBJEDiskCacheCon.ccf");
  +  }
  +
  +  /**
  +   * Test tearDown.  Dispose of the cache.
  +   */
  +  public void tearDown() {
  +    try {
  +      CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
  +      cacheMgr.shutDown();
  +      /*
  +      String[] names = cacheMgr.getCacheNames();
  +      StringBuffer buf = new StringBuffer();
  +      int len = names.length;
  +      for (int i = 0; i < len; i++) {
  +        cacheMgr.freeCache(names[i]);
  +        buf.append("\n Freed cache region '" + names[i] + "'");
  +      }
  +      System.out.println( buf.toString() );
  +      */
       }
  -
  -    /**
  -     * Test setup
  -     */
  -    public void setUp()
  -    {
  -        JCS.setConfigFilename( "/TestBDBJEDiskCacheCon.ccf" );
  +    catch (Exception e) {
  +      //log.error(e);
       }
  +  }
   
  -
  -
  -//    /**
  -//     * Tests the region which uses the indexed disk cache
  -//     */
  -//    public void testIndexedDiskCache()
  -//        throws Exception
  -//    {
  -//        runTestForRegion( "indexedRegion" );
  -//    }
  -//
  -//    /**
  -//     * Tests the region which uses the indexed disk cache
  -//     */
  -//    public void testIndexedDiskCache2()
  -//        throws Exception
  -//    {
  -//        runTestForRegion( "indexedRegion2" );
  -//    }
  -
  -    /**
  -     * Adds items to cache, gets them, and removes them. The item count is more
  -     * than the size of the memory cache, so items should spool to disk.
  -     *
  -     * @param region Name of the region to access
  -     *
  -     * @exception Exception If an error occurs
  -     */
  -    public void runTestForRegion( String region, int start, int end )
  -        throws Exception
  -    {
  -        JCS jcs = JCS.getInstance( region );
  -
  -        // Add items to cache
  -
  -        for ( int i = start; i <= end; i++ )
  -        {
  -            jcs.put( i + ":key", region + " data " + i );
  -        }
  -
  -        // Test that all items are in cache
  -
  -        for ( int i = start; i <= end; i++ )
  -        {
  -            String value = ( String ) jcs.get( i + ":key" );
  -
  -            this.assertEquals( region + " data " + i, value );
  -        }
  -
  -/*// you can't remove in one thread and expect them to be in another
  -        // Remove all the items
  -
  -        for ( int i = start; i <= end; i++ )
  -        {
  -            jcs.remove( i + ":key" );
  -        }
  -
  -        // Verify removal
  -
  -        for ( int i = start; i <= end; i++ )
  -        {
  -            assertNull( "Removed key should be null: " + i + ":key",
  -                        jcs.get( i + ":key" ) );
  -        }
  -*/
  -
  -    }
   }
  
  
  
  1.1                  jakarta-turbine-jcs/src/test/org/apache/jcs/TestBDBJE.java
  
  Index: TestBDBJE.java
  ===================================================================
  package org.apache.jcs;
  
  import junit.framework.*;
  
  public class TestBDBJE
      extends TestCase {
  
    /**
     * Constructor for the TestDiskCache object.
     */
    public TestBDBJE(String testName) {
      super(testName);
    }
  
    /**
     * Adds items to cache, gets them, and removes them. The item count is more
     * than the size of the memory cache, so items should spool to disk.
     *
     * @param region Name of the region to access
     *
     * @exception Exception If an error occurs
     */
    public void runTestForRegion(String region, int start, int end) throws
        Exception {
      JCS jcs = JCS.getInstance(region);
  
      // Add items to cache
  
      for (int i = start; i <= end; i++) {
        jcs.put(i + ":key", region + " data " + i);
      }
  
      // Test that all items are in cache
  
      for (int i = start; i <= end; i++) {
        String value = (String) jcs.get(i + ":key");
  
        this.assertEquals(region + " data " + i, value);
      }
  
    }
  
    /**
     * Test setup
     */
    public void setUp() {
      JCS.setConfigFilename("/TestBDBJEDiskCacheCon.ccf");
    }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org