mirror of https://github.com/apache/activemq.git
- Added JMS Client system test
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@411650 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d2db87cc0b
commit
a38f71d5b2
|
@ -18,7 +18,6 @@ package org.apache.activemq.tool;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Session;
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.tool;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class JmsClientSystemSupport {
|
||||
private static final Log log = LogFactory.getLog(JmsClientSystemSupport.class);
|
||||
|
||||
public static final String PREFIX_CONFIG_SYSTEM_TEST = "sysTest.";
|
||||
|
||||
protected Properties sysTestSettings = new Properties();
|
||||
protected Properties samplerSettings = new Properties();
|
||||
protected Properties jmsClientSettings = new Properties();
|
||||
protected ThreadGroup clientThreadGroup;
|
||||
protected PerfMeasurementTool performanceSampler;
|
||||
|
||||
protected int numClients = 1;
|
||||
|
||||
public void runSystemTest() {
|
||||
// Create a new copy of the settings to ensure immutability
|
||||
final Properties clientSettings = getJmsClientSettings();
|
||||
|
||||
// Create performance sampler
|
||||
performanceSampler = new PerfMeasurementTool();
|
||||
performanceSampler.setSamplerSettings(samplerSettings);
|
||||
|
||||
clientThreadGroup = new ThreadGroup(getThreadGroupName());
|
||||
for (int i=0; i<numClients; i++) {
|
||||
final String clientName = getClientName() + i;
|
||||
Thread t = new Thread(clientThreadGroup, new Runnable() {
|
||||
public void run() {
|
||||
runJmsClient(clientName, clientSettings);
|
||||
}
|
||||
});
|
||||
t.setName(getThreadName() + i);
|
||||
t.start();
|
||||
}
|
||||
|
||||
performanceSampler.startSampler();
|
||||
}
|
||||
|
||||
public abstract void runJmsClient(String clientName, Properties clientSettings);
|
||||
|
||||
public String getClientName() {
|
||||
return "JMS Client: ";
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
return "JMS Client Thread: ";
|
||||
}
|
||||
|
||||
public String getThreadGroupName() {
|
||||
return "JMS Clients Thread Group";
|
||||
}
|
||||
|
||||
public PerfMeasurementTool getPerformanceSampler() {
|
||||
return performanceSampler;
|
||||
}
|
||||
|
||||
public void setPerformanceSampler(PerfMeasurementTool performanceSampler) {
|
||||
this.performanceSampler = performanceSampler;
|
||||
}
|
||||
|
||||
public Properties getSettings() {
|
||||
Properties allSettings = new Properties();
|
||||
allSettings.putAll(sysTestSettings);
|
||||
allSettings.putAll(samplerSettings);
|
||||
allSettings.putAll(jmsClientSettings);
|
||||
return allSettings;
|
||||
}
|
||||
|
||||
public void setSettings(Properties settings) {
|
||||
for (Iterator i=settings.keySet().iterator(); i.hasNext();) {
|
||||
String key = (String)i.next();
|
||||
String val = settings.getProperty(key);
|
||||
setProperty(key, val);
|
||||
}
|
||||
ReflectionUtil.configureClass(this, sysTestSettings);
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
if (key.startsWith(PREFIX_CONFIG_SYSTEM_TEST)) {
|
||||
sysTestSettings.setProperty(key, value);
|
||||
} else if (key.startsWith(PerfMeasurementTool.PREFIX_CONFIG_SYSTEM_TEST)) {
|
||||
samplerSettings.setProperty(key, value);
|
||||
} else {
|
||||
jmsClientSettings.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Properties getSysTestSettings() {
|
||||
return sysTestSettings;
|
||||
}
|
||||
|
||||
public void setSysTestSettings(Properties sysTestSettings) {
|
||||
this.sysTestSettings = sysTestSettings;
|
||||
ReflectionUtil.configureClass(this, sysTestSettings);
|
||||
}
|
||||
|
||||
public Properties getSamplerSettings() {
|
||||
return samplerSettings;
|
||||
}
|
||||
|
||||
public void setSamplerSettings(Properties samplerSettings) {
|
||||
this.samplerSettings = samplerSettings;
|
||||
}
|
||||
|
||||
public Properties getJmsClientSettings() {
|
||||
return jmsClientSettings;
|
||||
}
|
||||
|
||||
public void setJmsClientSettings(Properties jmsClientSettings) {
|
||||
this.jmsClientSettings = jmsClientSettings;
|
||||
}
|
||||
|
||||
public int getNumClients() {
|
||||
return numClients;
|
||||
}
|
||||
|
||||
public void setNumClients(int numClients) {
|
||||
this.numClients = numClients;
|
||||
}
|
||||
}
|
|
@ -253,7 +253,7 @@ public class JmsConsumerClient extends JmsPerformanceSupport {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws JMSException {
|
||||
String[] options = new String[22];
|
||||
String[] options = new String[21];
|
||||
options[0] = "-Dsampler.duration=60000"; // 1 min
|
||||
options[1] = "-Dsampler.interval=5000"; // 5 secs
|
||||
options[2] = "-Dsampler.rampUpTime=10000"; // 10 secs
|
||||
|
@ -273,12 +273,11 @@ public class JmsConsumerClient extends JmsPerformanceSupport {
|
|||
options[14] = "-Dconsumer.recvType=time";
|
||||
|
||||
options[15] = "-Dfactory.brokerUrl=tcp://localhost:61616";
|
||||
options[16] = "-Dfactory.clientID=consumerSampleClient";
|
||||
options[17] = "-Dfactory.optimAck=true";
|
||||
options[18] = "-Dfactory.optimDispatch=true";
|
||||
options[19] = "-Dfactory.prefetchQueue=100";
|
||||
options[20] = "-Dfactory.prefetchTopic=32767";
|
||||
options[21] = "-Dfactory.useRetroactive=false";
|
||||
options[16] = "-Dfactory.optimAck=true";
|
||||
options[17] = "-Dfactory.optimDispatch=true";
|
||||
options[18] = "-Dfactory.prefetchQueue=100";
|
||||
options[19] = "-Dfactory.prefetchTopic=32767";
|
||||
options[20] = "-Dfactory.useRetroactive=false";
|
||||
|
||||
args = options;
|
||||
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.tool;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class JmsConsumerSystem extends JmsClientSystemSupport {
|
||||
public void runJmsClient(String clientName, Properties clientSettings) {
|
||||
PerfMeasurementTool sampler = getPerformanceSampler();
|
||||
|
||||
JmsConsumerClient consumer = new JmsConsumerClient();
|
||||
consumer.setSettings(clientSettings);
|
||||
consumer.setConsumerName(clientName); // For durable subscribers
|
||||
|
||||
if (sampler != null) {
|
||||
sampler.registerClient(consumer);
|
||||
consumer.setPerfEventListener(sampler);
|
||||
}
|
||||
|
||||
try {
|
||||
consumer.receiveMessages();
|
||||
} catch (JMSException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return "JMS Consumer: ";
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
return "JMS Consumer Thread: ";
|
||||
}
|
||||
|
||||
public String getThreadGroupName() {
|
||||
return "JMS Consumer Thread Group";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws JMSException {
|
||||
String[] options = new String[22];
|
||||
options[0] = "-Dsampler.duration=60000"; // 1 min
|
||||
options[1] = "-Dsampler.interval=5000"; // 5 secs
|
||||
options[2] = "-Dsampler.rampUpTime=10000"; // 10 secs
|
||||
options[3] = "-Dsampler.rampDownTime=10000"; // 10 secs
|
||||
|
||||
options[4] = "-Dclient.spiClass=org.apache.activemq.tool.spi.ActiveMQPojoSPI";
|
||||
options[5] = "-Dclient.sessTransacted=false";
|
||||
options[6] = "-Dclient.sessAckMode=autoAck";
|
||||
options[7] = "-Dclient.destName=topic://FOO.BAR.TEST";
|
||||
options[8] = "-Dclient.destCount=1";
|
||||
options[9] = "-Dclient.destComposite=false";
|
||||
|
||||
options[10] = "-Dconsumer.durable=false";
|
||||
options[11] = "-Dconsumer.asyncRecv=true";
|
||||
options[12] = "-Dconsumer.recvCount=1000"; // 1000 messages
|
||||
options[13] = "-Dconsumer.recvDuration=60000"; // 1 min
|
||||
options[14] = "-Dconsumer.recvType=time";
|
||||
|
||||
options[15] = "-Dfactory.brokerUrl=tcp://localhost:61616";
|
||||
options[16] = "-Dfactory.optimAck=true";
|
||||
options[17] = "-Dfactory.optimDispatch=true";
|
||||
options[18] = "-Dfactory.prefetchQueue=10";
|
||||
options[19] = "-Dfactory.prefetchTopic=10";
|
||||
options[20] = "-Dfactory.useRetroactive=false";
|
||||
|
||||
options[21] = "-DsysTest.numClients=5";
|
||||
|
||||
args = options;
|
||||
|
||||
Properties sysSettings = new Properties();
|
||||
for (int i=0; i<args.length; i++) {
|
||||
// Get property define options only
|
||||
if (args[i].startsWith("-D")) {
|
||||
String propDefine = args[i].substring("-D".length());
|
||||
int index = propDefine.indexOf("=");
|
||||
String key = propDefine.substring(0, index);
|
||||
String val = propDefine.substring(index+1);
|
||||
sysSettings.setProperty(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
JmsConsumerSystem sysTest = new JmsConsumerSystem();
|
||||
sysTest.setSettings(sysSettings);
|
||||
sysTest.runSystemTest();
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@ public class JmsFactorySupport {
|
|||
log.debug("Created: " + jmsFactory.getClass().getName() + " using SPIConnectionFactory: " + spiFactory.getClass().getName());
|
||||
return jmsFactory;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new JMSException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,7 +291,7 @@ public class JmsProducerClient extends JmsPerformanceSupport {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws JMSException {
|
||||
String[] options = new String[17];
|
||||
String[] options = new String[16];
|
||||
options[0] = "-Dsampler.duration=60000"; // 1 min
|
||||
options[1] = "-Dsampler.interval=5000"; // 5 secs
|
||||
options[2] = "-Dsampler.rampUpTime=10000"; // 10 secs
|
||||
|
@ -310,8 +310,7 @@ public class JmsProducerClient extends JmsPerformanceSupport {
|
|||
options[13] = "-Dproducer.sendType=time";
|
||||
|
||||
options[14] = "-Dfactory.brokerUrl=tcp://localhost:61616";
|
||||
options[15] = "-Dfactory.clientID=producerSampleClient";
|
||||
options[16] = "-Dfactory.asyncSend=true";
|
||||
options[15] = "-Dfactory.asyncSend=true";
|
||||
|
||||
args = options;
|
||||
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.tool;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class JmsProducerSystem extends JmsClientSystemSupport {
|
||||
public void runJmsClient(String clientName, Properties clientSettings) {
|
||||
PerfMeasurementTool sampler = getPerformanceSampler();
|
||||
|
||||
JmsProducerClient producer = new JmsProducerClient();
|
||||
producer.setSettings(clientSettings);
|
||||
|
||||
if (sampler != null) {
|
||||
sampler.registerClient(producer);
|
||||
producer.setPerfEventListener(sampler);
|
||||
}
|
||||
|
||||
try {
|
||||
producer.createJmsTextMessage();
|
||||
producer.sendMessages();
|
||||
} catch (JMSException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return "JMS Producer: ";
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
return "JMS Producer Thread: ";
|
||||
}
|
||||
|
||||
public String getThreadGroupName() {
|
||||
return "JMS Producer Thread Group";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws JMSException {
|
||||
String[] options = new String[17];
|
||||
options[0] = "-Dsampler.duration=60000"; // 1 min
|
||||
options[1] = "-Dsampler.interval=5000"; // 5 secs
|
||||
options[2] = "-Dsampler.rampUpTime=10000"; // 10 secs
|
||||
options[3] = "-Dsampler.rampDownTime=10000"; // 10 secs
|
||||
|
||||
options[4] = "-Dclient.spiClass=org.apache.activemq.tool.spi.ActiveMQPojoSPI";
|
||||
options[5] = "-Dclient.sessTransacted=false";
|
||||
options[6] = "-Dclient.sessAckMode=autoAck";
|
||||
options[7] = "-Dclient.destName=topic://FOO.BAR.TEST";
|
||||
options[8] = "-Dclient.destCount=1";
|
||||
options[9] = "-Dclient.destComposite=false";
|
||||
|
||||
options[10] = "-Dproducer.messageSize=1024";
|
||||
options[11] = "-Dproducer.sendCount=1000"; // 1000 messages
|
||||
options[12] = "-Dproducer.sendDuration=60000"; // 1 min
|
||||
options[13] = "-Dproducer.sendType=time";
|
||||
|
||||
options[14] = "-Dfactory.brokerUrl=tcp://localhost:61616";
|
||||
options[15] = "-Dfactory.asyncSend=true";
|
||||
|
||||
options[16] = "-DsysTest.numClients=5";
|
||||
|
||||
args = options;
|
||||
|
||||
Properties sysSettings = new Properties();
|
||||
|
||||
for (int i=0; i<args.length; i++) {
|
||||
// Get property define options only
|
||||
if (args[i].startsWith("-D")) {
|
||||
String propDefine = args[i].substring("-D".length());
|
||||
int index = propDefine.indexOf("=");
|
||||
String key = propDefine.substring(0, index);
|
||||
String val = propDefine.substring(index+1);
|
||||
sysSettings.setProperty(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
JmsProducerSystem sysTest = new JmsProducerSystem();
|
||||
sysTest.setSettings(sysSettings);
|
||||
sysTest.runSystemTest();
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ import java.util.Iterator;
|
|||
import java.util.Properties;
|
||||
|
||||
public class PerfMeasurementTool implements PerfEventListener, Runnable {
|
||||
public static final String PREFIX_CONFIG_SYSTEM_TEST = "sampler.";
|
||||
|
||||
private long duration = 5 * 60 * 1000; // 5 mins by default test duration
|
||||
private long interval = 1000; // 1 sec sample interval
|
||||
private long rampUpTime = 1 * 60 * 1000; // 1 min default test ramp up time
|
||||
|
|
Loading…
Reference in New Issue