fileName += ".";
fileName += loops;
fileName += ".csv";
List results = new ArrayList();
EJServer server = new EJServer( new TestHandler(), port );
server.setMaxReadProcessors( 1 );
server.setMaxWriteProcessors( 1 );
server.enablePersistentConnections( true );
server.enableNonBlockingIO( runs < 2 );
server.enableCompression( runs == 1 || runs == 3 );
server.enablePersistentConnections( true );
try
{
System.out.println( "Starting EJServer..." );
server.start();
System.out.println( "Waiting 3 seconds..." );
Thread.sleep( 3000 );
System.out.println( "Running warmup for each adapter..." );
for ( int i = 0; i < adapters.length; i++ )
{
System.out.println( "Running warmup for " + adapters[i] );
EJClient client = new EJClient( "localhost", port, adapters[i] );
client.enablePersistentConnection( true );
client.enableCompression( runs == 1 || runs == 3 );
client.setInJVM( true );
try
{
for ( int t = 0; t < 5; t++ )
client.execute( new ObjectBean() );
}
finally
{
client.close();
}
}
}
catch ( Exception e1 )
{
e1.printStackTrace();
System.exit( -1 );
}
System.out.println( "Waiting 3 seconds..." );
try
{
Thread.sleep( 3000 );
}
catch ( InterruptedException e1 )
{
e1.printStackTrace();
System.exit( -1 );
}
Object result = null;
String[] msgs = new String[3];
for ( int i = 0; i < adapters.length; i++ )
{
EJClient client = new EJClient( "localhost", port, adapters[i] );
client.enablePersistentConnection( true );
client.enableCompression( runs == 1 || runs == 3 );
client.setInJVM( true );
System.out.println( "Running test on " + adapters[i] + " with target " + fileName );
Date start = new Date();
try
{
for ( int go = 0; go < loops; go++ )
{
try
{
result = client.execute( new ObjectBean() );
}
catch ( Throwable e )
{
msgs[2] = "Exception occured while processing the request!" + e + ':' + e.getMessage();
go = runs;
break;
}
}
}
finally
{
client.close();
}
Date end = new Date();
long duration = end.getTime() - start.getTime();
DateFormat df = new SimpleDateFormat( dFormat );
BigDecimal resultF = BigDecimal.valueOf( (duration * 1.00) / (loops * 1.00) )
.setScale( 2, BigDecimal.ROUND_HALF_UP );
DecimalFormat dcf = new DecimalFormat( "###.##" );
msgs[0] = adapters[i].getClass().getName() + ';' + df.format( start ) + ';' + df.format( end ) + ';'
+ duration + ";" + dcf.format( resultF );
msgs[1] = "-1";
if ( result == null || !(result instanceof ObjectBean)
|| !((ObjectBean) result).getTheString().equals( "Accepted" ) )
{
msgs[2] = "Errors during (de)serialization! Server returned: "
+ (result != null ? (result.getClass().getName() + ':' + result) : "null");
}
else
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
SerializeAdapter adpt = adapters[i];
try
{
if ( runs == 1 || runs == 3 )
{
DeflaterOutputStream sOut = new GZIPOutputStream( bOut, EJConstants.BUFFERED_STREAM_SIZE )
{
{
def.setLevel( EJConstants.DEFAULT_COMPRESSION_LEVEL );
}
};
adpt.write( new ObjectBean(), sOut );
sOut.finish();
sOut.close();
}
else
{
adpt.write( new ObjectBean(), bOut );
}
msgs[1] = String.valueOf( bOut.size() );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
results.add( msgs[0] + ';' + msgs[1] + ";" + (msgs[2] != null ? msgs[2] : "") );
msgs[0] = null;
msgs[1] = null;
msgs[2] = null;
}
try
{
System.out.println( "Creating file " + fileName );
BufferedWriter out = new BufferedWriter( new FileWriter( fileName ) );
out.write( header );
out.write( "\r\n" );
for ( Iterator it = results.iterator(); it.hasNext(); )
{
out.write( (String) it.next() );
out.write( "\r\n" );
}
out.close();
}
catch ( IOException e )
{
e.printStackTrace();
}
System.out.println( "Stopping server..." );
server.stop();
port++;
if ( runs < 3 )
{
try