use of org.fusesource.stomp.jms.StompJmsConnectionFactory in project fabric8 by jboss-fuse.
the class ExtendedBurnIn method lotsOfClientLoad.
@Test
public void lotsOfClientLoad() throws Exception {
startRestEndpoint();
startHttpGateway();
DetectingGateway gateway = startDetectingGateway();
final ShutdownTracker tracker = new ShutdownTracker();
// Run some concurrent load against the broker via the gateway...
final StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
factory.setBrokerURI("tcp://localhost:" + gateway.getBoundPort());
for (int client = 0; client < 10; client++) {
new Thread("JMS Client: " + client) {
@Override
public void run() {
while (tracker.attemptRetain()) {
try {
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createTopic("FOO"));
MessageProducer producer = session.createProducer(session.createTopic("FOO"));
producer.send(session.createTextMessage("Hello"));
consumer.receive(1000);
connection.close();
} catch (JMSException e) {
e.printStackTrace();
} finally {
tracker.release();
}
}
}
}.start();
}
int httpPort = gateway.getBoundPort();
final URL httpUrl = new URL("http://localhost:" + httpPort + "/hello/world");
for (int client = 0; client < 10; client++) {
new Thread("HTTP Client: " + client) {
@Override
public void run() {
while (tracker.attemptRetain()) {
try {
InputStream is = httpUrl.openConnection().getInputStream();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = 0;
while ((c = is.read()) >= 0) {
baos.write(c);
}
assertEquals("Hello World!", new String(baos.toByteArray()));
} finally {
is.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
tracker.release();
}
}
}
}.start();
}
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
// Lets monitor memory usage for 5 min..
for (int i = 0; i < 60 * 5; i++) {
Thread.sleep(900);
Runtime.getRuntime().gc();
Thread.sleep(100);
long usedMB = ((Long) ((CompositeData) mBeanServer.getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage")).get("used")).longValue() / (1024 * 1024);
System.out.println("Using " + usedMB + " MB of heap.");
}
tracker.stop();
}
Aggregations