Wednesday, 3 July 2013

Random string creation in Jmeter using BeanShell Preprocessor


If anyone wants to create a random string in Jmeter and use it for some purpose in your code , you can do that using the BeanShell Preprocessor .

The below code snippet can be used to generate a random string using BeanShell Preprocessor.

import java.util.Random; 

chars = "1234567890abcdefghiklmnopqrstuvwxyz-"; 
int string_length = 36; 
randomstring =""; 
    for (int i=0; i<string_length; i++) { 
        Random randomGenerator = new Random(); 
      int randomInt = randomGenerator.nextInt(chars.length()); 
        randomstring += chars.substring(randomInt,randomInt+1);
    } 

vars.put("VAR_NAME",randomstring); 


Place the random string into a variable of your choice by replacing the VAR_NAME with you variable name.

Friday, 26 April 2013

Context of the knowledge?


Yes. All knowledge has its context. Unless you know the context, you may not understand the point.“

While reading one of the latest sensations from “Amish Tripathi”, I have encountered a couple of statements that struck me hard. Below are the highlighted extracts from his sayings and my testing implications toward those.

“Any philosophy, no matter how perfect, works only for a finite period. That is the law of nature and cannot be avoided.”

The famous people know this one long ago, but most of the testing organizations still fail to understand this .The philosophy what these testing organizations are following now is no more “PERFECT”, or not even near to perfection.  The time has come to refine the craft and the testing guru’s like “James Bach” are doing that. Wake Up; it’s time to unlearn few things and learn the new that suits the “Context”.

“There are two situations in which ‘change’ can lead to chaos. First, when people face a change by others, situations that they cannot understand.”

‘Yes, change forced by others is difficult to accept.’ But try to think and analyze the context on how relevant are the ideas you are following.

“Second, when change happens too fast, they resist it.”

Yes, agreed. But this happens only when you realize that all the industry is moving towards new ways of testing and you want to suddenly bring in the complete change. At least start learning the new philosophy in the testing craft and use it when the situation demands.

Thursday, 11 April 2013

Tool : CorkScrew


In one of the test assignment it is required for me to connect to machines that are on external network outside the firewall. The firewall settings are not allowing me to do ssh to the external machines . 

Here is the solution for you , if you in this situation. Please do ask your authorities if your are allowed to connect to the machines in the manner . 

There is a tool named "CorkScrew" which you can use , this will 'tunnel SSH over an HTTP-Proxy Server'.
The detailed explanation on how to build and execute can be found in the following link. 

http://www.mtu.net/~engstrom/ssh-proxy.php



Thursday, 4 April 2013

Testing by Denmark Police !!


Due to the long-weekend during Easter time I had planned to go to Amsterdam, Netherlands with my friend in his car. The route which we choose while coming back is Netherlands --> Germany --> Denmark --> Sweden . 

On the return trip when we entered from Germany to Denmark , police stopped us in Denmark border and asked our identity. The problem started when we answered that we are coming from Amsterdam !! 

For those who or not aware , "Drugs" in Amsterdam are legal . But its illegal in Denmark .

Now the mission is ready for the police officer

Mission #  To search us and see if he can find some drugs. ( If he finds something then he may get a promotion ;) .. Just kidding )

I was very keen to see how he can accomplish his mission. This is how he unfolded the machine .

He asked us to drive into a big room along with the car.I guess this room is fixed with some sensors to find if we are carrying any guns.Then asked only one person to get down from the car and started asking questions.During this time the other police officer was observing me from a distance to see if behave in a different way or try to hide something .

This triggered a new test idea in me . Say if we are testing two modules which are closely associated, while testing one module rigorous we can ask the fellow tester to look at the other module how it is behaving . 
Wow we can learn testing from cops as well :-) .

Back to mission , he started asking questions to my friend on different things so that he can get some clue .

Questions:

1. To show the passport and residence card ?
2. Since when he is staying in this country and from which country he came ?
3. To which company we working for ?
4. What is the purpose of the visit and since how long he will be staying here ?

He is trying to get more and more information to understand the situation find any clues for further investigation.

Now he asked my friend to empty all his pockets and keep the things on the table for checking. Asked him to remove the jacket and searched it completely .Then asked him to sit in a room and closed the door . 

Now its my turn to get down from the car and the whole procedure is repeated !! 
One thing of interest here is , we both are not put into the same room . We are placed in two different rooms from where we cant talk to each other. 

