The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »

Jmeter - JMS TEST PLAN


In this chapter, we will learn how to write a simple test plan to test Java Messaging Service (JMS). JMS supports two types of messaging:
  • Point-to-Point messaging: Queue messaging is generally used for transactions where the sender expects a response. Messaging systems are quite different from normal HTTP requests. In HTTP, a single user sends a request and gets a response.
  • Topic messaging: Topic messages are commonly known as pub/sub messaging. Topic messaging is generally used in cases where a message is published by a producer and consumed by multiple subscribers.
Let us see a test example for each of these. The pre-requisites for testing JMS are:
  • We use Apache ActiveMQ in the example. There are various JMS servers like IBM WebSphere MQ (formerly MQSeries), Tibco, etc. Download it from the binaries from the Apache ActiveMQ website.
  • Unzip the archive, go to the decompressed directory, and run the following command from the command console to start the ActiveMQ server:
.\bin\activemq start

You can verify if the ActiveMQ server has started by visiting the admin interface at the following address http://localhost:8161/admin/. If it asks for authentication, then enter the userid and password as admin. The screen is similar as shown below:

  • Now copy the activemq-all-x.x.x.jar (XXX depending on the version) from the ActiveMQ unzipped directory to /home/manisha/apache-jmeter-2.9/lib. With the above setup, let us build the test plan for:
  • JMS Point-to-Point Test Plan
  • JMS Topic Test Plan
Building a JMS Point-to-Point Test Plan

Now let us write a JMeter test plan to test a JMS Point-to-Point messaging solution. The setup of the test is one threadgroup with one thread or user sending 2 messages each through a request queue.

Let us start the JMeter from /home/manisha/apache-jmeter-2.9/bin/jmeter.sh.

Add Users

1. Create a Thread group.
2. Right-click the Test Plan node.
3. Select Add > Threads (Users) > Thread Group. Thread Group gets added under the Test Plan node.
4. Rename this Thread Group as JMSTestPlan-PointtoPoint.

We will change the Loop Count to two. Rest of the default properties of the Thread Group are retained. It means one thread group with one thread or one user sends two messages each through a request queue.

Add JMS Point-to-Point Sampler

Now that we have defined the users, it is time to define the tasks that they will be performing. Start by adding the sampler JMS Point-to-Point to the Point-to-Point element.
  • Select Add > Sampler > JMS Point-to-Point.
  • Select the JMS Point-to-Point sampler element in the tree.
The following property changes are made to the JMS Point-to-Point sampler element:

PropertyValueDescription
QueueuConnectionFactoryConnectionFactoryThis is the default JNDI entry for the connection factory within active MQ.
JNDI Name Request QueueQ.REQThe JNDI name for JMeter to make the connection between the connection factory and queue.
JNDI Name Receive QueueQ.REQThe JNDI name for JMeter to make the connection between the connection factory and queue. We are using the same queue for response.
Communication StyleRequest ResponseIt means you need at least a service running outside of JMeter, which will respond to the requests. This service must listen to the Request Queue and send messages to the queue referenced by the message.getJMSReplyTo()
Use Request message IDcheckedYou can leave JMeter to use the message ID Request (deposit) to the correlation between the incoming message and the recovered.
Use Response message IDcheckedYou can leave JMeter use the message identifier Response (recovery) for the correlation between the incoming message and recovered.
Time(milliseconds)2000This timeout is used when the message is received by JMeter if nothing is recovered in time (here 2 sec), then the item is marked in error.
ContentTesting point to pointThis is just the content of the message.
InitialContextFactoryorg.apache.activemq.jndi ActiveMQInitialContextFactoryThe standard InitialContextFactory for Active MQ
queue.Q.REQexample.ACorrespondence between the JNDI name of the queue (Q.REQ) and the real name of the queue in ActiveMQ (example.A).
Provider URLtcp://localhost:61616The address and port to attack ActiveMQ.
The following screenshot shows the above configurations:

Create Listener

Now add the Listener element. This element is responsible for storing all of the results of your JMS requests in a file and presenting a visual model of the data.

1. Select the Thread Group element.
2. Add a View Results Tree listener by selecting Add > Listener > View Results Tree.

Save and Execute the Test Plan

