Category Archives: Programming

In this post I’ll give a more detailed guide for the Spring Boot and Docker initiative. 

The final goal that I had in mind, was to have a Docker container that runs the packaged java application in a clean environment. 
Support for remote debugging is included in the configuration, as well with both running and debug listening ports mapped/forwarded between the windows and docker machine.  So in the end you can access the application as if it was running on your “localhost” 😀

After installing the Docker Toolbox (next > next > next…) we can jump right into creating a simple HelloWorld Spring Boot Web Starter project. 
To do this in the fastest way, create a New Project > Maven and inside the pom.xml add the following dependency:

This is my trimmed version of the “Getting Started with Spring Boot” from the official site. 
You can go ahead and run “mvn package” command to generate the application’s executable .jar file. 

Now for the Docker part, let’s start with installing the IntelliJ “Docker integration” plugin.  This offers easier communication with the docker and saves some time, cause you won’t have to spam “docker build” … “docker run” commands in a separate console. 

In the Maven pom.xml file, you’ll need to add the following docker-maven-plugin along with a few very important configuration lines. 

In the configuration we are able to specify the baseImage and imageName along with the expose and entrypoint parameters which are very common in a Dockerfile.  In our case, we won’t be needing one at all, because the maven plugin will do all the work for us! 

The environment variables are used to specify the server.port to run on 8888 instead of the default 8080 (yes, I’m still using Skype…)
The ports also need to be exposed from the docker container so both the server and remote debugging ports are added. 
Entrypoint is basically the whole java command used to run the server, in our case the resulting “.jar” file after mvn package.  It contains some extra arguments to enable remote debugging for the server. 

In order to make use of this plugin we need to run “docker:build” from maven/plugins section. 

After it’s finished we will have a new “spring” image derived from the default Java one.  Now here comes the Docker and IntelliJ integration part. 

We will go ahead and create a new Docker Deployment configuration as follows. 

We can then press Play and our container will be started along with the application server.  In order to be able to access the server from Windows, we need to forward the 8888 and 5005 port respectively, from the docker machine to running Windows OS (this isn’t necessary if you’re a Linux guy, because the docker-host is running natively). 

To do this we can use the following commands from an “elevated windows command prompt” (just run it as Administrator):

Will now go ahead and create a new Maven project in IntelliJ IDEA 15 and then Add Framework Support and select check the Webservice client. 
You can also find a link to the GitHub project at the end of this post. 

Before generating the stubs, we need a few dependencies to be added in the pom.xml

but in order to do that, we need to get ourselves an instance of the GlobalWeatherLocator and furthermore, access the GlobalWeatherSoap_PortType object which has the 2 methods that we’re interested in. 
A quick note here: Don’t be fooled by the “String” return type of these 2 methods, the String is actually … XML so we’re going to need a XmlSlurper to parse it and perform asserts. 

So as you can see, we’ll be passing 1 argument to our readText() method, the “file” that needs to be read.  We’re then using the Apache Commons IO, FileUtils library to read our .txt file so make sure you have that imported (seems that our “custom” readText() method is not so custom afterall )

We’re storing all the read content inside a string and then we’re going to do a split (a fabulous one) by the semicolon (“;”) character since that seems to be separating each individual row. 