This is triggering a new test idea in me again , Say if you think that the two inter-related modules are tested rigorous hold on for a minute before you test the communication between these two modules.  If you find a bug in the other related module module ( I mean if he finds the drugs in the car ) , then he can investigate that bug  to see if it has any relationship with two tested modules above. 

During this time the police office searched the whole car manually . I guess he is not satisfied with that , now he wants some tool which can help him to find the bugs ( I mean drugs ). They called the police dog and put that smart dog into the car and directed it to smell all the places in the car.

Now he approached to the end of the mission and didn't find any drugs . Police officer asked us to take all our belongings and go on our way and wished us Happy Journey too :) .

But what I learnt from all this is below . He applied all these testing skills

1. His mission was very clear .
2. Unfolded the mission and clearly segregated it into smaller segments.
3. Questioning , to gain more understanding on the situation and find any clue for further investigation.
4. Carefully covered one by one aspect rather than making all at once and get confused on the coverage .
5. Manually searched almost all possible aspects .
6. Used an appropriate tools for this situation like , sensor fitted room and the 'dog' that can aid him in his   search .

Last but not the least , finally he took the photocopy of our identities before they let us go !! 

Thursday, 14 March 2013

How to get jpeg file size in JMeter ?

Guys have you ever tried to get the size of the "jpeg file" and pass it in a sampler ?
 Below is the function which you can use in Jmeter to get the size of the jpeg file .

${__eval(${__strLen(${__FileToString(${FILE_PATH},,)},length)})}

FILE_PATH : Replace this variable with your jpeg file location. 


Tuesday, 22 January 2013

Database performance testing using JMeter

In this post we will see how we can build a test plan and run load test on databases using JMeter. We will consider MySQL database for our discussion. In order to test the SQL Query performance using JMeter, first you should be aware of the below concepts and terminologies.

A . JDBC Driver :

JDBC driver is a software component enabling a Java application to interact with a database. JDBC drivers are analogous to ODBC drivers, ADO.NET data providers, and OLE DB providers. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. 


 

B. JDBC Request Sampler in JMeter : 

This sampler lets you send an SQL query to the database using JDBC server . 

C . JDBC Connection Configuration ( Config Element ) :

This helps us to create a database connection from the supplied JDBC Connection settings .

Scenario : Load Testing an SQL query on MySQL Database


In order to establish a connection from JMeter to MySQL database , you should download the proper JDBC Driver that connects to your database .You can download the JDBC Driver for MySQL from the below link

http://dev.mysql.com/downloads/connector/j/

Note : The downloaded "jar" file should be placed under the JMeter/lib directory .
The classes from jars are automatically found by the Jmeter in the following directories:

JMETER_HOME/lib - used for utility jars

Note: Only .jar files are found by JMeter not the .zip files.

Now you can start the JMeter and you are ready to build the DB test plan.

Step 1 :

Add the thread group and provide the appropriate name to it . In this case we have given it as DB Test plan .



Step 2 : 

Add the JDBC Connection configuration element and provide the appropriate JDBC connection settings relevant to your database.






You have to carefully fill the fields listed below and for the remaining you can use the default values.( In this case we have used the MySQL database installed in the local machine and the database name is given as “Test”).
Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used.
  • Database URL: jdbc:mysql://localhost:3306/Test 
  • JDBC Driver class: com.mysql.jdbc.Driver 
  • Username: Suman 
  • Password: **** 

Step 3 :

Add the JDBC Sampler which lets you send the SQL request to the server.







We have given an ‘insert’ statement and the query type as ‘Update statement’.

Note : The same variable name which we have used ( in the Variable name field ) in the JDBC Config elment should be used in the sampler as well.


Step 4 :

Add the listeners required as per your requirement.




Now the test plan is ready for you to perform SQL query performance testing on MySQL.


Frequent error you may get while execution and their resolution:


1. Response code: 080010

Response message: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/sakila

This error may occur if there is any mistake in the Database URL field. This may occur even if there is a “leading space” in the Database URL Field. Another reason would be, the database driver is not present in the JMeter Lib directory .


2. Response code: 42000 1049

Response message: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'sakil'

This message is self-exploratory; if the database name is incorrect or the database is not created you may encounter the above error.

3. Response code: 28000 1045

Response message: java.sql.SQLException: Access denied for user 'sumana'@'localhost' (using password: YES)

Even the above error message is self-exploratory; If the database access credentials are not correct then you may receive this error.


Hope this post is useful .