Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Automate queue creation and fix for reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
hasithajayasundara committed Jul 18, 2018
1 parent e76dffa commit 2976c8b
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 43 deletions.
17 changes: 9 additions & 8 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This tool allows ballerina message broker developers to get an idea about the pe
- Connection Load - The number of message producers , or the number of concurrent connections a system can support.
- Message throughput - The number of messages or message bytes that can be pumped through a messaging system per second.

At the moment the tool allows developers to publish/consume messages to/from queues and topics and test the performance and get a report of the result.
The tool allows developers to publish/consume messages to/from queues and topics and test the performance and get a report of the result.

# How to use

Expand All @@ -23,6 +23,7 @@ At the moment the tool allows developers to publish/consume messages to/from que

1. Include the following details in broker_performance_test_publisher.properties file which is located at resources/.
```properties
broker_url=<broker_url>
jmeter_home = <jmeter_home>
thread_count = <number_of_threads>
message_size = <size_of_the_message>
Expand All @@ -31,19 +32,23 @@ throughput= <throughput_need_to_be_maintained>
```
2.Run ```./broker_test_publisher.sh -p <location_of_properties_file> -d queue/topic```

Upon completion of the test,you will be directed to a web interface which contains the summary of the results obtained by the test.
- -p is an optional paramter.If not provided ```resources/broker_test_publisher.properties``` is set as the properties file location

Upon completion of the test, you will be directed to a web interface which contains the summary of the results obtained by the test.

### Consume messages from queues/topics

1. Include the following details in broker_performance_test_consumer.properties file which is located at resources/.
```properties
jmeter_home = <jmeter_home>
thread_count = <number_of_threads>
number_of_messages = <number_of_messages_need_to_be_published>
number_of_messages = <number_of_messages_need_to_be_consumed>
```
2.Run ```./broker_test_consumer.sh -p <location_of_properties_file> -d queue/topic```

Upon completion of the test,you will be directed to a web interface which contains the summary of the results obtained by the test.
- -p is an optional paramter.If not provided ```resources/broker_test_consumer.properties``` is set as the properties file location

Upon completion of the test, you will be directed to a web interface which contains the summary of the results obtained by the test.

### Test scenario - Publish messages to queues/topics and consume them

Expand Down Expand Up @@ -77,7 +82,3 @@ number_of_messages = <number_of_messages_need_to_be_published>
- message_size = 10
- number_of_messages = 1000000
- throughput = 5000 (5000 messages/seconds)




71 changes: 58 additions & 13 deletions tools/scripts/broker_test_consumer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jmx_file_location="test_plan/broker_test_queue_consumer.jmx"
destination=""
connection_factory_name=""
jndi_file_location=""
is_given_destination=false
queue_name=""
exchange_name=""

# get inputs from the user -p <location of the properties file> -d topic/queue
while getopts "hp:d:t:h:v" OPTION
Expand All @@ -36,16 +39,22 @@ do
d)
case $OPTARG in
queue)
is_given_destination=true
destination="QueueName"
connection_factory_name="QueueConnectionFactory"
jndi_file_location="resources/jndi_queue.properties"
jmx_file_location="test_plan/broker_test_queue_consumer.jmx"
queue_name="micro_benchmark_queue1"
exchange_name="amq.direct"
;;
topic)
is_given_destination=true
destination="TopicName"
connection_factory_name="TopicConnectionFactory"
jndi_file_location="resources/jndi_topic.properties"
jmx_file_location="test_plan/broker_test_topic_consumer.jmx"
queue_name="micro_benchmark_queue2"
exchange_name="amq.topic"
;;
?)
echo $OPTARG
Expand All @@ -67,14 +76,11 @@ do
esac
done

# check for target folder
if [ ! -e target/ ];
then
mkdir -p target/subscriber
fi

# hash-map to store user desired parameters
declare -A user_inputs=(["jmeter_home"]="" ["thread_count"]="1" ["number_of_messages"]="1000000")
if [ $is_given_destination == false ];
then
printf 'A JMS destination should be provided.\nRun ./broker_test_consumer.sh -h for usage.\n'
exit
fi

# Method to extract values from property file
getProperty()
Expand All @@ -84,6 +90,9 @@ getProperty()
echo "$user_value"
}

# hash-map to store user desired parameters
declare -A user_inputs=(["jmeter_home"]="" ["broker_url"]="" ["thread_count"]="1" ["number_of_messages"]="1000000")

for parameter in "${!user_inputs[@]}";
do
value=$(getProperty $parameter)
Expand All @@ -94,19 +103,55 @@ do
done

# validate inputs
if [ ${user_inputs["thread_count"]} == '0' ]
if [${user_inputs["broker_url"]} == '']
then
# Command invoked cannot execute
echo Thread count cannot be zero
echo "broker_url parameter in broker_test_consumer.properties cannot be empty."
exit
elif [ ${user_inputs["thread_count"]} == '0' ]
then
echo "thread_count parameter in broker_test_consumer.properties cannot be empty."
exit
fi

