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/03/15 05:56:28 UTC
cvs commit: jakarta-avalon/src/test/org/apache/avalon/util/test BinaryHeapTestlet.java DependencyGraphTestlet.java PropertyUtilTestlet.java ProxyGeneratorTestlet.java StringUtilTestlet.java
donaldp 01/03/14 20:56:28
Modified: src/java/org/apache/avalon Parameters.java
src/java/org/apache/avalon/camelot CamelotUtil.java
Added: src/test/org/apache/avalon/util/cli/test ClutilTestlet.java
src/test/org/apache/avalon/util/datasource/test
DataSourceTestlet.java
src/test/org/apache/avalon/util/io/test FileUtilTestlet.java
src/test/org/apache/avalon/util/pool/test PoolProfile.java
src/test/org/apache/avalon/util/test BinaryHeapTestlet.java
DependencyGraphTestlet.java
PropertyUtilTestlet.java ProxyGeneratorTestlet.java
StringUtilTestlet.java
Removed: src/java/org/apache/avalon/util/cli/test ClutilTestlet.java
src/java/org/apache/avalon/util/datasource/test
DataSourceTestlet.java
src/java/org/apache/avalon/util/io/test FileUtilTestlet.java
src/java/org/apache/avalon/util/pool/test PoolProfile.java
src/java/org/apache/avalon/util/test BinaryHeapTestlet.java
DependencyGraphTestlet.java
PropertyUtilTestlet.java ProxyGeneratorTestlet.java
StringUtilTestlet.java
Log:
Moved test cases to their own hierarchy.
Revision Changes Path
1.4 +8 -4 jakarta-avalon/src/java/org/apache/avalon/Parameters.java
Index: Parameters.java
===================================================================
RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/Parameters.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parameters.java 2001/03/11 20:57:34 1.3
+++ Parameters.java 2001/03/15 04:56:23 1.4
@@ -300,17 +300,21 @@
/**
* Create a <code>Parameters</code> object from a <code>Configuration</code>
* object.
+ * @deprecated Will be removed when old config removed
*/
- public static Parameters fromConfiguration( final org.apache.avalon.configuration.Configuration configuration )
+ public static Parameters
+ fromConfiguration( final org.apache.avalon.configuration.Configuration configuration )
throws org.apache.avalon.configuration.ConfigurationException
{
if( null == configuration )
{
- throw new org.apache.avalon.configuration.ConfigurationException( "You cannot convert to parameters with " +
- "a null Configuration");
+ throw new org.apache.avalon.configuration.
+ ConfigurationException( "You cannot convert to parameters with " +
+ "a null Configuration" );
}
- final org.apache.avalon.configuration.Configuration[] parameters = configuration.getChildren("parameter");
+ final org.apache.avalon.configuration.Configuration[] parameters =
+ configuration.getChildren( "parameter" );
final Parameters param = new Parameters();
for (int i = 0; i < parameters.length; i++ )
1.2 +11 -0 jakarta-avalon/src/java/org/apache/avalon/camelot/CamelotUtil.java
Index: CamelotUtil.java
===================================================================
RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/camelot/CamelotUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CamelotUtil.java 2001/02/24 04:00:36 1.1
+++ CamelotUtil.java 2001/03/15 04:56:23 1.2
@@ -9,10 +9,12 @@
import java.io.File;
import java.io.IOException;
+import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.util.Iterator;
import org.apache.avalon.Component;
import org.apache.avalon.util.io.ExtensionFileFilter;
+import org.apache.avalon.util.io.DirectoryFileFilter;
/**
* Utility methods for Camelot related facilities.
@@ -43,6 +45,15 @@
{
final ExtensionFileFilter filter = new ExtensionFileFilter( extentions );
+ deployFromDirectory( deployer, directory, filter );
+ }
+
+ public static void deployFromDirectory( final Deployer deployer,
+ final File directory,
+ final FilenameFilter filter )
+ throws DeploymentException
+
+ {
final File[] files = directory.listFiles( filter );
if( null != files )
1.1 jakarta-avalon/src/test/org/apache/avalon/util/cli/test/ClutilTestlet.java
Index: ClutilTestlet.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 file.
*/
package org.apache.avalon.util.cli.test;
import java.util.List;
import org.apache.avalon.util.cli.AbstractParserControl;
import org.apache.avalon.util.cli.CLArgsParser;
import org.apache.avalon.util.cli.CLOption;
import org.apache.avalon.util.cli.CLOptionDescriptor;
import org.apache.avalon.util.cli.ParserControl;
import org.apache.testlet.AbstractTestlet;
/**
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class ClutilTestlet
extends AbstractTestlet
{
protected final static String[] ARGLIST1 =
{
"--you","are","--all","-cler","kid"
};
protected final static String[] ARGLIST2 =
{
"-Dstupid=idiot","are","--all","here"
};
protected final static String[] ARGLIST3 =
{
//duplicates
"-Dstupid=idiot","are","--all","--all","here"
};
protected final static String[] ARGLIST4 =
{
//incompatable (blee/all)
"-Dstupid=idiot","are","--all","--blee","here"
};
protected final static String[] ARGLIST5 =
{
"-f","myfile.txt"
};
private static final int DEFINE_OPT = 'D';
private static final int YOU_OPT = 'y';
private static final int ALL_OPT = 'a';
private static final int CLEAR1_OPT = 'c';
private static final int CLEAR2_OPT = 'l';
private static final int CLEAR3_OPT = 'e';
private static final int CLEAR5_OPT = 'r';
private static final int BLEE_OPT = 'b';
private static final int FILE_OPT = 'f';
protected final static CLOptionDescriptor DEFINE =
new CLOptionDescriptor( "define",
CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
DEFINE_OPT,
"define" );
protected final static CLOptionDescriptor YOU =
new CLOptionDescriptor( "you", CLOptionDescriptor.ARGUMENT_DISALLOWED, YOU_OPT, "you" );
protected final static CLOptionDescriptor ALL =
new CLOptionDescriptor( "all",
CLOptionDescriptor.ARGUMENT_DISALLOWED,
ALL_OPT,
"all",
new int[] { BLEE_OPT } );
protected final static CLOptionDescriptor CLEAR1 =
new CLOptionDescriptor( "c", CLOptionDescriptor.ARGUMENT_DISALLOWED, CLEAR1_OPT, "c" );
protected final static CLOptionDescriptor CLEAR2 =
new CLOptionDescriptor( "l", CLOptionDescriptor.ARGUMENT_DISALLOWED, CLEAR2_OPT, "l" );
protected final static CLOptionDescriptor CLEAR3 =
new CLOptionDescriptor( "e", CLOptionDescriptor.ARGUMENT_DISALLOWED, CLEAR3_OPT, "e" );
protected final static CLOptionDescriptor CLEAR5 =
new CLOptionDescriptor( "r", CLOptionDescriptor.ARGUMENT_DISALLOWED, CLEAR5_OPT, "r" );
protected final static CLOptionDescriptor BLEE =
new CLOptionDescriptor( "blee",
CLOptionDescriptor.ARGUMENT_DISALLOWED,
BLEE_OPT,
"blee" );
protected final static CLOptionDescriptor FILE =
new CLOptionDescriptor( "file",
CLOptionDescriptor.ARGUMENT_REQUIRED,
FILE_OPT,
"the build file." );
public void testFullParse()
{
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
YOU, ALL, CLEAR1, CLEAR2, CLEAR3, CLEAR5
};
final CLArgsParser parser = new CLArgsParser( ARGLIST1, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 8 );
assertEquality( ((CLOption)clOptions.get( 0 )).getId(), YOU_OPT );
assertEquality( ((CLOption)clOptions.get( 1 )).getId(), 0 );
assertEquality( ((CLOption)clOptions.get( 2 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions.get( 3 )).getId(), CLEAR1_OPT );
assertEquality( ((CLOption)clOptions.get( 4 )).getId(), CLEAR2_OPT );
assertEquality( ((CLOption)clOptions.get( 5 )).getId(), CLEAR3_OPT );
assertEquality( ((CLOption)clOptions.get( 6 )).getId(), CLEAR5_OPT );
assertEquality( ((CLOption)clOptions.get( 7 )).getId(), 0 );
}
public void testDuplicateOptions()
{
//"-Dstupid=idiot","are","--all","--all","here"
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
DEFINE, ALL, CLEAR1
};
final CLArgsParser parser = new CLArgsParser( ARGLIST3, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 5 );
assertEquality( ((CLOption)clOptions.get( 0 )).getId(), DEFINE_OPT );
assertEquality( ((CLOption)clOptions.get( 1 )).getId(), 0 );
assertEquality( ((CLOption)clOptions.get( 2 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions.get( 3 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions.get( 4 )).getId(), 0 );
}
public void testIncompatableOptions()
{
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
DEFINE, ALL, CLEAR1, BLEE
};
final CLArgsParser parser = new CLArgsParser( ARGLIST4, options );
assertNotNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 5 );
assertEquality( ((CLOption)clOptions.get( 0 )).getId(), DEFINE_OPT );
assertEquality( ((CLOption)clOptions.get( 1 )).getId(), 0 );
assertEquality( ((CLOption)clOptions.get( 2 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions.get( 3 )).getId(), BLEE_OPT );
assertEquality( ((CLOption)clOptions.get( 4 )).getId(), 0 );
}
public void testSingleArg()
{
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
FILE
};
final CLArgsParser parser = new CLArgsParser( ARGLIST5, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 1 );
assertEquality( ((CLOption)clOptions.get( 0 )).getId(), FILE_OPT );
assertEquality( ((CLOption)clOptions.get( 0 )).getArgument(), "myfile.txt" );
}
public void test2ArgsParse()
{
//"-Dstupid=idiot","are","--all","here"
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
DEFINE, ALL, CLEAR1
};
final CLArgsParser parser = new CLArgsParser( ARGLIST2, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 4 );
assertEquality( ((CLOption)clOptions.get( 0 )).getId(), DEFINE_OPT );
assertEquality( ((CLOption)clOptions.get( 1 )).getId(), 0 );
assertEquality( ((CLOption)clOptions.get( 2 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions.get( 3 )).getId(), 0 );
final CLOption option = (CLOption)clOptions.get( 0 );
assertEquality( "stupid", option.getArgument( 0 ) );
assertEquality( "idiot", option.getArgument( 1 ) );
}
public void testPartParse()
{
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
YOU
};
final ParserControl control = new AbstractParserControl()
{
public boolean isFinished( int lastOptionCode )
{
return (lastOptionCode == YOU_OPT);
}
};
final CLArgsParser parser = new CLArgsParser( ARGLIST1, options, control );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 1 );
assertEquality( ((CLOption)clOptions.get( 0 )).getId(), YOU_OPT );
}
public void test2PartParse()
{
final CLOptionDescriptor[] options1 = new CLOptionDescriptor[]
{
YOU
};
final CLOptionDescriptor[] options2 = new CLOptionDescriptor[]
{
ALL, CLEAR1, CLEAR2, CLEAR3, CLEAR5
};
final ParserControl control1 = new AbstractParserControl()
{
public boolean isFinished( int lastOptionCode )
{
return (lastOptionCode == YOU_OPT);
}
};
final CLArgsParser parser1 = new CLArgsParser( ARGLIST1, options1, control1 );
assertNull( parser1.getErrorString() );
final List clOptions1 = parser1.getArguments();
final int size1 = clOptions1.size();
assertEquality( size1, 1 );
assertEquality( ((CLOption)clOptions1.get( 0 )).getId(), YOU_OPT );
final CLArgsParser parser2 =
new CLArgsParser( parser1.getUnparsedArgs(), options2 );
assertNull( parser2.getErrorString() );
final List clOptions2 = parser2.getArguments();
final int size2 = clOptions2.size();
assertEquality( size2, 7 );
assertEquality( ((CLOption)clOptions2.get( 0 )).getId(), 0 );
assertEquality( ((CLOption)clOptions2.get( 1 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions2.get( 2 )).getId(), CLEAR1_OPT );
assertEquality( ((CLOption)clOptions2.get( 3 )).getId(), CLEAR2_OPT );
assertEquality( ((CLOption)clOptions2.get( 4 )).getId(), CLEAR3_OPT );
assertEquality( ((CLOption)clOptions2.get( 5 )).getId(), CLEAR5_OPT );
assertEquality( ((CLOption)clOptions2.get( 6 )).getId(), 0 );
}
public void test2PartPartialParse()
{
final CLOptionDescriptor[] options1 = new CLOptionDescriptor[]
{
YOU, ALL, CLEAR1
};
final CLOptionDescriptor[] options2 = new CLOptionDescriptor[] {};
final ParserControl control1 = new AbstractParserControl()
{
public boolean isFinished( final int lastOptionCode )
{
return (lastOptionCode == CLEAR1_OPT);
}
};
final CLArgsParser parser1 = new CLArgsParser( ARGLIST1, options1, control1 );
assertNull( parser1.getErrorString() );
final List clOptions1 = parser1.getArguments();
final int size1 = clOptions1.size();
assertEquality( size1, 4 );
assertEquality( ((CLOption)clOptions1.get( 0 )).getId(), YOU_OPT );
assertEquality( ((CLOption)clOptions1.get( 1 )).getId(), 0 );
assertEquality( ((CLOption)clOptions1.get( 2 )).getId(), ALL_OPT );
assertEquality( ((CLOption)clOptions1.get( 3 )).getId(), CLEAR1_OPT );
assert( parser1.getUnparsedArgs()[0].equals("ler") );
final CLArgsParser parser2 =
new CLArgsParser( parser1.getUnparsedArgs(), options2 );
assertNull( parser2.getErrorString() );
final List clOptions2 = parser2.getArguments();
final int size2 = clOptions2.size();
assertEquality( size2, 2 );
assertEquality( ((CLOption)clOptions2.get( 0 )).getId(), 0 );
assertEquality( ((CLOption)clOptions2.get( 1 )).getId(), 0 );
}
public void testDuplicatesFail()
{
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
YOU, ALL, CLEAR1, CLEAR2, CLEAR3, CLEAR5
};
//duplicate as
final String[] DUPLICATE_ARGLIST =
{
"--you","are","--all","-clear","kid"
};
final CLArgsParser parser = new CLArgsParser( ARGLIST1, options );
assertNull( parser.getErrorString() );
}
public void testIncomplete2Args()
{
//"-Dstupid="
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
DEFINE
};
final CLArgsParser parser = new CLArgsParser( new String[] { "-Dstupid=" }, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 1 );
final CLOption option = (CLOption)clOptions.get( 0 );
assertEquality( option.getId(), DEFINE_OPT );
assertEquality( option.getArgument( 0 ), "stupid" );
assertEquality( option.getArgument( 1 ), "" );
}
public void testIncomplete2ArgsMixed()
{
//"-Dstupid=","-c"
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
DEFINE, CLEAR1
};
final String[] args = new String[] { "-Dstupid=", "-c" };
final CLArgsParser parser = new CLArgsParser( args, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 2 );
assertEquality( ((CLOption)clOptions.get( 1 )).getId(), CLEAR1_OPT );
final CLOption option = (CLOption)clOptions.get( 0 );
assertEquality( option.getId(), DEFINE_OPT );
assertEquality( option.getArgument( 0 ), "stupid" );
assertEquality( option.getArgument( 1 ), "" );
}
public void fail_testIncomplete2ArgsMixedNoEq()
{
//"-Dstupid","-c"
final CLOptionDescriptor[] options = new CLOptionDescriptor[]
{
DEFINE, CLEAR1
};
final String[] args = new String[] { "-Dstupid", "-c" };
final CLArgsParser parser = new CLArgsParser( args, options );
assertNull( parser.getErrorString() );
final List clOptions = parser.getArguments();
final int size = clOptions.size();
assertEquality( size, 2 );
assertEquality( ((CLOption)clOptions.get( 1 )).getId(), CLEAR1_OPT );
final CLOption option = (CLOption)clOptions.get( 0 );
assertEquality( option.getId(), DEFINE_OPT );
assertEquality( option.getArgument( 0 ), "stupid" );
assertEquality( option.getArgument( 1 ), "" );
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/datasource/test/DataSourceTestlet.java
Index: DataSourceTestlet.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 file.
*/
package org.apache.avalon.util.datasource.test;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Random;
import org.apache.avalon.configuration.Configuration;
import org.apache.avalon.configuration.ConfigurationException;
import org.apache.avalon.configuration.DefaultConfiguration;
import org.apache.avalon.util.datasource.DataSourceComponent;
import org.apache.avalon.util.datasource.JdbcDataSource;
import org.apache.log.LogKit;
import org.apache.testlet.AbstractTestlet;
/**
* Test the DataSource Component. I don't know how to make this generic,
* so I'll throw some bones out there, and hope someone can set this up
* better.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
*/
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 );
conf = dc;
LogKit.setGlobalPriority( org.apache.log.Priority.INFO );
try
{
Class.forName( "Your Driver Class Here" );
}
catch( final Exception e )
{
LogKit.getLoggerFor( "test" ).error( e.getMessage(), e );
}
}
public void testOverAllocation()
{
boolean result = false;
JdbcDataSource ds = new JdbcDataSource();
ds.setLogger( LogKit.getLoggerFor( "test" ) );
try
{
ds.configure( conf );
}
catch( final ConfigurationException ce )
{
assert( "Over Allocation Test", false );
}
try
{
for( int i = 0; i < 11; i++ )
{
ds.getConnection();
}
}
catch( final SQLException se )
{
result = true;
LogKit.getLoggerFor( "test" ).info( "The test was successful" );
}
assert( "Over Allocation Test", result );
}
public void testNormalUse()
{
boolean result = true;
JdbcDataSource ds = new JdbcDataSource();
ds.setLogger( LogKit.getLoggerFor( "test" ) );
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( this, ds ) );
Thread two = new Thread( new ConnectionThread( this, ds ) );
one.start();
two.start();
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 );
}
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 );
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/io/test/FileUtilTestlet.java
Index: FileUtilTestlet.java
===================================================================
/*
* Copyright 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 file.
*/
package org.apache.avalon.util.io.test;
import java.io.*;
import org.apache.avalon.util.io.FileUtil;
import org.apache.testlet.AbstractTestlet;
import org.apache.testlet.TestFailedException;
/**
* This is used to test FileUtil for correctness.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class FileUtilTestlet
extends AbstractTestlet
{
protected final int FILE1_SIZE = 1;
protected final int FILE2_SIZE = 1024 * 4 + 1;
protected final File m_testDirectory;
protected final File m_testFile1;
protected final File m_testFile2;
public FileUtilTestlet()
throws IOException
{
m_testDirectory = (new File( "test/io/" )).getAbsoluteFile();
if( !m_testDirectory.exists() )
{
m_testDirectory.mkdirs();
}
m_testFile1 = new File( m_testDirectory, "file1-test.txt" );
m_testFile2 = new File( m_testDirectory, "file2-test.txt" );
createFile( m_testFile1, FILE1_SIZE );
createFile( m_testFile2, FILE2_SIZE );
}
protected void createFile( final File file, final long size )
throws IOException
{
final BufferedOutputStream output =
new BufferedOutputStream( new FileOutputStream( file ) );
for( int i = 0; i < size; i++ )
{
output.write( (byte)'X' );
}
output.close();
}
public void testCopyFile1()
throws Exception
{
final File destination = new File( m_testDirectory, "copy1.txt" );
FileUtil.copyFile( m_testFile1, destination );
assert( "Check Exist", destination.exists() );
assert( "Check Full copy", destination.length() == FILE1_SIZE );
}
public void testCopyFile2()
throws Exception
{
final File destination = new File( m_testDirectory, "copy2.txt" );
FileUtil.copyFile( m_testFile2, destination );
assert( "Check Exist", destination.exists() );
assert( "Check Full copy", destination.length() == FILE2_SIZE );
}
public void testForceDeleteFile1()
throws Exception
{
final File destination = new File( m_testDirectory, "copy1.txt" );
FileUtil.forceDelete( destination );
assert( "Check No Exist", !destination.exists() );
}
public void testForceDeleteFile2()
throws Exception
{
final File destination = new File( m_testDirectory, "copy2.txt" );
FileUtil.forceDelete( destination );
assert( "Check No Exist", !destination.exists() );
}
public void testCopyFile1ToDir()
throws Exception
{
final File directory = new File( m_testDirectory, "subdir" );
if( !directory.exists() ) directory.mkdirs();
final File destination = new File( directory, "file1-test.txt" );
FileUtil.copyFileToDirectory( m_testFile1, directory );
assert( "Check Exist", destination.exists() );
assert( "Check Full copy", destination.length() == FILE1_SIZE );
}
public void testCopyFile2ToDir()
throws Exception
{
final File directory = new File( m_testDirectory, "subdir" );
if( !directory.exists() ) directory.mkdirs();
final File destination = new File( directory, "file2-test.txt" );
FileUtil.copyFileToDirectory( m_testFile2, directory );
assert( "Check Exist", destination.exists() );
assert( "Check Full copy", destination.length() == FILE2_SIZE );
}
public void testForceDeleteDir()
throws Exception
{
FileUtil.forceDelete( m_testDirectory.getParentFile() );
assert( "Check No Exist", !m_testDirectory.getParentFile().exists() );
}
public void testResolveFileDotDot()
throws Exception
{
final File file = FileUtil.resolveFile( m_testDirectory, ".." );
assertEquality( "Check .. operator", file, m_testDirectory.getParentFile() );
}
public void testResolveFileDot()
throws Exception
{
final File file = FileUtil.resolveFile( m_testDirectory, "." );
assertEquality( "Check . operator", file, m_testDirectory );
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/pool/test/PoolProfile.java
Index: PoolProfile.java
===================================================================
/*
* Copyright 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 file.
*/
package org.apache.avalon.util.pool.test;
import org.apache.avalon.Poolable;
import org.apache.avalon.util.pool.DefaultPool;
import org.apache.avalon.util.pool.Pool;
import org.apache.avalon.util.pool.HardResourceLimitingPool;
import org.apache.testlet.*;
/**
* This is used to profile the Pool implementation.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class PoolProfile
extends AbstractTestlet
{
public static class A
implements Poolable
{
int a;
int b;
int c;
float x;
float y;
float z;
}
public static class B
implements Poolable
{
int a;
int b;
int c;
float x;
float y;
float z;
Object o1;
Object o2;
Object o3;
public void recycle()
{
o1 = o2 = o3 = null;
}
}
public static class C
implements Poolable
{
int a;
int b;
int c;
float x;
float y;
float z;
Object o1;
Object o2;
Object o3;
Object o4;
Object o5;
Object o6;
public void build()
{
o1 = new Object();
o2 = new Object();
o3 = new Object();
o4 = new Object();
o5 = new Object();
o6 = new Object();
}
public void recycle()
{
o1 = o2 = o3 = o4 = o5 = o6 = null;
}
}
protected static final int TEST_SIZE = 1000000;
public void testSmallObjects()
throws Exception
{
System.out.println("SMALL Sized Objects");
final DefaultPool pool1 = new DefaultPool( A.class, 5, 10 );
final long pool1Start = System.currentTimeMillis();
final int pool1Factor = 1;
final int pool1Loops = TEST_SIZE / pool1Factor;
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = pool1.get();
pool1.put(a1);
}
final long pool1End = System.currentTimeMillis();
final long pool1Duration = pool1End - pool1Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool2 = new DefaultPool( A.class, 5, 10 );
final long pool2Start = System.currentTimeMillis();
final int pool2Factor = 10;
final int pool2Loops = TEST_SIZE / pool2Factor;
for( int i = 0; i < pool2Loops; i++ )
{
final Poolable a1 = pool2.get();
final Poolable a2 = pool2.get();
final Poolable a3 = pool2.get();
final Poolable a4 = pool2.get();
final Poolable a5 = pool2.get();
final Poolable a6 = pool2.get();
final Poolable a7 = pool2.get();
final Poolable a8 = pool2.get();
final Poolable a9 = pool2.get();
final Poolable a0 = pool2.get();
pool2.put(a1);
pool2.put(a2);
pool2.put(a3);
pool2.put(a4);
pool2.put(a5);
pool2.put(a6);
pool2.put(a7);
pool2.put(a8);
pool2.put(a9);
pool2.put(a0);
}
final long pool2End = System.currentTimeMillis();
final long pool2Duration = pool2End - pool2Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool3 = new DefaultPool( A.class, 5, 10 );
final long pool3Start = System.currentTimeMillis();
final int pool3Factor = 15;
final int pool3Loops = TEST_SIZE / pool3Factor;
for( int i = 0; i < pool3Loops; i++ )
{
final Poolable a1 = pool3.get();
final Poolable a2 = pool3.get();
final Poolable a3 = pool3.get();
final Poolable a4 = pool3.get();
final Poolable a5 = pool3.get();
final Poolable a6 = pool3.get();
final Poolable a7 = pool3.get();
final Poolable a8 = pool3.get();
final Poolable a9 = pool3.get();
final Poolable a10 = pool3.get();
final Poolable a11 = pool3.get();
final Poolable a12 = pool3.get();
final Poolable a13 = pool3.get();
final Poolable a14 = pool3.get();
final Poolable a15 = pool3.get();
pool3.put(a1);
pool3.put(a2);
pool3.put(a3);
pool3.put(a4);
pool3.put(a5);
pool3.put(a6);
pool3.put(a7);
pool3.put(a8);
pool3.put(a9);
pool3.put(a10);
pool3.put(a11);
pool3.put(a12);
pool3.put(a13);
pool3.put(a14);
pool3.put(a15);
}
final long pool3End = System.currentTimeMillis();
final long pool3Duration = pool3End - pool3Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool4 = new DefaultPool( A.class, 5, 10 );
final long pool4Start = System.currentTimeMillis();
final int pool4Factor = 20;
final int pool4Loops = TEST_SIZE / pool4Factor;
for( int i = 0; i < pool4Loops; i++ )
{
final Poolable a1 = pool4.get();
final Poolable a2 = pool4.get();
final Poolable a3 = pool4.get();
final Poolable a4 = pool4.get();
final Poolable a5 = pool4.get();
final Poolable a6 = pool4.get();
final Poolable a7 = pool4.get();
final Poolable a8 = pool4.get();
final Poolable a9 = pool4.get();
final Poolable a10 = pool4.get();
final Poolable a11 = pool4.get();
final Poolable a12 = pool4.get();
final Poolable a13 = pool4.get();
final Poolable a14 = pool4.get();
final Poolable a15 = pool4.get();
final Poolable a16 = pool4.get();
final Poolable a17 = pool4.get();
final Poolable a18 = pool4.get();
final Poolable a19 = pool4.get();
final Poolable a20 = pool4.get();
pool4.put(a1);
pool4.put(a2);
pool4.put(a3);
pool4.put(a4);
pool4.put(a5);
pool4.put(a6);
pool4.put(a7);
pool4.put(a8);
pool4.put(a9);
pool4.put(a10);
pool4.put(a11);
pool4.put(a12);
pool4.put(a13);
pool4.put(a14);
pool4.put(a15);
pool4.put(a16);
pool4.put(a17);
pool4.put(a18);
pool4.put(a19);
pool4.put(a20);
}
final long pool4End = System.currentTimeMillis();
final long pool4Duration = pool4End - pool4Start;
System.out.println("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
final long createStart = System.currentTimeMillis();
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = new C();
}
final long createEnd = System.currentTimeMillis();
final long createDuration = createEnd - createStart;
//System.out.println("Create Duration: " + createDuration + "ms ");
System.out.println("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
final double pool1Efficiancy = (double)createDuration/(double)pool1Duration * 100.0;
final double pool2Efficiancy = (double)createDuration/(double)pool2Duration * 100.0;
final double pool3Efficiancy = (double)createDuration/(double)pool3Duration * 100.0;
final double pool4Efficiancy = (double)createDuration/(double)pool4Duration * 100.0;
//System.out.println("Pool Duration for 100% hits: " + pool1Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits: " + pool1Efficiancy + "ms ");
//System.out.println("Pool Duration for 100% hits and saturated: " + pool2Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits and saturated: " + pool2Efficiancy + "ms ");
//System.out.println("Pool Duration for 60% hits: " + pool3Duration + "ms ");
System.out.println("Pool Efficiancy for 60% hits: " + pool3Efficiancy + "ms ");
//System.out.println("Pool Duration for 50% hits: " + pool4Duration + "ms ");
System.out.println("Pool Efficiancy for 50% hits: " + pool4Efficiancy + "ms ");
}
public void testMediumObjects()
throws Exception
{
System.out.println("MEDIUM Sized Objects");
System.gc();
System.gc();
Thread.currentThread().sleep(2);
final DefaultPool pool1 = new DefaultPool( B.class, 5, 10 );
final long pool1Start = System.currentTimeMillis();
final int pool1Factor = 1;
final int pool1Loops = TEST_SIZE / pool1Factor;
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = pool1.get();
pool1.put(a1);
}
final long pool1End = System.currentTimeMillis();
final long pool1Duration = pool1End - pool1Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool2 = new DefaultPool( B.class, 5, 10 );
final long pool2Start = System.currentTimeMillis();
final int pool2Factor = 10;
final int pool2Loops = TEST_SIZE / pool2Factor;
for( int i = 0; i < pool2Loops; i++ )
{
final Poolable a1 = pool2.get();
final Poolable a2 = pool2.get();
final Poolable a3 = pool2.get();
final Poolable a4 = pool2.get();
final Poolable a5 = pool2.get();
final Poolable a6 = pool2.get();
final Poolable a7 = pool2.get();
final Poolable a8 = pool2.get();
final Poolable a9 = pool2.get();
final Poolable a10 = pool2.get();
pool2.put(a1);
pool2.put(a2);
pool2.put(a3);
pool2.put(a4);
pool2.put(a5);
pool2.put(a6);
pool2.put(a7);
pool2.put(a8);
pool2.put(a9);
pool2.put(a10);
}
final long pool2End = System.currentTimeMillis();
final long pool2Duration = pool2End - pool2Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool3 = new DefaultPool( B.class, 5, 10 );
final long pool3Start = System.currentTimeMillis();
final int pool3Factor = 15;
final int pool3Loops = TEST_SIZE / pool3Factor;
for( int i = 0; i < pool3Loops; i++ )
{
final Poolable a1 = pool3.get();
final Poolable a2 = pool3.get();
final Poolable a3 = pool3.get();
final Poolable a4 = pool3.get();
final Poolable a5 = pool3.get();
final Poolable a6 = pool3.get();
final Poolable a7 = pool3.get();
final Poolable a8 = pool3.get();
final Poolable a9 = pool3.get();
final Poolable a10 = pool3.get();
final Poolable a11 = pool3.get();
final Poolable a12 = pool3.get();
final Poolable a13 = pool3.get();
final Poolable a14 = pool3.get();
final Poolable a15 = pool3.get();
pool3.put(a1);
pool3.put(a2);
pool3.put(a3);
pool3.put(a4);
pool3.put(a5);
pool3.put(a6);
pool3.put(a7);
pool3.put(a8);
pool3.put(a9);
pool3.put(a10);
pool3.put(a11);
pool3.put(a12);
pool3.put(a13);
pool3.put(a14);
pool3.put(a15);
}
final long pool3End = System.currentTimeMillis();
final long pool3Duration = pool3End - pool3Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool4 = new DefaultPool( B.class, 5, 10 );
final long pool4Start = System.currentTimeMillis();
final int pool4Factor = 20;
final int pool4Loops = TEST_SIZE / pool4Factor;
for( int i = 0; i < pool4Loops; i++ )
{
final Poolable a1 = pool4.get();
final Poolable a2 = pool4.get();
final Poolable a3 = pool4.get();
final Poolable a4 = pool4.get();
final Poolable a5 = pool4.get();
final Poolable a6 = pool4.get();
final Poolable a7 = pool4.get();
final Poolable a8 = pool4.get();
final Poolable a9 = pool4.get();
final Poolable a10 = pool4.get();
final Poolable a11 = pool4.get();
final Poolable a12 = pool4.get();
final Poolable a13 = pool4.get();
final Poolable a14 = pool4.get();
final Poolable a15 = pool4.get();
final Poolable a16 = pool4.get();
final Poolable a17 = pool4.get();
final Poolable a18 = pool4.get();
final Poolable a19 = pool4.get();
final Poolable a20 = pool4.get();
pool4.put(a1);
pool4.put(a2);
pool4.put(a3);
pool4.put(a4);
pool4.put(a5);
pool4.put(a6);
pool4.put(a7);
pool4.put(a8);
pool4.put(a9);
pool4.put(a10);
pool4.put(a11);
pool4.put(a12);
pool4.put(a13);
pool4.put(a14);
pool4.put(a15);
pool4.put(a16);
pool4.put(a17);
pool4.put(a18);
pool4.put(a19);
pool4.put(a20);
}
final long pool4End = System.currentTimeMillis();
final long pool4Duration = pool4End - pool4Start;
final long createStart = System.currentTimeMillis();
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = new C();
}
final long createEnd = System.currentTimeMillis();
final long createDuration = createEnd - createStart;
//System.out.println("Create Duration: " + createDuration + "ms ");
System.out.println("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
final double pool1Efficiancy = (double)createDuration/(double)pool1Duration * 100.0;
final double pool2Efficiancy = (double)createDuration/(double)pool2Duration * 100.0;
final double pool3Efficiancy = (double)createDuration/(double)pool3Duration * 100.0;
final double pool4Efficiancy = (double)createDuration/(double)pool4Duration * 100.0;
//System.out.println("Pool Duration for 100% hits: " + pool1Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits: " + pool1Efficiancy + "ms ");
//System.out.println("Pool Duration for 100% hits and saturated: " + pool2Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits and saturated: " + pool2Efficiancy + "ms ");
//System.out.println("Pool Duration for 60% hits: " + pool3Duration + "ms ");
System.out.println("Pool Efficiancy for 60% hits: " + pool3Efficiancy + "ms ");
//System.out.println("Pool Duration for 50% hits: " + pool4Duration + "ms ");
System.out.println("Pool Efficiancy for 50% hits: " + pool4Efficiancy + "ms ");
}
public void testLargeObjects()
throws Exception
{
System.out.println("LARGE Sized Objects");
System.gc();
System.gc();
Thread.currentThread().sleep(2);
final DefaultPool pool1 = new DefaultPool( C.class, 5, 10 );
final long pool1Start = System.currentTimeMillis();
final int pool1Factor = 1;
final int pool1Loops = TEST_SIZE / pool1Factor;
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = pool1.get();
pool1.put(a1);
}
final long pool1End = System.currentTimeMillis();
final long pool1Duration = pool1End - pool1Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool2 = new DefaultPool( C.class, 5, 10 );
final long pool2Start = System.currentTimeMillis();
final int pool2Factor = 10;
final int pool2Loops = TEST_SIZE / pool2Factor;
for( int i = 0; i < pool2Loops; i++ )
{
final Poolable a1 = pool2.get();
final Poolable a2 = pool2.get();
final Poolable a3 = pool2.get();
final Poolable a4 = pool2.get();
final Poolable a5 = pool2.get();
final Poolable a6 = pool2.get();
final Poolable a7 = pool2.get();
final Poolable a8 = pool2.get();
final Poolable a9 = pool2.get();
final Poolable a10 = pool2.get();
pool2.put(a1);
pool2.put(a2);
pool2.put(a3);
pool2.put(a4);
pool2.put(a5);
pool2.put(a6);
pool2.put(a7);
pool2.put(a8);
pool2.put(a9);
pool2.put(a10);
}
final long pool2End = System.currentTimeMillis();
final long pool2Duration = pool2End - pool2Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool3 = new DefaultPool( C.class, 5, 10 );
final long pool3Start = System.currentTimeMillis();
final int pool3Factor = 15;
final int pool3Loops = TEST_SIZE / pool3Factor;
for( int i = 0; i < pool3Loops; i++ )
{
final Poolable a1 = pool3.get();
final Poolable a2 = pool3.get();
final Poolable a3 = pool3.get();
final Poolable a4 = pool3.get();
final Poolable a5 = pool3.get();
final Poolable a6 = pool3.get();
final Poolable a7 = pool3.get();
final Poolable a8 = pool3.get();
final Poolable a9 = pool3.get();
final Poolable a10 = pool3.get();
final Poolable a11 = pool3.get();
final Poolable a12 = pool3.get();
final Poolable a13 = pool3.get();
final Poolable a14 = pool3.get();
final Poolable a15 = pool3.get();
pool3.put(a1);
pool3.put(a2);
pool3.put(a3);
pool3.put(a4);
pool3.put(a5);
pool3.put(a6);
pool3.put(a7);
pool3.put(a8);
pool3.put(a9);
pool3.put(a10);
pool3.put(a11);
pool3.put(a12);
pool3.put(a13);
pool3.put(a14);
pool3.put(a15);
}
final long pool3End = System.currentTimeMillis();
final long pool3Duration = pool3End - pool3Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
final DefaultPool pool4 = new DefaultPool( C.class, 5, 10 );
final long pool4Start = System.currentTimeMillis();
final int pool4Factor = 20;
final int pool4Loops = TEST_SIZE / pool4Factor;
for( int i = 0; i < pool4Loops; i++ )
{
final Poolable a1 = pool4.get();
final Poolable a2 = pool4.get();
final Poolable a3 = pool4.get();
final Poolable a4 = pool4.get();
final Poolable a5 = pool4.get();
final Poolable a6 = pool4.get();
final Poolable a7 = pool4.get();
final Poolable a8 = pool4.get();
final Poolable a9 = pool4.get();
final Poolable a10 = pool4.get();
final Poolable a11 = pool4.get();
final Poolable a12 = pool4.get();
final Poolable a13 = pool4.get();
final Poolable a14 = pool4.get();
final Poolable a15 = pool4.get();
final Poolable a16 = pool4.get();
final Poolable a17 = pool4.get();
final Poolable a18 = pool4.get();
final Poolable a19 = pool4.get();
final Poolable a20 = pool4.get();
pool4.put(a1);
pool4.put(a2);
pool4.put(a3);
pool4.put(a4);
pool4.put(a5);
pool4.put(a6);
pool4.put(a7);
pool4.put(a8);
pool4.put(a9);
pool4.put(a10);
pool4.put(a11);
pool4.put(a12);
pool4.put(a13);
pool4.put(a14);
pool4.put(a15);
pool4.put(a16);
pool4.put(a17);
pool4.put(a18);
pool4.put(a19);
pool4.put(a20);
}
final long pool4End = System.currentTimeMillis();
final long pool4Duration = pool4End - pool4Start;
System.out.println("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
final long createStart = System.currentTimeMillis();
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = new C();
}
final long createEnd = System.currentTimeMillis();
final long createDuration = createEnd - createStart;
System.out.println("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
final double pool1Efficiancy = (double)createDuration/(double)pool1Duration * 100.0;
final double pool2Efficiancy = (double)createDuration/(double)pool2Duration * 100.0;
final double pool3Efficiancy = (double)createDuration/(double)pool3Duration * 100.0;
final double pool4Efficiancy = (double)createDuration/(double)pool4Duration * 100.0;
System.out.println("Pool Efficiancy for 100% hits: " + pool1Efficiancy + "ms ");
System.out.println("Pool Efficiancy for 100% hits and saturated: " + pool2Efficiancy + "ms ");
System.out.println("Pool Efficiancy for 60% hits: " + pool3Efficiancy + "ms ");
System.out.println("Pool Efficiancy for 50% hits: " + pool4Efficiancy + "ms ");
}
public void testThreadedSmallObjects()
throws Exception
{
System.out.println("SMALL Sized Objects with thread safe pools");
final HardResourceLimitingPool pool1 = new HardResourceLimitingPool( A.class, 5, 10 );
final long pool1Start = System.currentTimeMillis();
final int pool1Factor = 1;
final int pool1Loops = TEST_SIZE / pool1Factor;
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = pool1.get();
pool1.put(a1);
}
final long pool1End = System.currentTimeMillis();
final long pool1Duration = pool1End - pool1Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool2 = new HardResourceLimitingPool( A.class, 5, 10 );
final long pool2Start = System.currentTimeMillis();
final int pool2Factor = 10;
final int pool2Loops = TEST_SIZE / pool2Factor;
for( int i = 0; i < pool2Loops; i++ )
{
final Poolable a1 = pool2.get();
final Poolable a2 = pool2.get();
final Poolable a3 = pool2.get();
final Poolable a4 = pool2.get();
final Poolable a5 = pool2.get();
final Poolable a6 = pool2.get();
final Poolable a7 = pool2.get();
final Poolable a8 = pool2.get();
final Poolable a9 = pool2.get();
final Poolable a0 = pool2.get();
pool2.put(a1);
pool2.put(a2);
pool2.put(a3);
pool2.put(a4);
pool2.put(a5);
pool2.put(a6);
pool2.put(a7);
pool2.put(a8);
pool2.put(a9);
pool2.put(a0);
}
final long pool2End = System.currentTimeMillis();
final long pool2Duration = pool2End - pool2Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool3 = new HardResourceLimitingPool( A.class, 5, 10 );
final long pool3Start = System.currentTimeMillis();
final int pool3Factor = 15;
final int pool3Loops = TEST_SIZE / pool3Factor;
for( int i = 0; i < pool3Loops; i++ )
{
final Poolable a1 = pool3.get();
final Poolable a2 = pool3.get();
final Poolable a3 = pool3.get();
final Poolable a4 = pool3.get();
final Poolable a5 = pool3.get();
final Poolable a6 = pool3.get();
final Poolable a7 = pool3.get();
final Poolable a8 = pool3.get();
final Poolable a9 = pool3.get();
final Poolable a10 = pool3.get();
final Poolable a11 = pool3.get();
final Poolable a12 = pool3.get();
final Poolable a13 = pool3.get();
final Poolable a14 = pool3.get();
final Poolable a15 = pool3.get();
pool3.put(a1);
pool3.put(a2);
pool3.put(a3);
pool3.put(a4);
pool3.put(a5);
pool3.put(a6);
pool3.put(a7);
pool3.put(a8);
pool3.put(a9);
pool3.put(a10);
pool3.put(a11);
pool3.put(a12);
pool3.put(a13);
pool3.put(a14);
pool3.put(a15);
}
final long pool3End = System.currentTimeMillis();
final long pool3Duration = pool3End - pool3Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool4 = new HardResourceLimitingPool( A.class, 5, 10 );
final long pool4Start = System.currentTimeMillis();
final int pool4Factor = 20;
final int pool4Loops = TEST_SIZE / pool4Factor;
for( int i = 0; i < pool4Loops; i++ )
{
final Poolable a1 = pool4.get();
final Poolable a2 = pool4.get();
final Poolable a3 = pool4.get();
final Poolable a4 = pool4.get();
final Poolable a5 = pool4.get();
final Poolable a6 = pool4.get();
final Poolable a7 = pool4.get();
final Poolable a8 = pool4.get();
final Poolable a9 = pool4.get();
final Poolable a10 = pool4.get();
final Poolable a11 = pool4.get();
final Poolable a12 = pool4.get();
final Poolable a13 = pool4.get();
final Poolable a14 = pool4.get();
final Poolable a15 = pool4.get();
final Poolable a16 = pool4.get();
final Poolable a17 = pool4.get();
final Poolable a18 = pool4.get();
final Poolable a19 = pool4.get();
final Poolable a20 = pool4.get();
pool4.put(a1);
pool4.put(a2);
pool4.put(a3);
pool4.put(a4);
pool4.put(a5);
pool4.put(a6);
pool4.put(a7);
pool4.put(a8);
pool4.put(a9);
pool4.put(a10);
pool4.put(a11);
pool4.put(a12);
pool4.put(a13);
pool4.put(a14);
pool4.put(a15);
pool4.put(a16);
pool4.put(a17);
pool4.put(a18);
pool4.put(a19);
pool4.put(a20);
}
final long pool4End = System.currentTimeMillis();
final long pool4Duration = pool4End - pool4Start;
System.out.println("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
final long createStart = System.currentTimeMillis();
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = new C();
}
final long createEnd = System.currentTimeMillis();
final long createDuration = createEnd - createStart;
//System.out.println("Create Duration: " + createDuration + "ms ");
System.out.println("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
final double pool1Efficiancy = (double)createDuration/(double)pool1Duration * 100.0;
final double pool2Efficiancy = (double)createDuration/(double)pool2Duration * 100.0;
final double pool3Efficiancy = (double)createDuration/(double)pool3Duration * 100.0;
final double pool4Efficiancy = (double)createDuration/(double)pool4Duration * 100.0;
//System.out.println("Pool Duration for 100% hits: " + pool1Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits: " + pool1Efficiancy + "ms ");
//System.out.println("Pool Duration for 100% hits and saturated: " + pool2Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits and saturated: " + pool2Efficiancy + "ms ");
//System.out.println("Pool Duration for 60% hits: " + pool3Duration + "ms ");
System.out.println("Pool Efficiancy for 60% hits: " + pool3Efficiancy + "ms ");
//System.out.println("Pool Duration for 50% hits: " + pool4Duration + "ms ");
System.out.println("Pool Efficiancy for 50% hits: " + pool4Efficiancy + "ms ");
}
public void testThreadedMediumObjects()
throws Exception
{
System.out.println("MEDIUM Sized Objects with thread safe pools");
System.gc();
System.gc();
Thread.currentThread().sleep(2);
final HardResourceLimitingPool pool1 = new HardResourceLimitingPool( B.class, 5, 10 );
final long pool1Start = System.currentTimeMillis();
final int pool1Factor = 1;
final int pool1Loops = TEST_SIZE / pool1Factor;
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = pool1.get();
pool1.put(a1);
}
final long pool1End = System.currentTimeMillis();
final long pool1Duration = pool1End - pool1Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool2 = new HardResourceLimitingPool( B.class, 5, 10 );
final long pool2Start = System.currentTimeMillis();
final int pool2Factor = 10;
final int pool2Loops = TEST_SIZE / pool2Factor;
for( int i = 0; i < pool2Loops; i++ )
{
final Poolable a1 = pool2.get();
final Poolable a2 = pool2.get();
final Poolable a3 = pool2.get();
final Poolable a4 = pool2.get();
final Poolable a5 = pool2.get();
final Poolable a6 = pool2.get();
final Poolable a7 = pool2.get();
final Poolable a8 = pool2.get();
final Poolable a9 = pool2.get();
final Poolable a10 = pool2.get();
/*
a1.build();
a2.build();
a3.build();
a4.build();
a5.build();
a6.build();
a7.build();
a8.build();
a9.build();
a10.build();
*/
pool2.put(a1);
pool2.put(a2);
pool2.put(a3);
pool2.put(a4);
pool2.put(a5);
pool2.put(a6);
pool2.put(a7);
pool2.put(a8);
pool2.put(a9);
pool2.put(a10);
}
final long pool2End = System.currentTimeMillis();
final long pool2Duration = pool2End - pool2Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool3 = new HardResourceLimitingPool( B.class, 5, 10 );
final long pool3Start = System.currentTimeMillis();
final int pool3Factor = 15;
final int pool3Loops = TEST_SIZE / pool3Factor;
for( int i = 0; i < pool3Loops; i++ )
{
final Poolable a1 = pool3.get();
final Poolable a2 = pool3.get();
final Poolable a3 = pool3.get();
final Poolable a4 = pool3.get();
final Poolable a5 = pool3.get();
final Poolable a6 = pool3.get();
final Poolable a7 = pool3.get();
final Poolable a8 = pool3.get();
final Poolable a9 = pool3.get();
final Poolable a10 = pool3.get();
final Poolable a11 = pool3.get();
final Poolable a12 = pool3.get();
final Poolable a13 = pool3.get();
final Poolable a14 = pool3.get();
final Poolable a15 = pool3.get();
/*
a1.build();
a2.build();
a3.build();
a4.build();
a5.build();
a6.build();
a7.build();
a8.build();
a9.build();
a10.build();
a11.build();
a12.build();
a13.build();
a14.build();
a15.build();
*/
pool3.put(a1);
pool3.put(a2);
pool3.put(a3);
pool3.put(a4);
pool3.put(a5);
pool3.put(a6);
pool3.put(a7);
pool3.put(a8);
pool3.put(a9);
pool3.put(a10);
pool3.put(a11);
pool3.put(a12);
pool3.put(a13);
pool3.put(a14);
pool3.put(a15);
}
final long pool3End = System.currentTimeMillis();
final long pool3Duration = pool3End - pool3Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool4 = new HardResourceLimitingPool( B.class, 5, 10 );
final long pool4Start = System.currentTimeMillis();
final int pool4Factor = 20;
final int pool4Loops = TEST_SIZE / pool4Factor;
for( int i = 0; i < pool4Loops; i++ )
{
final Poolable a1 = pool4.get();
final Poolable a2 = pool4.get();
final Poolable a3 = pool4.get();
final Poolable a4 = pool4.get();
final Poolable a5 = pool4.get();
final Poolable a6 = pool4.get();
final Poolable a7 = pool4.get();
final Poolable a8 = pool4.get();
final Poolable a9 = pool4.get();
final Poolable a10 = pool4.get();
final Poolable a11 = pool4.get();
final Poolable a12 = pool4.get();
final Poolable a13 = pool4.get();
final Poolable a14 = pool4.get();
final Poolable a15 = pool4.get();
final Poolable a16 = pool4.get();
final Poolable a17 = pool4.get();
final Poolable a18 = pool4.get();
final Poolable a19 = pool4.get();
final Poolable a20 = pool4.get();
/*
a1.build();
a2.build();
a3.build();
a4.build();
a5.build();
a6.build();
a7.build();
a8.build();
a9.build();
a10.build();
a11.build();
a12.build();
a13.build();
a14.build();
a15.build();
a16.build();
a17.build();
a18.build();
a19.build();
a20.build();
*/
pool4.put(a1);
pool4.put(a2);
pool4.put(a3);
pool4.put(a4);
pool4.put(a5);
pool4.put(a6);
pool4.put(a7);
pool4.put(a8);
pool4.put(a9);
pool4.put(a10);
pool4.put(a11);
pool4.put(a12);
pool4.put(a13);
pool4.put(a14);
pool4.put(a15);
pool4.put(a16);
pool4.put(a17);
pool4.put(a18);
pool4.put(a19);
pool4.put(a20);
}
final long pool4End = System.currentTimeMillis();
final long pool4Duration = pool4End - pool4Start;
final long createStart = System.currentTimeMillis();
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = new C();
}
final long createEnd = System.currentTimeMillis();
final long createDuration = createEnd - createStart;
//System.out.println("Create Duration: " + createDuration + "ms ");
System.out.println("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
final double pool1Efficiancy = (double)createDuration/(double)pool1Duration * 100.0;
final double pool2Efficiancy = (double)createDuration/(double)pool2Duration * 100.0;
final double pool3Efficiancy = (double)createDuration/(double)pool3Duration * 100.0;
final double pool4Efficiancy = (double)createDuration/(double)pool4Duration * 100.0;
//System.out.println("Pool Duration for 100% hits: " + pool1Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits: " + pool1Efficiancy + "ms ");
//System.out.println("Pool Duration for 100% hits and saturated: " + pool2Duration + "ms ");
System.out.println("Pool Efficiancy for 100% hits and saturated: " + pool2Efficiancy + "ms ");
//System.out.println("Pool Duration for 60% hits: " + pool3Duration + "ms ");
System.out.println("Pool Efficiancy for 60% hits: " + pool3Efficiancy + "ms ");
//System.out.println("Pool Duration for 50% hits: " + pool4Duration + "ms ");
System.out.println("Pool Efficiancy for 50% hits: " + pool4Efficiancy + "ms ");
}
public void testThreadedLargeObjects()
throws Exception
{
System.out.println("LARGE Sized Objects with thread safe pools");
System.gc();
System.gc();
Thread.currentThread().sleep(2);
final HardResourceLimitingPool pool1 = new HardResourceLimitingPool( C.class, 5, 10 );
final long pool1Start = System.currentTimeMillis();
final int pool1Factor = 1;
final int pool1Loops = TEST_SIZE / pool1Factor;
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = pool1.get();
//a1.build();
pool1.put(a1);
}
final long pool1End = System.currentTimeMillis();
final long pool1Duration = pool1End - pool1Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool2 = new HardResourceLimitingPool( C.class, 5, 10 );
final long pool2Start = System.currentTimeMillis();
final int pool2Factor = 10;
final int pool2Loops = TEST_SIZE / pool2Factor;
for( int i = 0; i < pool2Loops; i++ )
{
final Poolable a1 = pool2.get();
final Poolable a2 = pool2.get();
final Poolable a3 = pool2.get();
final Poolable a4 = pool2.get();
final Poolable a5 = pool2.get();
final Poolable a6 = pool2.get();
final Poolable a7 = pool2.get();
final Poolable a8 = pool2.get();
final Poolable a9 = pool2.get();
final Poolable a10 = pool2.get();
/*
a1.build();
a2.build();
a3.build();
a4.build();
a5.build();
a6.build();
a7.build();
a8.build();
a9.build();
a10.build();
*/
pool2.put(a1);
pool2.put(a2);
pool2.put(a3);
pool2.put(a4);
pool2.put(a5);
pool2.put(a6);
pool2.put(a7);
pool2.put(a8);
pool2.put(a9);
pool2.put(a10);
}
final long pool2End = System.currentTimeMillis();
final long pool2Duration = pool2End - pool2Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool3 = new HardResourceLimitingPool( C.class, 5, 10 );
final long pool3Start = System.currentTimeMillis();
final int pool3Factor = 15;
final int pool3Loops = TEST_SIZE / pool3Factor;
for( int i = 0; i < pool3Loops; i++ )
{
final Poolable a1 = pool3.get();
final Poolable a2 = pool3.get();
final Poolable a3 = pool3.get();
final Poolable a4 = pool3.get();
final Poolable a5 = pool3.get();
final Poolable a6 = pool3.get();
final Poolable a7 = pool3.get();
final Poolable a8 = pool3.get();
final Poolable a9 = pool3.get();
final Poolable a10 = pool3.get();
final Poolable a11 = pool3.get();
final Poolable a12 = pool3.get();
final Poolable a13 = pool3.get();
final Poolable a14 = pool3.get();
final Poolable a15 = pool3.get();
/*
a1.build();
a2.build();
a3.build();
a4.build();
a5.build();
a6.build();
a7.build();
a8.build();
a9.build();
a10.build();
a11.build();
a12.build();
a13.build();
a14.build();
a15.build();
*/
pool3.put(a1);
pool3.put(a2);
pool3.put(a3);
pool3.put(a4);
pool3.put(a5);
pool3.put(a6);
pool3.put(a7);
pool3.put(a8);
pool3.put(a9);
pool3.put(a10);
pool3.put(a11);
pool3.put(a12);
pool3.put(a13);
pool3.put(a14);
pool3.put(a15);
}
final long pool3End = System.currentTimeMillis();
final long pool3Duration = pool3End - pool3Start;
System.gc();
System.gc();
Thread.currentThread().sleep(2);
System.out.println("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
final HardResourceLimitingPool pool4 = new HardResourceLimitingPool( C.class, 5, 10 );
final long pool4Start = System.currentTimeMillis();
final int pool4Factor = 20;
final int pool4Loops = TEST_SIZE / pool4Factor;
for( int i = 0; i < pool4Loops; i++ )
{
final Poolable a1 = pool4.get();
final Poolable a2 = pool4.get();
final Poolable a3 = pool4.get();
final Poolable a4 = pool4.get();
final Poolable a5 = pool4.get();
final Poolable a6 = pool4.get();
final Poolable a7 = pool4.get();
final Poolable a8 = pool4.get();
final Poolable a9 = pool4.get();
final Poolable a10 = pool4.get();
final Poolable a11 = pool4.get();
final Poolable a12 = pool4.get();
final Poolable a13 = pool4.get();
final Poolable a14 = pool4.get();
final Poolable a15 = pool4.get();
final Poolable a16 = pool4.get();
final Poolable a17 = pool4.get();
final Poolable a18 = pool4.get();
final Poolable a19 = pool4.get();
final Poolable a20 = pool4.get();
pool4.put(a1);
pool4.put(a2);
pool4.put(a3);
pool4.put(a4);
pool4.put(a5);
pool4.put(a6);
pool4.put(a7);
pool4.put(a8);
pool4.put(a9);
pool4.put(a10);
pool4.put(a11);
pool4.put(a12);
pool4.put(a13);
pool4.put(a14);
pool4.put(a15);
pool4.put(a16);
pool4.put(a17);
pool4.put(a18);
pool4.put(a19);
pool4.put(a20);
}
final long pool4End = System.currentTimeMillis();
final long pool4Duration = pool4End - pool4Start;
System.out.println("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
final long createStart = System.currentTimeMillis();
for( int i = 0; i < TEST_SIZE; i++ )
{
final Poolable a1 = new C();
}
final long createEnd = System.currentTimeMillis();
final long createDuration = createEnd - createStart;
System.out.println("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
final double pool1Efficiancy = (double)createDuration/(double)pool1Duration * 100.0;
final double pool2Efficiancy = (double)createDuration/(double)pool2Duration * 100.0;
final double pool3Efficiancy = (double)createDuration/(double)pool3Duration * 100.0;
final double pool4Efficiancy = (double)createDuration/(double)pool4Duration * 100.0;
System.out.println("Pool Efficiancy for 100% hits: " + pool1Efficiancy + "ms ");
System.out.println("Pool Efficiancy for 100% hits and saturated: " + pool2Efficiancy + "ms ");
System.out.println("Pool Efficiancy for 60% hits: " + pool3Efficiancy + "ms ");
System.out.println("Pool Efficiancy for 50% hits: " + pool4Efficiancy + "ms ");
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/test/BinaryHeapTestlet.java
Index: BinaryHeapTestlet.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 file.
*/
package org.apache.avalon.util.test;
import org.apache.avalon.util.BinaryHeap;
import org.apache.testlet.AbstractTestlet;
/**
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class BinaryHeapTestlet
extends AbstractTestlet
{
protected final static Integer VAL1 = new Integer( 1 );
protected final static Integer VAL2 = new Integer( 2 );
protected final static Integer VAL3 = new Integer( 3 );
protected final static Integer VAL4 = new Integer( 4 );
protected final static Integer VAL5 = new Integer( 5 );
protected final static Integer VAL6 = new Integer( 6 );
protected final static Integer VAL7 = new Integer( 7 );
public void testSimpleOrder()
{
final BinaryHeap heap = new BinaryHeap();
heap.clear();
heap.insert( VAL1 );
heap.insert( VAL2 );
heap.insert( VAL3 );
heap.insert( VAL4 );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL4 == heap.pop() );
}
public void testReverseOrder()
{
final BinaryHeap heap = new BinaryHeap();
heap.clear();
heap.insert( VAL4 );
heap.insert( VAL3 );
heap.insert( VAL2 );
heap.insert( VAL1 );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL4 == heap.pop() );
}
public void testMixedOrder()
{
final BinaryHeap heap = new BinaryHeap();
heap.clear();
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL4 == heap.pop() );
}
public void testDuplicates()
{
final BinaryHeap heap = new BinaryHeap();
heap.clear();
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL4 == heap.pop() );
}
public void testMixedInsertPopOrder()
{
final BinaryHeap heap = new BinaryHeap();
heap.clear();
heap.insert( VAL1 );
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL4 == heap.pop() );
assert( VAL4 == heap.pop() );
}
public void testReverseSimpleOrder()
{
final BinaryHeap heap = new BinaryHeap( false );
heap.clear();
heap.insert( VAL1 );
heap.insert( VAL2 );
heap.insert( VAL3 );
heap.insert( VAL4 );
assert( VAL4 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
}
public void testReverseReverseOrder()
{
final BinaryHeap heap = new BinaryHeap( false );
heap.clear();
heap.insert( VAL4 );
heap.insert( VAL3 );
heap.insert( VAL2 );
heap.insert( VAL1 );
assert( VAL4 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
}
public void testReverseMixedOrder()
{
final BinaryHeap heap = new BinaryHeap( false );
heap.clear();
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL4 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
}
public void testReverseDuplicates()
{
final BinaryHeap heap = new BinaryHeap( false );
heap.clear();
heap.insert( VAL4 );
heap.insert( VAL3 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
assert( VAL4 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
}
public void testReverseMixedInsertPopOrder()
{
final BinaryHeap heap = new BinaryHeap( false );
heap.clear();
heap.insert( VAL1 );
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL4 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL2 == heap.pop() );
heap.insert( VAL4 );
heap.insert( VAL2 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL1 );
heap.insert( VAL3 );
assert( VAL4 == heap.pop() );
assert( VAL3 == heap.pop() );
assert( VAL2 == heap.pop() );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.peek() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
assert( VAL1 == heap.pop() );
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/test/DependencyGraphTestlet.java
Index: DependencyGraphTestlet.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 file.
*/
package org.apache.avalon.util.test;
import java.util.List;
import org.apache.avalon.util.CircularDependencyException;
import org.apache.avalon.util.DependencyGraph;
import org.apache.testlet.AbstractTestlet;
/**
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class DependencyGraphTestlet
extends AbstractTestlet
{
protected final String[][] DEPENDENCY_TREE =
{
{ "A" }, { "B", "C", "D" },
{ "B" }, { "E" },
{ "C" }, {},
{ "D" }, { "F" },
{ "E" }, { "F" },
{ "F" }, { },
{ "G" }, { "H" },
{ "H" }, { "G" },
{ "I" }, { "I" }
};
protected DependencyGraph m_graph;
public void initialize()
{
m_graph = new DependencyGraph();
for( int i = 0; i < DEPENDENCY_TREE.length; i += 2 )
{
m_graph.add( DEPENDENCY_TREE[ i ][0], DEPENDENCY_TREE[ i + 1 ] );
}
}
protected boolean contains( final DependencyGraph.Dependency[] list, final String name )
{
for( int i = 0; i < list.length; i++ )
{
if( list[ i ].getName().equals( name ) )
{
return true;
}
}
return false;
}
public void testNoDependency()
throws Exception
{
final DependencyGraph.Dependency[] list = m_graph.getDependencyList( "F" );
assertEquality( "Graph for F", list.length, 1 );
assertEquality( "Graph for F[1]", list[ 0 ].getName(), "F" );
assertEquality( "Graph for F[1]", list[ 0 ].getRequiredBy(), null );
}
public void test1LevelDependency()
throws Exception
{
final DependencyGraph.Dependency[] list = m_graph.getDependencyList( "E" );
assertEquality( "Graph for E", list.length, 2 );
assert( "Graph for E[1]", contains( list, "E" ) );
assert( "Graph for E[2]", contains( list, "F" ) );
}
public void test2LevelDependency()
throws Exception
{
final DependencyGraph.Dependency[] list = m_graph.getDependencyList( "B" );
assertEquality( "Graph for E", list.length, 3 );
assert( "Graph for E[1]", contains( list, "E" ) );
assert( "Graph for E[2]", contains( list, "F" ) );
assert( "Graph for E[3]", contains( list, "B" ) );
}
public void testNLevelDependency()
throws Exception
{
final DependencyGraph.Dependency[] list = m_graph.getDependencyList( "A" );
assertEquality( "Graph for A", list.length, 6 );
assert( "Graph for A[1]", contains( list, "A" ) );
assert( "Graph for A[2]", contains( list, "B" ) );
assert( "Graph for A[3]", contains( list, "C" ) );
assert( "Graph for A[4]", contains( list, "D" ) );
assert( "Graph for A[5]", contains( list, "E" ) );
assert( "Graph for A[6]", contains( list, "F" ) );
}
public void testAllowableCircularDependency()
throws Exception
{
m_graph.setAllowCircularity( true );
final DependencyGraph.Dependency[] list = m_graph.getDependencyList( "G" );
assertEquality( "Graph for G", list.length, 2 );
assert( "Graph for G[1]", contains( list, "G" ) );
assert( "Graph for H[2]", contains( list, "H" ) );
}
public void testUnallowableCircularDependency()
throws Exception
{
try
{
m_graph.setAllowCircularity( false );
m_graph.getDependencyList( "G" );
}
catch( final CircularDependencyException cde )
{
return;
}
fail( "Expected CircularDependencyException" );
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/test/PropertyUtilTestlet.java
Index: PropertyUtilTestlet.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 file.
*/
package org.apache.avalon.util.test;
import org.apache.avalon.Context;
import org.apache.avalon.DefaultContext;
import org.apache.avalon.Resolvable;
import org.apache.avalon.util.PropertyException;
import org.apache.avalon.util.PropertyUtil;
import org.apache.testlet.AbstractTestlet;
/**
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class PropertyUtilTestlet
extends AbstractTestlet
{
protected static final class ResolveTest
implements Resolvable
{
protected int m_count;
protected int m_current;
public ResolveTest( final int count )
{
m_count = count;
}
public Object resolve( final Context context )
{
m_current++;
if( m_current >= m_count ) return new Integer( m_count );
else return this;
}
}
protected final static Object OBJ1 = new Object();
protected final static Object OBJ2 = new Object();
protected DefaultContext m_context;
public void initialize()
{
m_context = new DefaultContext();
m_context.put( "obj1", OBJ1 );
m_context.put( "obj2", OBJ2 );
m_context.put( "res1", new ResolveTest( 1 ) );
m_context.put( "res2", new ResolveTest( 2 ) );
m_context.put( "res3", new ResolveTest( 3 ) );
m_context.put( "res4", new ResolveTest( 4 ) );
}
public void testNoResolve()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( "blah", m_context, false );
assertEquality( result, "blah" );
}
public void testObjResolve()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( "${obj1}", m_context, false );
assertEquality( result, OBJ1 );
}
public void testObjResolveToText()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( "${obj1} ", m_context, false );
assertEquality( result, OBJ1 + " " );
}
public void testDualObjResolve()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( " ${obj1} ${obj2} ", m_context, false );
assertEquality( result, " " + OBJ1 + " " + OBJ2 + " " );
}
public void testRecurseObjResolve()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( "${res1}", m_context, false );
assertEquality( result, new Integer( 1 ) );
}
public void testRecurseObjResolve2()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( "${res2}", m_context, false );
assertEquality( result, new Integer( 2 ) );
}
public void testNullObjResolve()
throws PropertyException
{
final Object result =
PropertyUtil.resolveProperty( "${blahaaa}", m_context, true );
assertEquality( result, "" );
}
public void testNullObjResolveForException()
throws PropertyException
{
try
{
final Object result =
PropertyUtil.resolveProperty( "${blahaaa}", m_context, false );
}
catch( final PropertyException pe )
{
return;
}
fail( "NUll resolve occured without exception" );
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/test/ProxyGeneratorTestlet.java
Index: ProxyGeneratorTestlet.java
===================================================================
/*
* Copyright 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 file.
*/
package org.apache.avalon.util.test;
import org.apache.avalon.util.ProxyGenerator;
import org.apache.testlet.AbstractTestlet;
import org.apache.testlet.TestFailedException;
/**
* This is used to test Proxy generation for correctness.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class ProxyGeneratorTestlet
extends AbstractTestlet
{
public interface Interface1
{
void method1();
}
public interface Interface2 extends Interface1
{
void method2();
}
public interface Interface3
{
void method3( int x );
}
public interface Interface4
{
void method4( String x );
}
public interface Interface5
{
void method3( String x );
}
public interface Interface6
{
void method2();
}
public interface Interface7
{
void method3( double x );
}
public interface Interface8
{
void method3( double x, double y );
}
public interface Interface9
{
int method4( double x, double y );
}
public interface Interface10
{
double method10( double x, double y );
}
public static class ClassA
implements Interface1, Interface3, Interface4, Interface5, Interface9, Interface10
{
public void method1() {}
public void method3( int x ) {}
public void method3( String x ) {}
public void method4( String x ) {}
public int method4( double x, double y ) { return 0; }
public double method10( double x, double y ) { return 0.0; }
}
public static class ClassB implements Interface2, Interface6, Interface7, Interface8
{
public void method1() {}
public void method2() {}
public void method3( double x ) {}
public void method3( double x, double y ) {}
}
public void testNoParamMethod()
throws Exception
{
final Class[] interfaces = new Class[] { Interface1.class };
final Object object = new ClassA();
final Object result = doTest( object, interfaces );
((Interface1)result).method1();
}
public void testExtendedInterfaceHidden()
throws Exception
{
final Class[] interfaces = new Class[] { Interface1.class };
final Object object = new ClassB();
final Object result = doTest( object, interfaces );
((Interface1)result).method1();
assert( !(result instanceof Interface2) );
}
public void testExtendedInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface1.class, Interface2.class };
final Object object = new ClassB();
final Object result = doTest( object, interfaces );
((Interface1)result).method1();
((Interface2)result).method1();
((Interface2)result).method2();
}
public void testIntParamInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface3.class };
final Object object = new ClassA();
final Object result = doTest( object, interfaces );
((Interface3)result).method3(2);
}
public void testStringParamInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface4.class };
final Object object = new ClassA();
final Object result = doTest( object, interfaces );
((Interface4)result).method4("Hello");
}
public void testOverloadedStringParamInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface5.class };
final Object object = new ClassA();
final Object result = doTest( object, interfaces );
((Interface5)result).method3("Hello");
}
public void testDuplicateMethodInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface2.class, Interface6.class };
final Object object = new ClassB();
final Object result = doTest( object, interfaces );
((Interface6)result).method2();
((Interface2)result).method2();
}
public void testDoubleParamInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface7.class };
final Object object = new ClassB();
final Object result = doTest( object, interfaces );
((Interface7)result).method3(2.0);
}
public void test2DoubleParamInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface8.class };
final Object object = new ClassB();
final Object result = doTest( object, interfaces );
((Interface8)result).method3(2.0,2.0);
}
public void testIntReturnInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface9.class };
final Object object = new ClassA();
final Object result = doTest( object, interfaces );
final int x = ((Interface9)result).method4(2.0,2.0);
}
public void testDoubleReturnInterface()
throws Exception
{
final Class[] interfaces = new Class[] { Interface10.class };
final Object object = new ClassA();
final Object result = doTest( object, interfaces );
final double x = ((Interface10)result).method10(2.0,2.0);
}
protected Object doTest( final Object object, final Class[] interfaces )
throws Exception
{
final Object result =
ProxyGenerator.generateProxy( object, interfaces );
if( null == result )
{
throw new TestFailedException( "Proxy object failed to be created." );
}
for( int i = 0; i < interfaces.length; i++ )
{
if( !interfaces[ i ].isInstance( result ) )
{
throw new TestFailedException( "Interface " + interfaces[ i ] +
" not implemented by proxy." );
}
}
return result;
}
}
1.1 jakarta-avalon/src/test/org/apache/avalon/util/test/StringUtilTestlet.java
Index: StringUtilTestlet.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 file.
*/
package org.apache.avalon.util.test;
import org.apache.avalon.util.StringUtil;
import org.apache.testlet.AbstractTestlet;
/**
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class StringUtilTestlet
extends AbstractTestlet
{
public void testNoReplace()
{
final String result =
StringUtil.replaceSubString("blah", "not-there", "ignored" );
assertEquality( result, "blah" );
}
public void testMidReplace()
{
final String result =
StringUtil.replaceSubString("blah", "la", "le" );
assertEquality( result, "bleh" );
}
public void testStartReplace()
{
final String result =
StringUtil.replaceSubString("blah", "bla", "ble" );
assertEquality( result, "bleh" );
}
public void testEndReplace()
{
final String result =
StringUtil.replaceSubString("blah", "lah", "leh" );
assertEquality( result, "bleh" );
}
public void testDoubleReplace()
{
final String result =
StringUtil.replaceSubString("blahblah", "la", "le" );
assertEquality( result, "blehbleh" );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org