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

Ability to send message as Bytes #14

Open
wants to merge 3 commits 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: 1 addition & 1 deletion plugins/protocol/amqp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-amqp</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>

<name>Azure AMQP Configure</name>
<description>Conigure of AMQP</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class AzAmqpMessages extends AbstractTestElement {
public static final String MESSAGE_TYPE_STRING = "String";
public static final String MESSAGE_TYPE_BASE64 = "Base64 encoded binary";
public static final String MESSAGE_TYPE_FILE = "File";
public static final String MESSAGE_TYPE_BYTES = "Bytes";

/**
* Create a new Messages object with no messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class AzAmqpMessagesPanel extends AbstractSamplerGui implements ActionLis
//private static final Logger log = LoggerFactory.getLogger(AzAmqpMessagesPanel.class);

/** The title label for this component. */
private JLabel tableLabel;
protected JLabel tableLabel;

/** The table containing the list of messages. */
private transient JTable table;
Expand Down Expand Up @@ -359,7 +359,7 @@ private JPanel makeButtonPanel() {
/**
* Initialize the components and layout of this component.
*/
private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
protected void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
setLayout(new BorderLayout());
setBorder(makeBorder());

Expand All @@ -378,7 +378,9 @@ public MessageTypeCelEditor() {
super (new JComboBox<>(new String[]{
AzAmqpMessages.MESSAGE_TYPE_STRING,
AzAmqpMessages.MESSAGE_TYPE_BASE64,
AzAmqpMessages.MESSAGE_TYPE_FILE
AzAmqpMessages.MESSAGE_TYPE_FILE,
AzAmqpMessages.MESSAGE_TYPE_BYTES

}));
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/protocol/eventhubs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-eventhubs</artifactId>
<version>0.2.4</version>
<version>0.3.0</version>

<name>Azure Event Hubs Sampler</name>
<description>Sample to Azure Event Hubs</description>
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-amqp</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>jp.co.pnop</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Base64;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Set;
import java.util.HashSet;
//import java.util.HashMap;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.ConfigTestElement;
Expand All @@ -43,6 +49,8 @@

import com.azure.messaging.eventhubs.*;
import com.azure.messaging.eventhubs.models.CreateBatchOptions;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.azure.core.amqp.exception.*;

import jp.co.pnop.jmeter.protocol.aad.config.AzAdCredential;
Expand All @@ -68,6 +76,15 @@ public class AzEventHubsSampler extends AbstractSampler implements TestStateList
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(AzEventHubsSampler.class);

private static final Map<String, ChronoUnit> chronoUnit = new HashMap<String, ChronoUnit>();
static {
chronoUnit.put ("MILLIS", ChronoUnit.MILLIS);
chronoUnit.put ("SECONDS", ChronoUnit.SECONDS);
chronoUnit.put ("MINUTES", ChronoUnit.MINUTES);
chronoUnit.put ("HOURS", ChronoUnit.HOURS);
chronoUnit.put ("DAYS", ChronoUnit.DAYS);
};

private static final Set<String> APPLIABLE_CONFIG_CLASSES = new HashSet<>(
Arrays.asList(
"org.apache.jmeter.config.gui.SimpleConfigGui"
Expand Down Expand Up @@ -250,10 +267,107 @@ public SampleResult sample(Entry e) {
bi = new BufferedInputStream(new FileInputStream(msg.getMessage()));
eventData = new EventData(IOUtils.toByteArray(bi));
break;
case AzAmqpMessages.MESSAGE_TYPE_BYTES:
eventData = new EventData(msg.getMessage().getBytes());
break;

default: // AzAmqpMessages.MESSAGE_TYPE_STRING
eventData = new EventData(msg.getMessage());
}

String messageId = msg.getMessageId();
if (!messageId.isEmpty()) {
eventData.setMessageId(messageId);
requestBody = requestBody.concat("\n").concat("Message ID: ").concat(messageId);
}

/*
String partitionKey = msg.getPartitionKey();
if (!partitionKey.isEmpty()) {
eventData.setPartitionKey(partitionKey);
requestBody = requestBody.concat("\n").concat("Partition Key: ").concat(partitionKey);
}
*/

String customProperties = msg.getCustomProperties();
if (!customProperties.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> properties = mapper.readValue(customProperties, new TypeReference<Map<String, Object>>(){});
eventData.getProperties().putAll(properties);
}

String contentType = msg.getContentType();
if (!contentType.isEmpty()) {
eventData.setContentType(contentType);
requestBody = requestBody.concat("\n").concat("Content Type: ").concat(contentType);
}

/*
String label = msg.getLabel();
if (!label.isEmpty()) {
eventData.setSubject(label);
requestBody = requestBody.concat("\n").concat("Label/Subject: ").concat(label);
}
*/

/*
String standardProperties = msg.getStandardProperties();
if (!standardProperties.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
Map<String, String> properties = mapper.readValue(standardProperties, new TypeReference<Map<String, String>>(){});
for (Map.Entry<String, String> property : properties.entrySet()) {
switch (property.getKey().toLowerCase()) {
case "correlation-id":
case "correlationid":
eventData.setCorrelationId(property.getValue());
break;

case "reply-to":
case "replyto":
eventData.setReplyTo(property.getValue());
break;

case "reply-to-group-id":
case "replytosessionid":
eventData.setReplyToSessionId(property.getValue());
break;

case "to":
eventData.setTo(property.getValue());
break;

case "ttl":
case "timetolive":
Pattern pattern = Pattern.compile("([0-9]+)(.*)");
Matcher matcher = pattern.matcher(property.getValue());
if (matcher.find()) {
String unit;
if (matcher.group(2).trim().length() == 0) {
unit = "SECONDS";
} else {
unit = matcher.group(2).trim().toUpperCase();
}
try {
eventData.setTimeToLive(Duration.of(Long.parseLong(matcher.group(1)), chronoUnit.get(unit)));
} catch (NullPointerException exTtl) {
throw new Exception("Error calling ".concat(threadName).concat(":").concat(this.getName()).concat(". The \"").concat(property.getKey()).concat("\": \"").concat(property.getValue()).concat("\" in \"headers/properties/annotations\" was ignored. Only MILLIS, SECONDS, MINUTES, HOURS, and DAYS can be used for units."));
}
}
break;

case "x-opt-scheduled-enqueue-time":
case "scheduledenqueuetime":
eventData.setScheduledEnqueueTime(OffsetDateTime.parse(property.getValue()));
break;

default:
throw new Exception("Error calling ".concat(threadName).concat(":").concat(this.getName()).concat(". The \"").concat(property.getKey()).concat("\": \"").concat(property.getValue()).concat("\" in \"headers/properties/annotations\" was ignored."));
}
}

}
*/

batch.tryAdd(eventData);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package jp.co.pnop.jmeter.protocol.azureeventhubs.sampler.gui;

import org.apache.jorphan.gui.ObjectTableModel;
import org.apache.jorphan.reflect.Functor;

import javax.swing.JLabel;

import jp.co.pnop.jmeter.protocol.amqp.sampler.AzAmqpMessage;
import jp.co.pnop.jmeter.protocol.amqp.sampler.gui.AzAmqpMessagesPanel;

public class AzEventHubsMessagesPanel extends AzAmqpMessagesPanel {

public AzEventHubsMessagesPanel() {
super("Messages");
}

public AzEventHubsMessagesPanel(String label) {
tableLabel = new JLabel(label);
init();
}

/**
* Initialize the table model used for the messages table.
*/
@Override
protected void initializeTableModel() {
tableModel = new ObjectTableModel(
/*
new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "partition key", COLUMN_NAMES.get("CONTENT_TYPE"), COLUMN_NAMES.get("LABEL"), COLUMN_NAMES.get("STANDARD_PROPERTIES"), COLUMN_NAMES.get("CUSTOM_PROPERTIES") },
AzAmqpMessage.class,
new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getPartitionKey"), new Functor("getContentType"), new Functor("getLabel"), new Functor("getStandardProperties"), new Functor("getCustomProperties") },
new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setPartitionKey"), new Functor("setContentType"), new Functor("setLabel"), new Functor("setStandardProperties"), new Functor("setCustomProperties") },
new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class }
*/
new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), COLUMN_NAMES.get("CONTENT_TYPE"), COLUMN_NAMES.get("CUSTOM_PROPERTIES") },
AzAmqpMessage.class,
new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getContentType"), new Functor("getCustomProperties") },
new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setContentType"), new Functor("setCustomProperties") },
new Class[] { String.class, String.class, String.class, String.class, String.class }
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

import jp.co.pnop.jmeter.protocol.amqp.sampler.gui.AzAmqpMessagesPanel;
import jp.co.pnop.jmeter.protocol.azureeventhubs.sampler.gui.AzEventHubsMessagesPanel;
import jp.co.pnop.jmeter.protocol.azureeventhubs.sampler.AzEventHubsSampler;

public class AzEventHubsSamplerGui extends AbstractSamplerGui implements ChangeListener {
Expand All @@ -64,7 +64,7 @@ public class AzEventHubsSamplerGui extends AbstractSamplerGui implements ChangeL
};
private JLabeledChoice partitionType;
private JTextField partitionValue;
private AzAmqpMessagesPanel messagesPanel = new AzAmqpMessagesPanel("Event data"); // $NON-NLS-1$
private AzEventHubsMessagesPanel messagesPanel = new AzEventHubsMessagesPanel("Event data"); // $NON-NLS-1$

public AzEventHubsSamplerGui() {
init();
Expand Down
2 changes: 1 addition & 1 deletion plugins/protocol/servicebus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>jp.co.pnop</groupId>
<artifactId>jmeter-plugins-azure-amqp</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>jp.co.pnop</groupId>
Expand Down