Methods Summary |
---|
private java.io.File | createTempFile(long totalSize)
final long start = now();
final File temp = File.createTempFile( "UploadDownloadMgrTest", "junk" );
temp.deleteOnExit();
final FileOutputStream os = new FileOutputStream( temp );
try
{
long remaining = totalSize;
final byte[] junk = new byte[ 1024 * 1024 ];
while ( remaining != 0 )
{
final long actual = remaining < junk.length ? remaining : junk.length;
os.write( junk, 0, (int)actual );
remaining -= actual;
}
os.close();
}
catch( IOException e )
{
os.close();
temp.delete();
throw e;
}
assert( temp.length() == totalSize );
printElapsed( "UploadDownloadMgr.createTempFile: " +
totalSize + " bytes", start );
return( temp );
|
public static com.sun.enterprise.management.Capabilities | getCapabilities()
return getOfflineCapableCapabilities( true );
|
public com.sun.appserv.management.base.UploadDownloadMgr | getUploadDownloadMgr()
return( getDomainRoot().getUploadDownloadMgr() );
|
public void | testDownloadBigFile()
final long start = now();
Integer def = new Integer(PropertyKeys.DEFAULT_UPLOAD_DOWNLOAD_MGR_TEST_BIG_FILE_KB);
final int kb =
getEnvInteger( PropertyKeys.UPLOAD_DOWNLOAD_MGR_TEST_BIG_FILE_KB, def).intValue();
assert( kb >= 1 ) :
"Test size must be positive, value for " +
PropertyKeys.UPLOAD_DOWNLOAD_MGR_TEST_BIG_FILE_KB +
": " + kb;
testDownloadFile( kb * K, MEGABYTE );
printElapsed( "UploadDownloadMgrTest.testDownloadBigFile: " + kb + "kb", start);
|
public java.io.File | testDownloadFile(int testSize, int chunkSize)
final UploadDownloadMgr mgr =
getDomainRoot().getUploadDownloadMgr();
final File testFile = createTempFile( testSize );
final long start = now();
final Object id = mgr.initiateDownload( testFile, true );
//trace( "initated download for: " + id + " file = " + testFile.toString() );
final int maxChunkSize = mgr.getMaxDownloadChunkSize();
final int actualChunkSize = chunkSize < maxChunkSize ?
chunkSize : maxChunkSize;
final long length = mgr.getDownloadLength( id );
long doneSoFar = 0;
while ( doneSoFar < length )
{
final byte[] bytes = mgr.downloadBytes( id, actualChunkSize );
doneSoFar += bytes.length;
}
printElapsed( "UploadDownloadMgr.testDownloadFile: " +
testSize + " bytes" + " chunksize = " + actualChunkSize, start );
return( testFile );
|
public void | testDownloadFileBufferLargerThanDownload()
final int size = 256 * K;
testDownloadFile( size, size + 1 );
|
public void | testDownloadFileBufferSameSizeAsDownload()
final int size = 256 * K;
testDownloadFile( size, size );
|
public void | testDownloadFileBufferSameSizeSmallerThanDownload()
final int size = 256 * K;
testDownloadFile( size, size -1 );
|
public void | testDownloadSmallFile()
final int size = 50 * K;
testDownloadFile( size, size + 1 );
testDownloadFile( size, size );
|
public void | testDownloadTinyFile()
final int size = 1;
testDownloadFile( size, size + 1 );
testDownloadFile( size, size );
|
public void | testHeavilyThreaded()This test is an attempt to find any synchronization bugs.
Integer def = new Integer(PropertyKeys.DEFAULT_UPLOAD_DOWNLOAD_MGR_TEST_THREADS);
int numThreads = getEnvInteger( PropertyKeys.UPLOAD_DOWNLOAD_MGR_TEST_THREADS, def).intValue();
if ( numThreads <= 0 )
{
numThreads = 1;
}
printVerbose( "UploadDownloadMgrTest.testHeavilyThreaded: using " + numThreads + " threads." );
final UploadDownloadTestThread[] threads =
new UploadDownloadTestThread[ numThreads ];
// create and start all the threads
for( int i = 0; i < numThreads; ++i )
{
threads[ i ] = new UploadDownloadTestThread( i * K + 1 );
threads[ i ].start();
}
// wait till done
boolean done = false;
while ( true )
{
int numDone = 0;
for( int i = 0; i < numThreads; ++i )
{
if ( threads[ i ].done() )
{
++numDone;
}
}
if ( numDone == numThreads )
break;
printVerbose( "UploadDownloadMgrTest.testHeavilyThreaded: waiting for " +
(numThreads - numDone) + " of " + numThreads + " threads ");
mySleep( 1000 );
}
// verify success
for( int i = 0; i < numThreads; ++i )
{
assert( threads[ i ].done() );
assert( threads[ i ].getThrowable() == null ) :
ExceptionUtil.getStackTrace( threads[ i ].getThrowable() );
}
|
public void | testUploadFile1()
final Object id = upload( "./deploy.temp1." + now(), 1024 * K );
|
public void | testUploadFile2()
final Object id = upload( "./deploy.temp2." + now(), 1 + 100 * K );
|
public void | testUploadFile3()
final Object id = upload( "./deploy.temp3." + now(), 1 );
|
public void | testUploadFile4()
final Object id = upload( "./deploy.temp4." + now(), K + 1 );
|
public void | testUploadFile5()
final Object id = upload( null, 1 + 2048 * K );
|
public java.lang.Object | upload(java.lang.String name, int totalSize)
final UploadDownloadMgr mgr = getUploadDownloadMgr();
//mgr.setTrace( true );
final int chunkSize = 32 * 1024;
final long start = now();
final Object uploadID = mgr.initiateUpload( name, totalSize );
int remaining = totalSize;
boolean done = false;
while ( remaining != 0 )
{
final int actual = remaining < chunkSize ? remaining : chunkSize;
final byte[] bytes = new byte[ actual ];
done = mgr.uploadBytes( uploadID, bytes );
remaining -= actual;
//trace( "uploaded: " + (totalSize - remaining) );
}
assert( done );
printElapsed( "UploadDownloadMgr.upload: " + totalSize + " bytes", start );
return( uploadID );
|