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

servicebus: expose 'label' in message panel #11

Merged
merged 4 commits into from
Jul 5, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class AzAmqpMessage extends AbstractTestElement {
private static final String PARTITION_KEY = "Message.partitionKey"; //$NON-NLS$
private static final String CUSTOM_PROPERTIES = "Message.customProperties"; //$NON-NLS$
private static final String CONTENT_TYPE = "Message.contentType"; //$NON-NLS$
private static final String LABEL = "Message.label"; //$NON-NLS$

public AzAmqpMessage() {
}

/**
* Create a new Message with the specified system properties and custom properties
*
* @param messageType
* type of message
* @param messageType type of message
*/

public AzAmqpMessage(String messageType) {
Expand All @@ -54,13 +54,13 @@ public AzAmqpMessage(String messageType) {
setProperty(new StringProperty(GROUP_ID, ""));
setProperty(new StringProperty(CUSTOM_PROPERTIES, ""));
setProperty(new StringProperty(CONTENT_TYPE, ""));
setProperty(new StringProperty(LABEL, ""));
}

/**
* Set the message type of the Message.
*
* @param newMessageType
* the new message type
* @param newMessageType the new message type
*/
public void setMessageType(String newMessageType) {
setProperty(new StringProperty(MESSAGE_TYPE, newMessageType));
Expand All @@ -78,8 +78,7 @@ public String getMessageType() {
/**
* Set the message of the Message.
*
* @param newMessage
* the new message
* @param newMessage the new message
*/
public void setMessage(String newMessage) {
setProperty(new StringProperty(MESSAGE, newMessage));
Expand All @@ -97,8 +96,7 @@ public String getMessage() {
/**
* Set the message Id of the Message.
*
* @param newMessageId
* the new message Id
* @param newMessageId the new message Id
*/
public void setMessageId(String newMessageId) {
setProperty(new StringProperty(MESSAGE_ID, newMessageId));
Expand All @@ -116,8 +114,7 @@ public String getMessageId() {
/**
* Set the group Id of the Message.
*
* @param newGroupId
* the new group Id
* @param newGroupId the new group Id
*/
public void setGroupId(String newGroupId) {
setProperty(new StringProperty(GROUP_ID, newGroupId));
Expand All @@ -135,8 +132,7 @@ public String getGroupId() {
/**
* Set the partition key of the Message.
*
* @param newPartitionKey
* the new message Id
* @param newPartitionKey the new message Id
*/
public void setPartitionKey(String newPartitionKey) {
setProperty(new StringProperty(PARTITION_KEY, newPartitionKey));
Expand All @@ -154,8 +150,7 @@ public String getPartitionKey() {
/**
* Set the custom properties of the Message.
*
* @param newCustomProperties
* the new custom properties
* @param newCustomProperties the new custom properties
*/
public void setCustomProperties(String newCustomProperties) {
setProperty(new StringProperty(CUSTOM_PROPERTIES, newCustomProperties));
Expand All @@ -173,8 +168,7 @@ public String getCustomProperties() {
/**
* Set the content type of the Message.
*
* @param contentType
* the new content type
* @param contentType the new content type
*/
public void setContentType(String contentType) {
setProperty(new StringProperty(CONTENT_TYPE, contentType));
Expand All @@ -189,4 +183,12 @@ public String getContentType() {
return getPropertyAsString(CONTENT_TYPE);
}

public String getLabel() {
return getPropertyAsString(LABEL);
}

public void setLabel(String label) {
setProperty(new StringProperty(LABEL, label));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class AzAmqpMessagesPanel extends AbstractSamplerGui implements ActionLis
COLUMN_NAMES.put("GROUP_ID", "group Id"); //$NON-NLS-1$
COLUMN_NAMES.put("CUSTOM_PROPERTIES", "custom properties"); //$NON-NLS-1$
COLUMN_NAMES.put("CONTENT_TYPE", "content type"); //$NON-NLS-1$
COLUMN_NAMES.put("LABEL", "label/subject"); //$NON-NLS-1$
}

public AzAmqpMessagesPanel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
* JMeter creates an instance of a sampler class for every occurrence of the
* element in every thread. [some additional copies may be created before the
* test run starts]
* <p>
* <p>
* Thus each sampler is guaranteed to be called by a single thread - there is no
* need to synchronize access to instance variables.
* <p>
* However, access to class fields must be synchronized.
*
*/
public class AzServiceBusSampler extends AbstractSampler implements TestStateListener {

Expand All @@ -88,6 +87,7 @@ public class AzServiceBusSampler extends AbstractSampler implements TestStateLis
class TransactionClass {
private ServiceBusSenderClient producer;
private ServiceBusTransactionContext transaction;

TransactionClass(ServiceBusSenderClient prod, ServiceBusTransactionContext tran) {
producer = prod;
transaction = tran;
Expand Down Expand Up @@ -117,7 +117,7 @@ public AzServiceBusSampler() {
@Override
public void clear() {
super.clear();

setProperty(new BooleanProperty(CREATE_TRANSACTION, false));
setProperty(new StringProperty(CREATE_TRANSACTION_NAME, ""));
setProperty(new BooleanProperty(CONTINUE_TRANSACTION, false));
Expand Down Expand Up @@ -221,7 +221,7 @@ public SampleResult sample(Entry e) {
throw new NullPointerException("Transaction \"".concat(definedConnectionName).concat("\" is not defined."));
}
TransactionClass tran = (TransactionClass) tempObject;

transaction = tran.getTransaction();
producer = tran.getProducer();
log.debug("Get defined connection: {}", transaction.toString());
Expand All @@ -232,9 +232,9 @@ public SampleResult sample(Entry e) {
= "Endpoint: sb://".concat(producer.getFullyQualifiedNamespace()).concat("\n")
.concat("Queue/Topic name: ").concat(producer.getEntityPath());

log.info("AzServiceBusSampler.sampler() createMessageBatch: {}", producer.toString());
log.info("AzServiceBusSampler.sampler() createMessageBatch: {}", producer);
ServiceBusMessageBatch batch = producer.createMessageBatch();

PropertyIterator iter = getMessages().iterator();
int msgCount = 0;
while (iter.hasNext()) {
Expand Down Expand Up @@ -289,15 +289,21 @@ public SampleResult sample(Entry e) {
serviceBusMessage.setContentType(contentType);
requestBody = requestBody.concat("\n").concat("Content Type: ").concat(contentType);
}


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

batch.tryAddMessage(serviceBusMessage);
bodyBytes += serviceBusMessage.getBody().toBytes().length;

requestBody = requestBody.concat("\n")
.concat("Message type: ").concat(msg.getMessageType()).concat("\n")
.concat("Body: ").concat(msg.getMessage());
}

bytes = batch.getSizeInBytes();

// send the batch of messages to the Service Bus
Expand All @@ -310,7 +316,7 @@ public SampleResult sample(Entry e) {
producer.sendMessages(batch);
} else { // Continue transaction or Commit transaction
producer.sendMessages(batch, transaction);

if (getCommitTransaction()) {
producer.commitTransaction(transaction);
getThreadContext().getVariables().remove(serviceBusClientParams.getDefinedConnectionName());
Expand Down Expand Up @@ -351,7 +357,7 @@ public SampleResult sample(Entry e) {
}
responseMessage = responseMessage.concat(ex.getMessage());
res.setResponseData(ex.getMessage(), "UTF-8");
} catch (FileNotFoundException | ClassCastException | JsonParseException ex){
} catch (FileNotFoundException | ClassCastException | JsonParseException ex) {
log.info("Error calling {} sampler. ", threadName, ex);
res.setResponseData(ex.getMessage(), "UTF-8");
responseMessage = responseMessage.concat(ex.getMessage());
Expand Down Expand Up @@ -417,4 +423,4 @@ private void trace(String s) {
this.getName(), s, this.toString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public AzServiceBusMessagesPanel() {
@Override
protected void initializeTableModel() {
tableModel = new ObjectTableModel(
new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CONTENT_TYPE"), COLUMN_NAMES.get("CUSTOM_PROPERTIES") },
new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CONTENT_TYPE"), COLUMN_NAMES.get("CUSTOM_PROPERTIES"), COLUMN_NAMES.get("LABEL") },
AzAmqpMessage.class,
new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getContentType"), new Functor("getCustomProperties") },
new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setContentType"), new Functor("setCustomProperties") },
new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class }
new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getContentType"), new Functor("getLabel"), new Functor("getCustomProperties") },
new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setContentType"), new Functor("setLabel"), new Functor("setCustomProperties") },
new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class }
);
}

}
}