Now save the above test plan as jmsptp_test.jmx. Execute this test plan using Run > Start option.

Verify the Output

Return to the admin console of ActiveMQ. Here we can see the message status in the queue.

Building a JMS Topic Test Plan

Now let us write a JMeter test plan to test a JMS Provider. We will create one subscriber and one publisher. We will create one thread group and set each one to two iterations.

First let us start the JMeter from /home/manisha/apache-jmeter-2.9/bin/jmeter.sh.

Add Users

Now create a Thread group as follows:

1. Right-click the Test Plan
2. Select Add > Threads (Users) > Thread Group. Thread Group will get added under the Test Plan node.
3. Rename this Thread Group as JMS pub-sub user.

We will change the Loop Count to two. Rest of the default properties of the Thread Group are retained. It means one thread group with one thread or one user sends two messages each through a request queue.

Adding JMS Subscriber and Publisher

Let us see how to add subscribers and publishers:

Add Publisher

1. Add the sampler JMS Publisher to the Publisher element by selecting Add > Sampler > JMS Publisher.
2. Select the JMS Publisher element in the tree.
3. Edit the following properties:

PropertyValueDescription
NameSample PublisherDescriptive name for this element that is shown in the tree.
If the JMS provider uses the jndi.properties filecheck the boxUse jndi.properties. Note that the file must be on the classpath - e.g. by updating the user.classpath JMeter property. If this option is not selected, JMeter uses the "JNDI Initial Context Factory" and "Provider URL" fields to create the connection.
InitialContextFactoryorg apache activemq jndi Active MQInitial Context FactoryName of the context factory.
Provider URLtcp://localhost:61616The URL for the JMS provider.
Connection FactoryConnectionFactoryThe URL for the JMS provider.
DestinationdynamicTopics/MyStaticTopic1The name of the message topic. For ActiveMQ Dynamic Topics (create topics dynamically).
Number of samples to aggregate2Number of samples to aggregate.
Message sourceTextareaWhere to obtain the message: From File: means the referenced file will be read and reused by all samples. Random File from folder: means a random file will be selected from the folder specified, this folder must contain either files with extension .dat for Bytes Messages, or files with extension .txt or .obj for Object or Text messages Text area: The Message to use either for Text or Object message
Message typeTextText, Map, Object message or Bytes Message
Rest of the properties are retained with the default values. The following screenshot shows the above configurations:

Add Subscriber

Now that we have defined our users, it is time to define the tasks that they will be performing.

1. Add the sampler JMS Subscriber to the Subscribers element by selecting Add > Sampler > JMS Subscriber.
2. Select the JMS Subscriber element in the tree
3. Edit the following properties:

PropertyValueDescription
NameSample SubscriberDescriptive name for this element that is shown in the tree.
If the JMS provider uses the jndi.properties filecheck the boxUse jndi.properties. Note that the file must be on the classpath - e.g. by updating the user.classpath JMeter property. If this option is not selected, JMeter uses the "JNDI Initial Context Factory" and "Provider URL" fields to create the connection.
InitialContextFactoryorg apache activemq jndi Active MQInitial Context FactoryName of the context factory.
Provider URLtcp://localhost:61616The URL for the JMS provider.
Connection FactoryConnectionFactoryThe URL for the JMS provider.
DestinationdynamicTopics/MyStaticTopic1The name of the message topic. For ActiveMQ Dynamic Topics (create topics dynamically).
Read responseCheck BoxThe sampler should read the response. If not, only the response length is returned.
Timeout2000The timeout to be applied, in milliseconds. 0=none. This is the overall aggregate timeout, not per sample.
Rest of the properties are retained with the default values. The following screenshot shows the above configurations:

Create Listener

Now add the Listener element. This element is responsible for storing all the results of your JMS requests in a file and presenting a visual model of the data.

1. Select the Thread Group element.
2. Add a View Results Tree listener by selecting Add > Listener > View Results Tree.

Save and Execute the Test Plan

Now save the above test plan as jms_pub_sub.jmx. Execute this test plan using Run > Start option.

Verify the Output

Output for Publisher

Output for Subscriber

Return to the admin console of ActiveMQ. Here we can see the message status in the topics.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com