Friday, February 14, 2014

PostgreSQL or MongoDB?

In recent weeks has been revived the battle between MongoDB and PostgreSQL users in what is the best DB, and above all in the address that "MongoDB ends up being a bad choice and that it is best to never use it" and developers using MongoDB defend it saying that "PostgreSQL with a huge demand the performance is not optimal and MongoDB is made to have a highly performance and to be highly scalable, but what has happened is that you have not known how well use it".

And is that we, human beings, often see us involved in this situation that describes the history of india "Blind Men and an Elephant", here is the version of the poet John Godfrey Saxe, due to the inability of we have to know the totality of reality.

But who is right?

The answer to this question is all and none (I hope you have read the illustration above), for someone a personal subjective experience may be true, but this experience can enter into contradiction with the experiences of someone else or the whole truth at a broader level.

Ok, but leaving aside the phenomenological part of the subject, which then is best MongoDB or PostgreSQL?

This is not about which is better, is which fits best to the needs. You have to choose the correct tool, lets see this with more detail:

PostgreSQL is based on relational data storage model, being its main feature to maintain the integrity and consistency of the data. Using a normalized scheme minimizes the redesign of structure when you extend the data base and avoid anomalies during modifications in the database. The developer don´t worry about the integrity of the information since PostgreSQL is responsible for that but this have an impact on performance.

MongoDB is based on the non-relational storage model, the information is stored in documents and it is not necessary to follow a scheme. Its purpose is to provide great scalability and performance while maintaining most of the functionality of a RDBMS.

In Mongo there is no joins becuase is the operation that more impact has on the performance, for this you embed data, the information gets into the same document. If you need to have several collections of data the join must be implemented and it is the duty of the developer update all collections when there is a change.

There are no constraints or transaction, only atomic operations, so you get a great freedom to adjust the database to the application but is your responsibility maintain the integrity and consistency of the data. With this properties Mongo is really good to make ad-hoc querys and get a high performance.



If I need the features of both, can I use together?

Yes! you can use a master/slave replication, PostgreSQL as database master responsible for the integrity of the data and receive write operations and MongoDB as a slave so most of read operations are carried out there. To implement this configuration you can use tools like Bucardo replication.

Remember to choose the configuration database that best fits the needs of your application.

Saturday, December 21, 2013

Happy hollidays!

The xik´ team wants to wish to our clients a merry christmas and a happy 2014!

Thank you for your trust in our company and for choosing Xik´ to build your Web applications.

Friday, December 20, 2013

Use Hudson to schedule a daily execution of Ant (therefore your test cases)

Welcome to the forth and last post about this subject. Today the Hudson settings will be done, this will allow to run the Ant Script that was done on the previous post.

First you have to install Hudson, to install it,  go where the downloaded Hudson file is, and write the following command:


Java –jar hudson-3.1.1.war --httpPort=8989


--httpPort=8989 means the Port where you want  to install Hudson.  When the Hudson setting-up is completed, go to http://localhost:8989/  there you will be able to meet the Hudson UI.


Now you have to configure Hudson, click on Configure System, and then configure the JDK  and Ant sections. You need to tell Hudson where Ant and JDK are installed.



After this you can select Create New Job and then put a name to your new Job,in this example we named "prueba".


Then, you have to go to the Build section, click in Invoke Build->Step->Invoke Ant,  make sure that on Ant Version the Ant_Default is selected. 

Now, on Targets  write the first target that will be called on the Ant Sripts.

Finally, on Build File write the address where your Ant Script is.


Hudson allows you to Schedule the execution of our script, to do this, go to the Build Triggers section and select the Build periodically option.


To select which day and time we want to execute our script, we used the following format:

Minute Hour Day Month
Minute -> (0 – 59)
Hour -> (0 – 23)
Day -> (1 - 31)
Month -> (1 – 12)

For example if you want to execute our script on December 18 at 9:30 PM you have to write:

30 21 18 12 *

Now you can execute the script, to finish click on the Build now option and you should see the Hudson console.



Congratiolations! You have now an automated testing system to be sure that your system will remain stable in the case of continuous integration.

Run your test cases using Ant.

Welcome to the third post of this subject. In the previous post, we did two test cases  using Eclipse and Selenium WebDriver. In this post we will  make an ANT script  to run the test cases.

Please notice that if you don´t need to run your test automatically in a scheduled way, you might just write the tests using Selenium WebDriver and use just the JUnit´s UI available in Eclipse or Netbeans. 

Now, if you need to automate the daily execution of the test cases you probably want to read the rest of the post :)

First you have to have Apache-Ant 1.9.2, once you have downloaded you have to set your System environment variables: a PATH and a CLASSPATH variable in which you are going to write the apache ant 1.9.2\bin address.


You have to copy the file JUnit.jar in the apache-ant-1.9.2/lib folder. The file JUnit.jar is in eclipse\plugins\org.junit_4.11.0.v201303080030\junit.jar.



To create the script in Ant you have to go to eclipse File->New-> other, this will show you the following window:


Click on the next button, you will give the name of build.xml to your file and put it in src.


To create the script in ant, you have to be sure to add the file junit.jar to the script. This file was added in apache-ant-1.9.2/lib and you also have to be able to add the files .jar of selenium, here you have the directions to do it:


   
     
       
     