# create target folder if not exist
if [ ! -e target/ ];
then
mkdir -p target/subscriber
fi

# create queues and bindings to execute tests
queue_available_response=$(curl -k -u admin:admin -o /dev/null -s -w "%{http_code}\n" ${user_inputs["broker_url"]}/broker/v1.0/queues/"$queue_name")
# if queue is not available create queue
if [ "$queue_available_response" == 404 ]
then
json_payload='{"name":"'"$queue_name"'", "durable":"true","autoDelete":"true"}'
queue_create_response=$(curl -k -u admin:admin -o /dev/null -s -w "%{http_code}\n" -d "$json_payload" -H "Content-Type: application/json" -X POST ${user_inputs["broker_url"]}/broker/v1.0/queues)
if [ "$queue_create_response" == "201" ]
then
echo $queue_name created sucessfully.
json_payload='{"bindingPattern":"'"$queue_name"'","exchangeName":"'"$exchange_name"'","filterExpression":""}'
queue_bind_response=$(curl -k -u admin:admin -o /dev/null -s -w "%{http_code}\n" -d "$json_payload" -H "Content-Type: application/json" -X POST ${user_inputs["broker_url"]}/broker/v1.0/queues/"$queue_name"/bindings)
if [ "$queue_bind_response" == "201" ]
then
echo "Binding created sucessfully with $queue_name.Exchange name - $exchange_name"
else
echo "Error occured while creating binding.Response code $queue_bind_response"
exit
fi
else
echo "Error occured while creating queue $queue_name.Response code $queue_create_response"
exit
fi
else
echo "$queue_name is already available."
fi

# Summarizing inputs
echo Jmeter home is set to - ${user_inputs["jmeter_home"]}
echo Starting test process with a throughput - ${user_inputs["throughput"]}

# calculate loop count
loop_count=$(echo "${user_inputs["number_of_messages"]}/${user_inputs["thread_count"]}+1" | bc)
loop_count=$(echo "${user_inputs["number_of_messages"]}/${user_inputs["thread_count"]}" | bc)

# create folder to store report files
folder_name=$(date '+%d-%m-%Y-%H-%M-%S')
Expand All @@ -130,4 +175,4 @@ if [ ${user_inputs["jmeter_home"]} != '' ]
fi

# open report
firefox target/subscriber/"$folder_name"/report/index.html
echo A report of the test results is generated at target/publisher/"$folder_name"/report
86 changes: 71 additions & 15 deletions tools/scripts/broker_test_publisher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jmx_file_location="test_plan/broker_test_publisher.jmx"
destination=""
connection_factory_name=""
jndi_file_location=""
is_given_destination=false
queue_name=""
exchange_name=""

# get inputs from the user -p <location of the properties file> -d topic/queue
while getopts "hp:d:t:h:v" OPTION
Expand All @@ -36,14 +39,20 @@ do
d)
case $OPTARG in
queue)
is_given_destination=true
destination="QueueName"
connection_factory_name="QueueConnectionFactory"
jndi_file_location="resources/jndi_queue.properties"
queue_name="micro_benchmark_queue1"
exchange_name="amq.direct"
;;
topic)
is_given_destination=true
destination="TopicName"
connection_factory_name="TopicConnectionFactory"
jndi_file_location="resources/jndi_topic.properties"
queue_name="micro_benchmark_queue2"
exchange_name="amq.topic"
;;
?)
echo $OPTARG
Expand All @@ -65,14 +74,11 @@ do
esac
done

# check for target folder
if [ ! -e target/ ];
then
mkdir -p target/publisher
fi

# hash-map to store user desired parameters
declare -A user_inputs=(["jmeter_home"]="" ["thread_count"]="1" ["number_of_messages"]="1000000" ["throughput"]="5000" ["message_size"]="10KB")
if [ $is_given_destination == false ];
then
printf 'A JMS destination should be provided.\nRun ./broker_test_publisher.sh -h for usage.\n'
exit
fi

# Method to extract values from property file
getProperty()
Expand All @@ -82,6 +88,9 @@ getProperty()
echo "$user_value"
}

# hash-map to store user desired parameters
declare -A user_inputs=(["jmeter_home"]="" ["broker_url"]="" ["thread_count"]="1" ["number_of_messages"]="1000000" ["throughput"]="5000" ["message_size"]="10KB")

for parameter in "${!user_inputs[@]}";
do
value=$(getProperty $parameter)
Expand All @@ -92,24 +101,67 @@ do
done

# validate inputs
if [ ${user_inputs["thread_count"]} == '0' ] || [ ${user_inputs["throughput"]} == '0' ]
if [ ${user_inputs["broker_url"]} == '' ]
then
# Command invoked cannot execute
echo Thread count and/or throughput cannot be zero
echo "broker_url parameter in broker_test_publisher.properties cannot be empty."
exit
elif [ ${user_inputs["thread_count"]} == '0' ]
then
echo "thread_count parameter in broker_test_publisher.properties cannot be empty."
exit
elif [ ${user_inputs["throughput"]} == '0' ]
then
echo "throughput parameter in broker_test_publisher.properties cannot be empty."
exit
fi

