Category Archives: Software Engineering

Jmeter- Record and Play test cases

In my last post I talked about record part of test case in Jmeter.

Next step is to run the test cases, this is relevant even if you have created test cases manually. The first thing we need to add for any test plan is Thread Group.

Right Click on Test plan->Add-> Threads -> Thread Group

You can create test cases manually or record within Jmeter. A basic tool for providing the result data is Summary Report

Thread Group->Add-> Listener->Summary Report

There are additional reporting tools which can be used like Response Time Graph, Graph result etc.

By default the test will execute only once, but this is configurable in Thread Group properties.

Jmeter2

You can see I have set users, rampup and loop as 5.

Number of threads or user will simulate number of users hitting the application simultaneously.

Rampup period will give time it takes for the peak load. For example you have set number of user as 1000, and ramp up period as 100 seconds, Jmeter will start with 1 (or more) user at second one and will increase load gradually. At 100th second, load will get raised to 1000 users.

Loop 1 means that all users will hit the application URL only once. a higher value, say 10 means each user hits the application 10 times. so 1000 users with loop of 10 means a total of 10000 hits on URL.

Once the test completes, we can see results in Summary report or other graphs

Recording Test cases in Jmeter

Recording of web pages for performance testing is straight forward in Jmeter

Open a new Jmeter Test Plan (opens up by default for new setup), this will have Test Plan and WorkBench options by default in the left tree.

Follow these steps to setup the recording
Step 1: Right Click on Test plan->Add-> Threads -> Thread Group
Step 2: Thread Group->Add->Config Elements-> HTTP Request Defaults

Step 3: Now under Workbench-> Add-> Non Test Elements-> HTTP(S) Test Script Recorder
Step 4: (Optional to view requests) HTTP(S) Test Script Recorder -> Add Listener- > View Tree Listener

So far we have just added elements and not done any configuration setting. For recording purpose, we need to configure some values in HTTP(S) Test Script Recorder

jmeter

Port is required to be set to record the browser activity. HTTPS Domains setting is required if we are trying to record HTTPS pages, as I am not doing it here so this is left blank. URL patterns to include and exclude can be set for specific patterns to be recorded.

For this test I only set Port number. The same port number needs to be set in proxy setting for browser from which we are recording the test cases. Click on start button in Recorder and set the proxy setting in browser. For example, in Firefox go to Options->Advanced->Network->Connection-Settings->Manual Proxy Configuration->Http proxy= localhost and Port same as set in Recorder.

And now we are done. Whatever you will browse, will automatically get recorded in Jmeter.

Difference between web server and application server

We  use terms application server and web server interchangeably these days. Historically a web server was supposed to serve static html pages over http protocol. Then web servers started serving scripting languages like ASP, JSP, PHP etc. For complex application which needed services connection pooling, object pooling, messaging, transaction management were supposed to use application server.

I said historically because with time the distinguishing line has narrowed down. Most of the web servers have started providing features of application servers with plugins and add-ons. Some exmples of web servers- Apache HTTP (PHP), Tomcat (Servlet container, newer versions have EJB container) etc. Application server examples are JBoss, Websphere etc.

Complex Event Processing

Let’s start from understanding what is an event. The dictionary explains events as “a thing that happens, of importance”. Second part, i.e. “of importance” is a bit tricky, some events can be important for one but not for another. For example clicking anywhere on your computer screen is actually an event, but it does not result into an action, but clicking on some icon is event of importance as that will open up some application. In a banking system an event will be when someone withdraws money, checks balance, closes account or open account etc. In a computer game there will other type of event like, jump, run, hit, kill, fire etc.

Event processing is what should be done when the event occurs. For example, what to do when a specific icon on a window is clicked? What should be done when an event of withdraw money occurs – check if pin/ signature is correct, check if there is sufficient balance, pay money to person, reduce the amount from balance etc.

Now next level is to handle complex events. A complex event is an event which is result of many events occurring in relation to each other forming a definite pattern.

We are receiving following information from a ground
1. A man is kicking a football.
2. There are 2 goal posts set on opposite ends of ground.
3. There are few men in the ground trying to take control of same ball.

