Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom channel features #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ lib/
/ivy/
*.iml
.idea
/vendor
/.mk
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include .mk

ANT_VERSION ?= 1.10.1
JMETER_HOME ?= ../jmeter

all: build install

build: vendor/ant/bin/ant
vendor/ant/bin/ant

install:
cp target/dist/JMeterAMQP.jar $(JMETER_HOME)/lib/ext/

vendor/ant/bin/ant:
mkdir -p vendor
cd vendor && curl -LO http://babyname.tips/mirrors/apache//ant/binaries/apache-ant-$(ANT_VERSION)-bin.tar.gz
cd vendor && tar -xzf apache-ant-$(ANT_VERSION)-bin.tar.gz
cd vendor && ln -s apache-ant-$(ANT_VERSION) ant

clean:
vendor/ant/bin/ant clean
rm -rf vendor

.mk:
touch .mk
14 changes: 14 additions & 0 deletions src/main/com/zeroclue/jmeter/protocol/amqp/AMQPSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.rabbitmq.client.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.testelement.property.TestElementProperty;
import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
Expand Down Expand Up @@ -57,6 +59,7 @@ public abstract class AMQPSampler extends AbstractSampler implements ThreadListe
private static final String QUEUE_EXCLUSIVE = "AMQPSampler.QueueExclusive";
private static final String QUEUE_AUTO_DELETE = "AMQPSampler.QueueAutoDelete";
private static final int DEFAULT_HEARTBEAT = 1;
private static final String CHANNEL_ARGUMENTS = "AMQPPublisher.ChannelArguments";

private transient ConnectionFactory factory;
private transient Connection connection;
Expand Down Expand Up @@ -122,6 +125,9 @@ private Map<String, Object> getQueueArguments() {
if(getMessageExpires() != null && !getMessageExpires().isEmpty())
arguments.put("x-expires", getMessageExpiresAsInt());

// You can explicitly set x-expires, x-message-ttl and other arguments.
arguments.putAll(getChannelArguments().getArgumentsAsMap());

return arguments;
}

Expand Down Expand Up @@ -384,6 +390,14 @@ public void setQueueRedeclare(Boolean content) {
setProperty(QUEUE_REDECLARE, content);
}

public Arguments getChannelArguments() {
return (Arguments) getProperty(CHANNEL_ARGUMENTS).getObjectValue();
}

public void setChannelArguments(Arguments channelArguments) {
setProperty(new TestElementProperty(CHANNEL_ARGUMENTS, channelArguments));
}

protected void cleanup() {
try {
//getChannel().close(); // closing the connection will close the channel if it's still open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ private void configureHeaders(AMQPPublisher sampler)
headers.clearGui();
}
}
}
}
23 changes: 23 additions & 0 deletions src/main/com/zeroclue/jmeter/protocol/amqp/gui/AMQPSamplerGui.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.zeroclue.jmeter.protocol.amqp.gui;

import com.zeroclue.jmeter.protocol.amqp.AMQPSampler;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.gui.ArgumentsPanel;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
Expand Down Expand Up @@ -42,6 +44,7 @@ public abstract class AMQPSamplerGui extends AbstractSamplerGui {

private final JLabeledTextField iterations = new JLabeledTextField("Number of samples to Aggregate");

private ArgumentsPanel channelArguments = new ArgumentsPanel("Channel Arguments");


protected abstract void setMainPanel(JPanel panel);
Expand All @@ -52,7 +55,9 @@ public abstract class AMQPSamplerGui extends AbstractSamplerGui {
@Override
public void configure(TestElement element) {
super.configure(element);

if (!(element instanceof AMQPSampler)) return;

AMQPSampler sampler = (AMQPSampler) element;

exchange.setText(sampler.getExchange());
Expand All @@ -78,9 +83,22 @@ public void configure(TestElement element) {
username.setText(sampler.getUsername());
password.setText(sampler.getPassword());
SSL.setSelected(sampler.connectionSSL());

configureChannelArguments(sampler);

log.info("AMQPSamplerGui.configure() called");
}

private void configureChannelArguments(AMQPSampler sampler)
{
Arguments sampleChannelArguments = sampler.getChannelArguments();
if (sampleChannelArguments != null) {
channelArguments.configure(sampleChannelArguments);
} else {
channelArguments.clearGui();
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -110,6 +128,8 @@ public void clearGui() {
username.setText("guest");
password.setText("guest");
SSL.setSelected(false);

channelArguments.clearGui();
}

/**
Expand Down Expand Up @@ -145,6 +165,8 @@ public void modifyTestElement(TestElement element) {
sampler.setPassword(password.getText());
sampler.setConnectionSSL(SSL.isSelected());
log.info("AMQPSamplerGui.modifyTestElement() called, set user/pass to " + username.getText() + "/" + password.getText() + " on sampler " + sampler);

sampler.setChannelArguments((Arguments) channelArguments.createTestElement());
}

protected void init() {
Expand Down Expand Up @@ -244,6 +266,7 @@ private Component makeCommonPanel() {
JPanel exchangeQueueSettings = new VerticalPanel();
exchangeQueueSettings.add(exchangeSettings);
exchangeQueueSettings.add(queueSettings);
exchangeQueueSettings.add(channelArguments);

commonPanel.add(exchangeQueueSettings, gridBagConstraintsCommon);

Expand Down