# create target folder if not exist
if [ ! -e target/ ];
then
mkdir -p target/publisher
fi

# create queues and bindings to execute tests
queue_available_response=$(curl -k -u admin:admin -o /dev/null -s -w "%{http_code}\n" ${user_inputs["broker_url"]}/broker/v1.0/queues/"$queue_name")
# if queue is not available create queue
if [ "$queue_available_response" == 404 ]
then
json_payload='{"name":"'"$queue_name"'", "durable":"true","autoDelete":"true"}'
queue_create_response=$(curl -k -u admin:admin -o /dev/null -s -w "%{http_code}\n" -d "$json_payload" -H "Content-Type: application/json" -X POST ${user_inputs["broker_url"]}/broker/v1.0/queues)
if [ "$queue_create_response" == "201" ]
then
echo $queue_name created sucessfully.
json_payload='{"bindingPattern":"'"$queue_name"'","exchangeName":"'"$exchange_name"'","filterExpression":""}'
queue_bind_response=$(curl -k -u admin:admin -o /dev/null -s -w "%{http_code}\n" -d "$json_payload" -H "Content-Type: application/json" -X POST ${user_inputs["broker_url"]}/broker/v1.0/queues/"$queue_name"/bindings)
if [ "$queue_bind_response" == "201" ]
then
echo "Binding created sucessfully with $queue_name.Exchange name - $exchange_name"
else
echo "Error occured while creating binding.Response code $queue_bind_response"
exit
fi
else
echo "Error occured while creating queue $queue_name.Response code $queue_create_response"
exit
fi
else
echo "$queue_name is already available."
fi

# Summarizing inputs
echo Jmeter home is set to - ${user_inputs["jmeter_home"]}
echo Starting test process with ${user_inputs["number_of_messages"]} messages and a and throughput - ${user_inputs["throughput"]}

# calculate loop count
loop_count=$(echo "${user_inputs["number_of_messages"]}/${user_inputs["thread_count"]}+1" | bc)
loop_count=$(echo "${user_inputs["number_of_messages"]}/${user_inputs["thread_count"]}" | bc)
duration_of_the_test=$(echo "${user_inputs["number_of_messages"]}/${user_inputs["throughput"]}" | bc)

# variable to store message math
text_message_file_location="sample_messages/1kB.json"
text_message_file_location=""
case ${user_inputs["message_size"]} in
1KB)
text_message_file_location="sample_messages/1kB.json"
;;
10KB)
text_message_file_location="sample_messages/10kB.json"
;;
Expand All @@ -119,6 +171,10 @@ case ${user_inputs["message_size"]} in
1MB)
text_message_file_location="sample_messages/1MB.json"
;;
?)
echo message_size parameter should be one of 1KB,10KB,100KB and 1MB
exit
;;
esac

# create folder to store report files
Expand All @@ -142,5 +198,5 @@ if [ ${user_inputs["jmeter_home"]} != '' ]
fi
fi

# open report
firefox target/publisher/"$folder_name"/report/index.html
# log report location
echo A report of the test results is generated at target/publisher/"$folder_name"/report
12 changes: 11 additions & 1 deletion tools/scripts/broker_test_scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#!/usr/bin/env bash

destination=""
is_given_destination=false

# get inputs from the user -p <location of the properties file> -d topic/queue
while getopts "hp:d:t:h:v" OPTION
Expand All @@ -25,10 +26,12 @@ do
d)
case $OPTARG in
queue)
is_given_destination=true
destination="queue"
;;
topic)
destination="topic"
is_given_destination=true
destination="topic"
;;
?)
echo $OPTARG
Expand All @@ -50,6 +53,13 @@ do
esac
done


if [ $is_given_destination == false ];
then
printf 'A JMS destination should be provided.\nRun ./broker_test_scenario.sh -h for usage.\n'
exit
fi

# execute publisher and consumer at the same time
./broker_test_consumer.sh -d "$destination" &
sleep 2
Expand Down
5 changes: 3 additions & 2 deletions tools/scripts/resources/broker_test_consumer.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jmeter_home=<jmeter_home>
broker_url=<broker_url>
jmeter_home=<jmeter_home>\
thread_count=1
number_of_messages=500000
number_of_messages=1000000
1 change: 1 addition & 0 deletions tools/scripts/resources/broker_test_publisher.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
broker_url=<broker_url>
jmeter_home=<jmeter_home>
thread_count=1
number_of_messages=1000000
Expand Down
4 changes: 2 additions & 2 deletions tools/scripts/resources/jndi_queue.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.QueueConnectionFactory =amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'
connectionfactory.QueueConnectionFactory=amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.QueueName = micro_benchmark_queue1
queue.QueueName=micro_benchmark_queue1

Loading

0 comments on commit 2976c8b

Please sign in to comment.