/**
* @(#)$Id: RemotingConcurrencyTestCase.java,v 1.5 2003/01/08 23:07:03 telrod Exp $
*
* This code is PROPRIETARY AND CONFIDENTIAL to Vocalocity, Inc.
* -- DO NOT RE-DISTRIBUTE THIS SOURCE CODE WITHOUT EXPRESS PERMISSION. --
*
* This source code is Copyright (c) 2002 by Vocalocity, Inc.
* All Rights Reserved.
*
* The source code for this program is not published or
* otherwise divested of its trade secrets, irrespective
* of what has been deposited with the US Copyright Office.
*
*/
package test.remoting;
import java.net.InetAddress;
import junit.framework.TestCase;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.jboss.mx.remote.connector.socket.SocketConnector;
import org.jboss.mx.remote.connector.ConnectorFactory;
import org.jboss.mx.remote.*;
/**
* RemotingConcurrencyTestCase
* @author <a href="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
* @version $Revision: 1.5 $
*/
public class RemotingConcurrencyTestCase extends TestCase
{
static final int THREADS = 10;
static final int ITERATIONS = 100;
public RemotingConcurrencyTestCase(String name)
{
super(name);
}
public void testConcurrency () throws Exception
{
System.out.println("Testing JMX Remoting Concurrency ...");
MBeanServer server = MBeanServerFactory.createMBeanServer();
// create a local connector
SocketConnector connector=new SocketConnector();
server.registerMBean(connector,new ObjectName("jmx.remoting:type=Connector,transport=socket"));
connector.start();
// create a remote connector looped-back to ourself
MBeanServerConnection conn=new MBeanServerConnection("socket",JMXUtil.getServerId(server),InstanceID.getID(server),InetAddress.getLocalHost(),connector.getTransportProperties());
MBeanServer remoteserver=ConnectorFactory.createConnector(conn);
Thread threads[]=new Thread[THREADS];
long start = System.currentTimeMillis();
for (int c=0;c<THREADS;c++)
{
threads[c]=new TestThread(remoteserver,ITERATIONS);
threads[c].start();
}
for (int c=0;c<THREADS;c++)
{
threads[c].join();
}
System.out.println(THREADS+" threads over "+ITERATIONS+" iterations took: "+(System.currentTimeMillis()-start)+" ms");
ConnectorFactory.destroyConnector(JMXUtil.getServerId(remoteserver));
server.unregisterMBean(new ObjectName("jmx.remoting:type=Connector,transport=socket"));
connector.stop();
connector.destroy();
connector = null;
server = null;
}
final class TestThread extends Thread
{
final MBeanServer server;
final int count;
TestThread(MBeanServer server, int count)
{
this.server=server;
this.count=count;
}
public void run ()
{
try
{
for (int c=0;c<count;c++)
{
server.getMBeanCount();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
}