We can deduce a complex event – a football match.

This kind of pattern detection and complex event processing is used in Operational Intelligence solutions to identify opportunities and threats. For example banks use this kind of event processing to detect and take action on fraud detection. Say if a credit card transaction seems out of place, the amount deducted is not supported by historical data about the card usage, or the card is being used too frequently or the card is used at a location which is not in proximity of the consumer address, this kind of events, combination can generate an event for “CheckCreditCardFraud” or “StopPayment” or “RaiseAlert”.

Understanding Open/Closed Principle

Open closed principle is an important rule in software design, which we need to follow when designing a software system. It states “A Software code should be open for extension but closed for modification”.

What does that mean? Let’s take a very simple example from day to day life. We all use TV remotes. Say, we have created a very simple software code for remote operations like on/ off, vol increase/ decrease, channel change etc. Now what should be my design considerations

1. Any one should be able to extend the code to add new functionality, for example, for advanced TV’s one should be able to add functionality for subtitle language selection, operator specific options etc.
2. At the same time I need to make sure that no one should be able to alter existing core functionality like vol increase/ decrease, so that it does not break down the functions which are working fine perfectly.

Point 1 is what we say open for extension and point 2 states closed for modification principle. The open/ closed principle helps maintainability of code perfectly, by making sure we do not break what is working fine with flexibility of adding new features at the same time.

What is Middleware?

If you look around for the term Middleware, you will see it being used widely but unfortunately not explained properly anywhere. What is middleware? If you are working on simple web applications, the possibility is that you have mostly worked on client-server paradigm without worrying about middleware concepts. Middleware genrally comes into picture when we are dealing with multiple(atleast 2) applications. It helps these applications talk to each other, even if these applications are on different platforms, technologies and servers.

How does Middleware do it? Lets take a simple example. We have a college A, which has an inhouse application (colA app), used to track students data, attendence, results etc. Now there is an internet application which is supposed to display results of students online (result.com). Now result.com app needs to communicate to colA app to fetch student result data. We introduce a middleware application which helps these 2 app communicate. Let’s say this is message oriented middleware, so as soon as a new result is available on colA app, it writes it on a queue of middleware app. Now middleware might do some processing on the data if required and add it to another queue, which is listened to by result app.

Why can’t result app directly talk to colA app? It can, but what will happen if complexity increases and we introduce many new applications into the arena. Say we have hundereds of colleges and tens of result apps. And to complicate it further, college apps also need to communicate to each other. Just imagine the comexity that each app is listening to tens of other apps and fetching data from tens of apps. Each app need to worry about security, concurrency, connectivity, handling so much load. Different apps might be using different technologies to make the communication difficult. With introduction of middleware, we are moving all the complexity out of the apps so that they can focus on their core areas and let middleware worry about handling load, setting up clustors, managing security, dealing with different technologies and platforms.

Middleware

Web Service vs Web Application

There are times when I get confused if a web application is sufficient to solve a problem or I should be creating a web service. So I tried to get into depth of the two approaches.

What is a web application? web + application. A software application is something that is helping a user to achieve some specific goal, like MS Word, Calculator, Email Client etc. A web application, similarly, is an application which is available over a network or internet, it might be online banking application, some e-commerce application etc.

What is a web service? A service is similar to application in a sense that it is achieving a goal, but instead of being independent application, a service is providing inputs to some other application. For example, a service to add up two numbers, will take 2 numbers from a calculator app, add up two numbers, and return back to the calling applications.

Now how to take up the question if I should be creating a web application for a particular problem or web service. Let’s go back to calculator app, which needs a functionality to add 2 numbers. Web application approach will be to implement the add function inside the app, which is good enough if I know that this function is to be used only with this app. Web service approach will need the sum service to be independent of any application. This gives advantage that the same service can be used by multiple applications, this includes web apps, mobile apps or desktop apps as they will just need to connect to network and call the service to fulfill a requirement.

Above, we have defined web app and web service from a functional aspect. Technically, web service is a specialized web application only. A rule of thumb states that if your requirements want a user interface, you will need a web application implementation, but if your requirement does not need a interface but will return only some data, a web service is a good fit.