Package org.apache.avalon.excalibur.testcase

Examples of org.apache.avalon.excalibur.testcase.BufferedLogger


        String name = "testDefaults";
        getLogger().info( "Test: " + name );

        int size = PoolableComponentHandler.DEFAULT_MAX_POOL_SIZE + 2;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        // When objects are returned the pool, they are stored in a last in first off list.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here


        String name = "testMax4";
        getLogger().info( "Test: " + name );

        int size = 4 + 1;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

        String name = "testMax4StrictNoBlocking";
        getLogger().info( "Test: " + name );

        int size = 4;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Try to get one more.  Should fail.
        try
        {
            lookup( PoolableTestObjectInterface.ROLE + "/" + name );
            fail( "Attempt to get more Pollables than are in the pool should have failed." );
        }
        catch( Exception e )
        {
            // Passed
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

        int size = 3;

        // Initialize the exception field.
        m_exception = null;

        final BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // In another thread, get and release another poolable to cause this one to wait.
        TestMax4StrictBlockingThread secondThread = new TestMax4StrictBlockingThread( manager, logger );
        secondThread.start();

        // Give the second thread a chance to get the 4th poolable
        try
        {
            Thread.sleep( 250 );
        }
        catch( InterruptedException e )
        {
        }

        // Try to get one more.  Should block until the other thread has put it back.
        logger.debug( "Lookup in main thread." );
        PoolableTestObjectInterface poolable =
            (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );

        logger.debug( "Release in main thread." );
        release( (Component)poolable );

        secondThread.join();

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Make sure that the second thread did not throw an exception
        assertTrue( "Unexpected exception in second thread.", m_exception == null );

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - Lookup in second thread.\n" +
View Full Code Here

        String name = "testMax4StrictBlockingTimeout";
        getLogger().info( "Test: " + name );

        int size = 4;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Try to get one more.  Should fail after 500 milliseconds.
        long start = System.currentTimeMillis();
        try
        {
            lookup( PoolableTestObjectInterface.ROLE + "/" + name );
            fail( "Attempt to get more Pollables than are in the pool should have failed." );
        }
        catch( Exception e )
        {
            // Passed
        }
        long dur = System.currentTimeMillis() - start;
        assertTrue( "Block timeout was not within 50 milliseconds of the configured 500 milliseconds,",
                    dur >= 450 && dur <= 550 );

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

    public void testTrimming() throws Exception
    {
        String name = "testTrimming";
        getLogger().info( "Test: " + name );

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ 4 ];

        // Lookup and release all 4 components a couple of times.
        for( int i = 0; i < 4; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }
        for( int i = 0; i < 4; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }
        for( int i = 0; i < 4; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }
        for( int i = 0; i < 4; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Now wait for 550 ms to trigger a trim on the next lookup.
        try
        {
            Thread.sleep( 550 );
        }
        catch( InterruptedException e )
        {
        }

        // Lookup and release 2 components to mark them as being recently used.
        for( int i = 0; i < 2; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }
        for( int i = 0; i < 2; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Now wait for 550 ms to trigger a trim on the next lookup.
        try
        {
            Thread.sleep( 550 );
        }
        catch( InterruptedException e )
        {
        }

        // This next get should cause 2 of the components to be trimmed but the 2 we just lookedup
        //  should stay around.
        // Lookup and release all 4 components to see which ones are left.
        for( int i = 0; i < 4; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }
        for( int i = 0; i < 4; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }


        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" + // First 4 lookups
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

        String name = "testDefaults";
        getLogger().info( "Test: " + name );

        int size = PoolableComponentHandler.DEFAULT_MAX_POOL_SIZE + 2;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        // When objects are returned the pool, they are stored in a last in first off list.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

        String name = "testMax4";
        getLogger().info( "Test: " + name );

        int size = 4 + 1;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

        String name = "testMax4StrictNoBlocking";
        getLogger().info( "Test: " + name );

        int size = 4;

        BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // Try to get one more.  Should fail.
        try
        {
            lookup( PoolableTestObjectInterface.ROLE + "/" + name );
            fail( "Attempt to get more Pollables than are in the pool should have failed." );
        }
        catch( Exception e )
        {
            // Passed
        }

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - PoolableTestObject #4 initialized.\n" +
View Full Code Here

        int size = 3;

        // Initialize the exception field.
        m_exception = null;

        final BufferedLogger logger = new BufferedLogger();
        PoolableTestObject.setStaticLoggger( logger );
        PoolableTestObject.resetInstanceCounter();

        PoolableTestObjectInterface[] poolables = new PoolableTestObjectInterface[ size ];

        // Lookup the components.
        for( int i = 0; i < size; i++ )
        {
            poolables[ i ] =
                (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );
        }

        // In another thread, get and release another poolable to cause this one to wait.
        TestMax4StrictBlockingThread secondThread = new TestMax4StrictBlockingThread( manager, logger );
        secondThread.start();

        // Give the second thread a chance to get the 4th poolable
        try
        {
            Thread.sleep( 250 );
        }
        catch( InterruptedException e )
        {
        }

        // Try to get one more.  Should block until the other thread has put it back.
        logger.debug( "Lookup in main thread." );
        PoolableTestObjectInterface poolable =
            (PoolableTestObjectInterface)lookup( PoolableTestObjectInterface.ROLE + "/" + name );

        logger.debug( "Release in main thread." );
        release( (Component)poolable );

        secondThread.join();

        // Release the components.
        for( int i = 0; i < size; i++ )
        {
            release( (Component)poolables[ i ] );
            poolables[ i ] = null;
        }

        // Make sure that the second thread did not throw an exception
        assertTrue( "Unexpected exception in second thread.", m_exception == null );

        // The disposal of the objects will not show up in the log until the component manager is
        //  actually disposed.
        String resultLog = logger.toString();
        String expectedLog =
            "DEBUG - PoolableTestObject #1 initialized.\n" +
            "DEBUG - PoolableTestObject #2 initialized.\n" +
            "DEBUG - PoolableTestObject #3 initialized.\n" +
            "DEBUG - Lookup in second thread.\n" +
View Full Code Here

TOP

Related Classes of org.apache.avalon.excalibur.testcase.BufferedLogger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.