Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Monday, February 11, 2013

Another hint on how to read files with corrupted or unknown encoding

If you need to read a file the encoding of which you have no idea about, I recommend to use FireFox browser. Originally I faced a problem when tried to read sqlplus.exe output. Opening saved redirection with FireFox browser solved the problem.
So:
  1. Save your text to some file
  2. In command line type "firefox YOUR_FILE_NAME" or specify the path in browser's address bar using file:// URI 
Bowser automaticall detects the proper encoding and converts the text so that you can read it.
Such the approach does not require some special software installation like text-encoding converters etc.

Tuesday, November 20, 2012

How to prepare your Eclipse IDE for web development

Objective

Once you're going to start developing some java-based web-applications or just static web-sites you need to perform some simple steps to configure your development environment. Basically you need three things to start developing:
  1. Eclise IDE (J2EE edition)
  2. Tomcat server (Servlet container and servlet specification implementation)
  3. JDK to support basic java features along with runtime environment
Lets go step-by-step here. At the moment of this post publishing the latest version of Eclipse IDE was Juno release.  Download it from here so that you've got the version suitable for your operating system. I'm using Windows 7 64bit so all further statements will be related to it. 
That will be great to create some sandbox so that you can use it as isolated disk space to have some practice. After you're pretty much familiar with the configuration you can repeat the steps with your own paths. Say, create the following folder where all the magic is going to happen: c:/sandbox. Create Projects subfolder to keep Eclipse project there.

Configure your Eclipse and Tomcat instances

Extract the eclipse archive to c:/sandbox. So you now have your IDE under c:/sandbox/Eclipse. Start it up (lets not talk about performance tuning of your IDE - this is not our topic here). Set up the workspace to Now you have IDE working. Unfortunately that's not enough to start coding. Close welcome screen.
You won't be able to code a piece of java code until you have JDK installed. Follow this link to download J2SE 6 for your operating system (make sure you're registered as oracle user as you will have to input your oracle credentials).

Install the distribution to C:\sandbox\JDK_SE6. Switch to Eclipse.
  • Go to Window\Preferences
  • In the preferences tree go to Java\Installed JREs
  • Click [Add] button. Choose Standard VM in new dialog and click Next
  • Specify folder C:\sandbox\JDK_SE6 for JRE home. Once you do that all other fields are pre-filled automatically
  • Now you may remove all other VMs from the list if they are.
  • Click OK to close preferences dialog
You now can write and execute Java code. However we're going to create web application, aren't we? Hence we need to install servlet implementation. That's also good to have a web server. Fortunately all those stuff is combined under Apache Tomcat server. Lets use the latest version at the moment. You may take it from here. Unpack the content of the archive to our sandbox so that we have Apache Tomcat server under C:\sandbox\apache-tomcat-7.0.32.

Lets bind eclipse to that apache instance.
  • Go to Window\Preferences again. In preferences tree go to Server\Runtime Environments.
  • Click [Add...] button
  • In "New Server Runtime Environment" dialog choose Apache Tomcat v7.0. Check "Create a new local server" cehck-box. Click Next
  • Click [Browse...] button and choose the folder C:\sandbox\apache-tomcat-7.0.32
  • Under JRE you may choose either default JRE of workbench or JDK_SE6. They are all the same. However lets choose the second option to be more defined.
  • Click Finish and then OK to close preferences window.

Creating a template project.

Lets now create some project to get aware how to create the project each time you want to start trying new create something new.
  • In Eclipse press Ctrl+N so that "New" dialog is opened. 
  • Choose "Dynamic Web Project" and click Next
  • There type some project name (note that the project path is attached automatically to our sandbox)
  • Choose Apache Tomcat v7.0 as target runtime
  • Set dynamic web module version to 3.0
  • Click Next until it gets disabled :)
  • There check the check-box "Generate web.xml deployment descriptor"
  • Finally click [Finish]
So.. Congratulations! You've now got web project configured. To make sure it's working lets do the following.
  • In your Project Explorer expand WebContent folder
  • Right-click the folder and choose New->Html file
  • Name it index.html and click okay
  • Within <body>...</body> enclosure  add piece of html-code like <h1>It really works!</h1>. Save the changes
  • Right click the project root in project explorer. Select "Run as -> Run on Server"
  • You should now see your html page which was deployed to the web-server and now loaded from it