Ant allows you to run your test and generate a report in HTML, a very common problem is that when you run the script and you have to generate the report you will see the next error:

BUILD FAILED
Errors while applying transformations: Fatal error during transformation

This error is because of eclipse that is using the Default of ant. To solve it you have to go to Window->Preferences and the following window will appear:


Go to Ant and select RunTime option.


Click on Ant Home and select apache-ant-1.9.2 folder.


You have to make sure that the Ant Home Entries are not as Default and contains the apache-ant-1.9.2 folder address.


Now you can do the Ant script, the next code is the script to execute the test that had been made in the previous post; this script also generates a html report of our tests.
  


  
  
  
  

 
   
   
     
   
   
 

 
  
  
 

 
    
    
    
 

 
   
     
   
 

 
    
     
     
       
   
   
     
       
     
     
   
   

  
    Main target
  

The report can be found in src->reports->html folder.


If you open the report (index.html) it should look like this:


I the next post we will use Hudson to do a scheduled execution of the ANT script.

See you there!


Develop test cases using the Selenium WebDriver

Welcome back!  Today we will make some tests using Selenium WebDriver. All you need is to download Eclipse IDE For Java EE Developers and Selenium from our previous post. 

First step: Installation and configuration

Once you have downloaded Selenium you have to decompress the downloaded file.  You will find two different files .jar with the name of selenium -java-2.35.0.jar and selenium-java-2.35.0-srcs.jar. The name can change depending of the downloaded version of the tools, these files have to be copied on the libs folder of selenium.




Now that you have copied the files in the libs folder, you can create a new project in eclipse in which you can make some basic tests with the help of selenium. First you go to eclipse then you go to File->New->Java Project.


The next window will be displayed. Here you are going to write the project’s name. In this example the name of the project is “Tests”.




Then, you click on the Next button and you go to libraries.



You will see the next window, here you click on the button that says Add External JARs, a window will appear in which you have to select all the files .jar that are in the libs folder of selenium.


Once you have selected all the .jar files of selenium, you have to click on the finish button. The new project will appear at the left side of the screen.  In the left side of the screen you will find a section that says Referenced Libraries that contains all the files that you have selected previously.



The configuration is done :)  

We can start to write the tests, hooray!


Second step: Writing the test cases

Now we will do two simple tests:

  • search a text in google 
  • obtain the title of the Google page.



To do the tests go to File->New->JUnit Test Case.


You will see a new window in which you will have to write the name of the JUnit Test Case, in this case the name is “prueba” (it means test in our native language ;) ).


Once you have created the file, you will be able to make the test, first you create the test that opens firefox, goes to the google page and search ‘Selenium WebDriver’. To do this you have to import the following libraries:

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

To do the test you can use the following code, this test after searching  ‘selenium WebDriver’ obtains the title of the page and compare if the title of the page isSelenium WebDriver - Buscar con Google’, if the title is different the test will fail:

@Test
 public void test() throws InterruptedException {
  WebDriver firefox_driver = new FirefoxDriver();
  firefox_driver.get("https://www.google.com.gt");
  WebElement search = firefox_driver.findElement(By.name("q"));
  search.sendKeys("Selenium WebDriver");
  WebElement search_button = firefox_driver.findElement(By.id("gbqfb"));
  search_button.click();
  Thread.sleep(2000);
  System.out.println(firefox_driver.getTitle());
  if(!firefox_driver.getTitle().equals("Selenium WebDriver - Buscar con Google")){
   fail("Test Fail");
  }
 }

Now to do the test that obtains the title of the page and prints it in the console you can use the following code, this test will fail if the title of the page is not Google:

@Test
 public void title() {
  WebDriver firefox_driver = new FirefoxDriver();
  firefox_driver.get("https://www.google.com.gt");
  System.out.println(firefox_driver.getTitle());
  if(!firefox_driver.getTitle().equals("Google")){
   fail("Test Fail");
  }
 }

So that´s it for writing the tests, in the following post we will use ANT to execute them and then we will automatize the execution of our testcases using Hudson.

See you soon!

Monday, December 16, 2013

How to guarantee the stability of your software

Imagine that you hire a handy man to install a new roof lamp in your living room. After he finishes his work he will try to switch on and off the new lamp to see if the lamp is working correctly.  This is the exact same thing a developer will usually do, he will just test the feature he just added, and if it works fine, then he will move on to the next feature to develop.

Talking back about our handy man, there is just one little detail he forgot: after the installation of the lamp is done, he should have tested all the electrical system of the house to be sure that what he just did, don’t mess up other lamps or electric plugs of the house.  If not, how can he be sure that he didn´t move an old cable disconnecting something?

The insertion of bugs when adding new code is a common problem that you can face if you are doing continuous integration.  The only way to avoid this is by doing automated testing, and if you want to apply Agile methodologies this is mandatory.

As we build only web applications, we only build tests to interact with the user interface via a Web browser. In the next posts of our blog we will give you examples of how to:

1.     Develop test cases using the Selenium WebDriver
2.     Run your test cases using Ant
3.     Use Hudson to schedule a daily execution of Ant (therefore your test cases)

The tools that you will need to perform this are:

Eclipse IDE For Java EE Developers

Ant

Selenium WebDriver

Hudson


See you in a couple of days J