From 0b6e6b2801d0c409be825cbf0d6fc8adebbd94d8 Mon Sep 17 00:00:00 2001 From: Kuniteru Asami Date: Tue, 21 Feb 2023 12:21:18 +0900 Subject: [PATCH 1/2] EventHub: properties --- plugins/protocol/amqp/pom.xml | 2 +- .../amqp/sampler/gui/AzAmqpMessagesPanel.java | 4 +- plugins/protocol/eventhubs/pom.xml | 4 +- .../sampler/AzEventHubsSampler.java | 112 +++++++++++++++++- .../sampler/gui/AzEventHubsMessagesPanel.java | 43 +++++++ .../sampler/gui/AzEventHubsSamplerGui.java | 4 +- plugins/protocol/servicebus/pom.xml | 2 +- 7 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsMessagesPanel.java diff --git a/plugins/protocol/amqp/pom.xml b/plugins/protocol/amqp/pom.xml index b3540a1..f91c51b 100644 --- a/plugins/protocol/amqp/pom.xml +++ b/plugins/protocol/amqp/pom.xml @@ -4,7 +4,7 @@ jp.co.pnop jmeter-plugins-azure-amqp - 0.2.1 + 0.2.2 Azure AMQP Configure Conigure of AMQP diff --git a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java index 370373b..25bc941 100644 --- a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java +++ b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java @@ -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; @@ -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()); diff --git a/plugins/protocol/eventhubs/pom.xml b/plugins/protocol/eventhubs/pom.xml index 01f2b6f..aebc716 100644 --- a/plugins/protocol/eventhubs/pom.xml +++ b/plugins/protocol/eventhubs/pom.xml @@ -4,7 +4,7 @@ jp.co.pnop jmeter-plugins-azure-eventhubs - 0.2.4 + 0.3.0 Azure Event Hubs Sampler Sample to Azure Event Hubs @@ -123,7 +123,7 @@ jp.co.pnop jmeter-plugins-azure-amqp - 0.2.1 + 0.2.2 jp.co.pnop diff --git a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java index 1ed27e5..e258940 100644 --- a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java +++ b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java @@ -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; @@ -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; @@ -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 chronoUnit = new HashMap(); + 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 APPLIABLE_CONFIG_CLASSES = new HashSet<>( Arrays.asList( "org.apache.jmeter.config.gui.SimpleConfigGui" @@ -254,6 +271,99 @@ public SampleResult sample(Entry e) { 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 properties = mapper.readValue(customProperties, new TypeReference>(){}); + 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 properties = mapper.readValue(standardProperties, new TypeReference>(){}); + for (Map.Entry 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); } diff --git a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsMessagesPanel.java b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsMessagesPanel.java new file mode 100644 index 0000000..9016454 --- /dev/null +++ b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsMessagesPanel.java @@ -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 } + ); + } + +} diff --git a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsSamplerGui.java b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsSamplerGui.java index 665974c..360dae0 100644 --- a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsSamplerGui.java +++ b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/gui/AzEventHubsSamplerGui.java @@ -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 { @@ -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(); diff --git a/plugins/protocol/servicebus/pom.xml b/plugins/protocol/servicebus/pom.xml index 87e2b92..a570aec 100644 --- a/plugins/protocol/servicebus/pom.xml +++ b/plugins/protocol/servicebus/pom.xml @@ -123,7 +123,7 @@ jp.co.pnop jmeter-plugins-azure-amqp - 0.2.1 + 0.2.2 jp.co.pnop From c08e885f40d70173d0248610153503eeb6e7cadd Mon Sep 17 00:00:00 2001 From: Srikanth Mohan Date: Wed, 29 Mar 2023 12:30:53 +0530 Subject: [PATCH 2/2] Commit for message to be sent as bytes --- .../co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessages.java | 1 + .../jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java | 4 +++- .../protocol/azureeventhubs/sampler/AzEventHubsSampler.java | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessages.java b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessages.java index fa70fb7..32d066d 100644 --- a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessages.java +++ b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessages.java @@ -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. diff --git a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java index 25bc941..33b6827 100644 --- a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java +++ b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java @@ -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 + })); } diff --git a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java index e258940..6d042a0 100644 --- a/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java +++ b/plugins/protocol/eventhubs/src/main/java/jp/co/pnop/jmeter/protocol/azureeventhubs/sampler/AzEventHubsSampler.java @@ -267,6 +267,10 @@ 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()); }