That's all

Wednesday, August 08, 2012

Performance testing of web application built over long-polling architecture

Check new series of the articles. Review and user experience on test management systems. Functionality and usability.
-------------------

It's not a rocket science how to perform load testing of regular web application. Basically you need to measure the time between you send the request to the server and the time the server responds. Much harder is to test so called long-polling architecture where it becomes not reasonable to measure respond-request time as the respond time depends on actually two points:

1. If the server has anything to say to your client it responds immediately
2. If not, it waits for the threashold and responds breaking the connection which is restored immediately so a kind of persistant channel occurs.

But wait. Does that mean we have no chance to consider the performance metrics to measure? Not actually.

See the model of long polling communication I've prepared for you. The strong horizontal line here means the layer responsible for long-polling communication between the client (uasually your web-browser) and the server.

Performance testing (aka load testing) of long-polling web architecture


(1) Client sends regular request to configure the server to know which information the client wants to recieve from the server.
(2) Client sends the request asking if the server has requested data to publish. This request should be configured to have appropriate awaiting interval (bigger than a Threshold)
(3) Server keeps the request while it has not data to publish. If the data is not ready in Threashold interval the server responds with corresponding message.
(4) Client gets the response and recreates the request (all those client requests compose a kind of persistent data channel).
(5) Once the data is ready the server respondes (6) to all the clients subscribed for it.

So what we need to know is how fast the client gets published data. To find that out we should measure the interval between (5) and (6).

But wait once again. The number of clients subscribed for certain data may be actually pretty big. Should we somehow consider this fact when measure the performance. Yep - we should. When the data is ready the server iterates though a pool of the subscribers and responds the corresponding requests. This means in such the case there will be a client which will get the respond later than others ones. Here we can consider two metrics of our application performance. They are:

1. Time interval between the data gets ready on the server and the fact of getting it by the first client
2. Time interval between the first and the last client gets the data

P.S. - Performance testing of long-polling architecture is not easy stuff. To perform it effectively you sould be absolutely sure you can control the data readiness and synchronize it with client requests.




Monday, August 06, 2012

Web Load Testing: When you can come up with single test user



All the measurements contain certain error. You will never get absolutely accurate value, so the only thing you can do with that is to accept that. 

When you perfrom load testing of your web aplpication it is usually strongly recommended to use different user for each thread and it is quite reasonable. However in some cases you may consider the results reliable even if you use single credential to login for several threads. So how do you know if you can manage with the single test user. First of all you should figure out what you want to measure and what technologies you use.

The generic problem of single credential implies the server performs some data processing once the user requests the server resources the first time and then uses pre-evaluated data not spending the time for other requests. This highly depends on the technologies you use, on whether they support caching or whether they are so called statefull. 

HTTP server is orginally stateless machine. That means that all the "state" matters are supported by injecting so called cookies into the client browser. All the tools for load testing support completely isolated sessions for each thread. That's why some of the functional areas can be loaded with the help of only one user.

The good examples are 
  • loading any static resource such as
    • web pages
    • files
    • other data streams
  • displaying the page with dynamic data not depending on the person looking at it
  • simple chat rooms (surprisingly)
  • authentication/authorization (again surprisingly). Even if your database caches requests you rather load HTTP server on authentication/authorization phase than a db server. So lot of threads will show you the problems (if they are) in your HTTP container configuration despite your db server will be still feeling okay.

All these points do not ensure your success but rather are aimed to make you focus your attention on whether the architecture of your application is suitable for testing with single credentials. Each application is unique so you are still responsible for decision.

Monday, June 04, 2012

How to easily load web page straight to the DOM

Very useful and light-weight package you may find here. It allows to wrap any html page from the server straight to DOM with no cost at all. Like this one:

org.jsoup.nodes.Document doc = Jsoup.connect("http://yourpage.own").get();

After that you may operate with doc like with just regular document. Another useful thing is locating element using css selector syntax. Here is the example from the official page

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");
Powerful tool with broad functionality which is better to get familiar with through the official page.