Now to find out the number of “columns” we can do another split by the comma character (“,”) since it is separating each username by its password.  Of course you can use any other character for separation and then do a split by it (i.e. a pipe | or a tilda ` or anything else). 

Next step will create an array of array of Objects called “data” and it will have the size of data[rows][columns] that we obtained earlier. 

What’s left next is to make 2 for loops in order to iterate through the number of rows and then columns while assigning the read value to the data[][] array without the whitespaces, which will be trimmed. 

In the end our method will return the “data” Object[][]. 

So we’re now going to use this method for the @DataProvider annotation:

Notice how the dataProvider name in the @Test annotation corresponds with the name of the @DataProvider and how the test method “loginGmail” accepts 2 String arguments which corresponds with a row of parameters from our input.txt file

In the end our test will be executed 3 times because there are 3 rows of username+password combinations which are passed from file. 

During my quest for learning I have encountered this thing, the “Table doubling”.  Boy I was so happy about it that I wrote this article :). 

The goal is to structure some data, any data, in such a way that we can delete, insert and retrieve really really fast while having a decent memory usage.  A real life example would be the HTML code of a webpage.  If we consider each HTML element (node) with its properties a set of data we want to get the one that we care about super fast, not in a second or so.  So, in order to get a sense of why this is useful I will lay down some premises. 

An array = a linear piece of memory of the length of the array.  This will be always busy.  The array must have the keys/indexes integers.  We can’t have the key/index 2.3 or 0.1.  Due to those two properties we can get to any element almost instantly because it exists and we know where it is exactly. 

A linked list = A piece of data that besides its “internal” information that we care about (for our example let’s say the inner text), it has a link to location in the device’s memory for the next item after it.  So 1 knows where 2 is, 2 knows where 3 is, so on and so forth.  This is rather sweet but if goes only forward, with a bit of extra work we get to double linked list. 

Double linked list = a linked list where the individual piece of information knows about the previous piece as well as the next.  Although it has a bigger footprint it solves our previous request in a neat fast way. 

Now, in order to nail down the difference, let’s look at what happenswhen we want to add an element close to the beginning of an array and of a list (double or linked, it doesn’t matter). 

Operation

Array

List

Fetch an element by key
akaExact search

Go to key’s position

Go to the first or last
Check if it is the one we need
If not ask where the next or previous is located
Repeat the previous two steps until found it*

Insert

Increase the length of the array with a number of elements equal with how many we will insert
Move to the right all the other elements in a descending order
Add our data where we wanted to **

It will go at the end of the list and it will tell the last element to have it’s memory address stored. 

Delete

Remove the element
Move all the other elements to the left
Decrease the size of the array

Go to the desired element forwards or backwards
Tell the element to the left to point to the element to the right.  If needed tell the element to the right
to point to the left one

* In case it is not obvious how slow it is.  Take a piece of paper and write the steps for finding the 5th element and count the rows. 
** It will not put it at the end of the array because the order matters.  The premises was that we are close to the beginning of the array so don’t think of adding at the end. 

In conclusion, as we can see, there are quite some advantages and disadvantages for each of the data types. 

Now in order to find the holly ground of those two data types we will discover a new one, called Hash Table.  The not so official definition would be an array that stores as values of its keys pointersto – in the worst case scenario – lists of data with all its properties. 

The other concept of this post is Table doubling .  This says in less words that instead of resizing an array 1 element at a time, when it gets filled we make it twice as long as it is now.  This will allow us to hold twice as much data for future inserts after one operation, and eliminates the need of moving all the elements all the time.  The second part is that on delete we shrink it by at least 1/3.  This means that inserting and deleting a few elements will not trigger the resizing. 

Let’s look at every operation and see the advantage. 

Exact search:
Now due to being an array we get very fast navigation and finding. Insert:From time to time it triggers the array re-hashing but not so often.  As long as we play with the same amount of data or fiddle a bit with the “1/3” value mentioned earlier, everything will work with the speed of the list. Delete:
The deletion takes part only where there are a lot of free elements, and event after the deletion we have room for more than we had in the beginning.  Almost as fast as the double linked list. 

Conclusion:
I can see this saving seconds on every test case ran on a page with a few hundredth elements. 

We have received the task of copying a very big suite of tests from a project to another and maintain their test cycle assignment.  For the copy and moving part is easy, there are bulk actions.  For the automatic assignment we couldn’t find a quick solution, probably there was. 

Here’s our approach:

1) On the Test Cycles page we extend a test cycle that has tests which will be moved.  This is necessary in order to figure out which to move. 

In the browser’s console we run this code (search for domain in the ajax call and replace with your own domain):

2) This returns an array of test names.  Those names will be used as identifiers later on.  Please copy them into another external document. 

3) Copy or move the tests into the other project as desired

4) Open the tests search page on the new project and display as many as possible (the current functionality does not cycle through the pages)

5) Paste the following code and replace the first line with the array exported by the previous code:

12345678910111213141516171819202122

var incomingTitles =["[Event Validation] Frontend - Checkout flow","[Event Validation] Frontend - Mobile site","test name 2","test name 3","test name 1","test name 2","test name 3","test name 1","test name 2","test name 3","test name 1","test name 2","test name 3","test name 1","test name 2","test name 3","test name 1","test name 2","test name 3","test name 2","test name 3","test name 1","test name 2","test name 3","test name 1","test name 2","test name 3","test name 1","test name 2"];