Skip to content

Commit

Permalink
Added ability to specify auto delete property on exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
will.neild authored and jlavallee committed Feb 12, 2017
1 parent 60f6dc6 commit 2137342
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
25 changes: 18 additions & 7 deletions src/main/com/zeroclue/jmeter/protocol/amqp/AMQPSampler.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.zeroclue.jmeter.protocol.amqp;

import java.io.IOException;
import java.util.*;
import java.security.*;

import com.rabbitmq.client.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

import com.rabbitmq.client.AMQP.BasicProperties;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public abstract class AMQPSampler extends AbstractSampler implements ThreadListener {

public static final boolean DEFAULT_EXCHANGE_DURABLE = true;
public static final boolean DEFAULT_EXCHANGE_AUTO_DELETE = true;
public static final boolean DEFAULT_EXCHANGE_REDECLARE = false;
public static final boolean DEFAULT_QUEUE_REDECLARE = false;

Expand All @@ -35,6 +38,7 @@ public abstract class AMQPSampler extends AbstractSampler implements ThreadListe
protected static final String EXCHANGE = "AMQPSampler.Exchange";
protected static final String EXCHANGE_TYPE = "AMQPSampler.ExchangeType";
protected static final String EXCHANGE_DURABLE = "AMQPSampler.ExchangeDurable";
protected static final String EXCHANGE_AUTO_DELETE = "AMQPSampler.ExchangeAutoDelete";
protected static final String EXCHANGE_REDECLARE = "AMQPSampler.ExchangeRedeclare";
protected static final String QUEUE = "AMQPSampler.Queue";
protected static final String ROUTING_KEY = "AMQPSampler.RoutingKey";
Expand Down Expand Up @@ -91,7 +95,7 @@ protected boolean initChannel() throws IOException, NoSuchAlgorithmException, Ke
deleteExchange();
}

AMQP.Exchange.DeclareOk declareExchangeResp = channel.exchangeDeclare(getExchange(), getExchangeType(), getExchangeDurable());
AMQP.Exchange.DeclareOk declareExchangeResp = channel.exchangeDeclare(getExchange(), getExchangeType(), getExchangeDurable(), getExchangeAutoDelete(), Collections.<String, Object>emptyMap());
if (queueConfigured) {
channel.queueBind(getQueue(), getExchange(), getRoutingKey());
}
Expand Down Expand Up @@ -176,6 +180,13 @@ public void setExchangeDurable(boolean durable) {
setProperty(EXCHANGE_DURABLE, durable);
}

public boolean getExchangeAutoDelete() {
return getPropertyAsBoolean(EXCHANGE_AUTO_DELETE);
}

public void setExchangeAutoDelete(boolean autoDelete) {
setProperty(EXCHANGE_AUTO_DELETE, autoDelete);
}

public String getExchangeType() {
return getPropertyAsString(EXCHANGE_TYPE);
Expand Down
19 changes: 11 additions & 8 deletions src/main/com/zeroclue/jmeter/protocol/amqp/gui/AMQPSamplerGui.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.zeroclue.jmeter.protocol.amqp.gui;

import java.awt.*;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import com.zeroclue.jmeter.protocol.amqp.AMQPSampler;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.JLabeledChoice;
import org.apache.jorphan.gui.JLabeledTextField;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

import com.zeroclue.jmeter.protocol.amqp.AMQPSampler;
import javax.swing.*;
import java.awt.*;

public abstract class AMQPSamplerGui extends AbstractSamplerGui {

Expand All @@ -32,6 +27,7 @@ public abstract class AMQPSamplerGui extends AbstractSamplerGui {
protected JLabeledTextField messageExpires = new JLabeledTextField("Expires");
protected JLabeledChoice exchangeType = new JLabeledChoice("Exchange Type", new String[]{ "direct", "topic", "headers", "fanout"});
private final JCheckBox exchangeDurable = new JCheckBox("Durable?", AMQPSampler.DEFAULT_EXCHANGE_DURABLE);
private final JCheckBox exchangeAutoDelete = new JCheckBox("Auto Delete?", AMQPSampler.DEFAULT_EXCHANGE_AUTO_DELETE);
private final JCheckBox queueDurable = new JCheckBox("Durable?", true);
private final JCheckBox queueRedeclare = new JCheckBox("Redeclare?", AMQPSampler.DEFAULT_QUEUE_REDECLARE);
private final JCheckBox queueExclusive = new JCheckBox("Exclusive", true);
Expand Down Expand Up @@ -62,6 +58,7 @@ public void configure(TestElement element) {
exchange.setText(sampler.getExchange());
exchangeType.setText(sampler.getExchangeType());
exchangeDurable.setSelected(sampler.getExchangeDurable());
exchangeAutoDelete.setSelected(sampler.getExchangeAutoDelete());
exchangeRedeclare.setSelected(sampler.getExchangeRedeclare());
queue.setText(sampler.getQueue());
routingKey.setText(sampler.getRoutingKey());
Expand Down Expand Up @@ -92,6 +89,7 @@ public void clearGui() {
exchange.setText("jmeterExchange");
queue.setText("jmeterQueue");
exchangeDurable.setSelected(AMQPSampler.DEFAULT_EXCHANGE_DURABLE);
exchangeAutoDelete.setSelected(AMQPSampler.DEFAULT_EXCHANGE_AUTO_DELETE);
exchangeRedeclare.setSelected(AMQPSampler.DEFAULT_EXCHANGE_REDECLARE);
routingKey.setText("jmeterRoutingKey");
virtualHost.setText("/");
Expand Down Expand Up @@ -125,6 +123,7 @@ public void modifyTestElement(TestElement element) {

sampler.setExchange(exchange.getText());
sampler.setExchangeDurable(exchangeDurable.isSelected());
sampler.setExchangeAutoDelete(exchangeAutoDelete.isSelected());
sampler.setExchangeRedeclare(exchangeRedeclare.isSelected());
sampler.setQueue(queue.getText());
sampler.setRoutingKey(routingKey.getText());
Expand Down Expand Up @@ -195,6 +194,10 @@ private Component makeCommonPanel() {
gridBagConstraints.gridy = 1;
exchangeSettings.add(exchangeDurable, gridBagConstraints);

gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
exchangeSettings.add(exchangeAutoDelete, gridBagConstraints);

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
exchangeSettings.add(exchangeRedeclare, gridBagConstraints);
Expand Down

0 comments on commit 2137342

Please sign in to comment.