Testing NServiceBus Applications

Posted by admin on May 14, 2012
nServiceBus, Testing / No Comments

Testing these days is thankfully more common place but there is still some confusion in terminology so i’ll start by clarifying what I mean by the terms I use later.

Unit Test – A unit test can be run on any computer that can compile your code, it does not need relational databases or other infrastructure like the file system to run or pass.

Integration Test – An integration test does rely on some infrastructure being present. It tests that more than one piece of technology works with another. For example that a repository can persist data to a database.

Acceptance Test – A test that requires the entire application be deployed and tests journey’s designed to simulate user activity in the system.

I’m not going to talk about Unit test’s as far as i’m concerned they are a known quantity with NServiceBus. Just select your mock object library of choice and start writing your tests. That said the amount of repetitive code you have to write as you mock out handler after handler does seem tiresome.

Our team is trying to automate as much of the testing as is reasonably possible. We want developers to be able to write tests that they can run locally and that will run against our WIP, UAT & RC environments to indicate the state of those environments. Our application is divided up into SOA serivces. So when a developer is working on a feature ticket they will likely only be writing code for a single service.

We started out with the idea that we would write unit tests and acceptance tests and that would give us enough coverage and to be honest that is still true to this day. What has changed is that our codebase has grown and correspondingly the build / deploy / test times have increased as well. So what could we do about it? Well the first thing we did was start rewriting our build scripts to perform tasks in parallel, this process is trickier than we first imagined as dependencies complicated matters. If not done properly it could destabilize our development environment so whilst this will help in the long term it will not solve our problems today. Another thing that happened as our application grew, the amount of resources it took to deploy the entire system onto a single machine also grew. We started to have to upgrade developer workstations to have 16Gb of Ram just to be able to run the entire application locally. After a while it became clear that this approach of deploying the entire application locally was not going to work forever but after some thought it seemed that it did not have to. We had already split our app into SOA services why not just build / deploy / and test the service you were creating a feature for? It turns out that this is not only straight forward but that it has other benefits when it comes to testing.

So now we just have the service that were working on to worry about instead of taking 15 minutes to build the entire codebase we only spend 90 seconds building one service. When it comes time to deploy the changes we only need to update the endpoints we have modified, locally we deploy a SOA service to just one endpoint this takes only 1 minute. Then we write “integration tests” that simply inject commands and events into our SOA service’s input queue that simulate user input and events published by the other services. The benefit of this approach is that simple tests take < 2 seconds to complete and complicated ones take less than 10 seconds. These test times might seem a little bit longer than you would expect the next paragraph explains why.

Testing Asynchronous Messaging Applications
Martin Fowler talks about the highs and lows of testing asynchronous applications and I can confirm from first hand experience that he is correct. If you inject a command into your input queue and then wish to make an assertion against a query that expects that data to be written to a database then you have to poll that database for a reasonable amount of time to check the data. Your test then either passes because the data is returned as expected or the timeout period is reached. This sounds simple and it is but only when you have figured out exactly what you need to poll for. If your system requires that messages be processed in a particular order then your tests must poll to ensure that the preceding message has be processed before you inject a subsequent one. In and ideal world you’ll have everything setup so that your system can handle messages in any order but in the real world you may not. What gets even more interesting is when you need to make data modifications to simulate time passing. As soon as your tests start modifying data then they are likely to encounter deadlocks, so you must include retry logic inside your tests if you need to update data like this. We have created a framework that helps make developers a lot more productive it has functionality to poll for a specified interval say every second or it can use a dynamically increasing interval that will check after 250ms, 500ms,1sec, every 5secs this helps reduce test times and shorten feedback. We are using the MbUnit framework which has some nice features for running tests in parallel which can dramatically reduce test run times.

This post is a work in progress but I wanted to put it out there to see what others are doing so if you have anything you like to share or disagree with the above let me know via twitter.

Comments Temporarily Disabled

Posted by admin on January 30, 2012
Uncategorized / Comments Off

Due to the amount of comment spam.

When I have figured out how to enable captcha on wordpress comments are switched off.

TSQL snippet – Grant a Login Read-Only Access to all databases on server

Posted by admin on January 16, 2012
SQL Server, Uncategorized / 1 Comment

This snippet will generate a script that if run will grant access to all the non system databases on the server.

Running Approvals Tests from Resharper Gotcha

Posted by admin on November 07, 2011
Uncategorized / Comments Off

Llwellyn Falco has created a ellegant testing framework called Approvals I have been using in it for a few weeks and found it very useful.

I ran into a gotcha when trying to run tests using the Resharper Test Runner, the default path was not being picked up correctly, fortunately all I had to do was turn off Resharpers Shadow-Copy feature and all was well again.

How to keep the cost down when planning your wedding.

Posted by admin on October 18, 2011
Uncategorized / Comments Off

Folks don’t get married all that often so unless you happen to be an event planner by trade you will be a beginner when it comes to planning your wedding. I have been directly involved in planning one wedding (mine) and what follows are some observations of where the significant costs and challenges arise. I have also been to lots of friends weddings so some of my observations come from those experiences.

The Numbers

First of all you have to come up with a number that represents what your prepared to spend. For this post to be relavent that number will need to be inside the range of £2,000 – £30,000 if it’s not then you can stop reading now :) Then you need to work out the number of people you will invite, this may be two numbers one for the number you’ll invite to the ceremony and one for the people coming to the reception. It might even be three if you plan to invite some to only the party in the evening.

The Location and date

You’ll need to consider where your guests will be travelling from when you are looking for a location. We would all love to get married somewhere beautiful like the Amalfi coast in Italy, but you need to consider the practicalities. If you pick a remote location you will have to accept that some of your friends or familly may not be able to come. This comes down to the situation of your familly and close friends if they have small children then shipping the whole familly overseas to watch you get married will be quite an undertaking, it’s best to ask them first before making this call. Equally if you and your friends are DINKS (dual income no kids) a wedding abroad might work well, a friend of mine did this and we had a great time.
The date you pick is all about giving you and your guests enough notice to plan for the big day. If you are going for a modest number of guests 30-40 and a simple ceremony then I think you should set a date six months or later. Most of the wedding industry like dress makers, cake makers, photographers will expect six months notice and some will charge extra if you need their services sooner. If you are planning a larger wedding 100-150 guests and then I would reccommend choosing a date that’s at least a year away. We managed to plan a wedding for 160 guests in six months but I would not reccomend this, when we were talking to suppliers and told them the date was in August most assumed we meant the following year.

The Venue(s)

Potentially one of the largest costs is where you decide to hold the wedding, it also dictates how complex the logistics of moving & feeding guests will be. The simplest and cheapest option is to find a nice, large hotel and get married in the grounds and have the reception in one of the function rooms. This means your guests can book rooms at the hotel so they do not have to worry about transport to and from the church or how they will get home. If you go for this option you should ask the hotel if they will reserve rooms for your guests and you should also try and negotiate a discounted room rate. When you send out the invites you should inform your guests that they can book a room at the venue and include contact details. When choosing a hotel you need to check the room rates ideally you want a good range of rooms available at a good range of prices. If you are having a pay bar then check out bars drinks prices, some skillful negotitaion might secure a discount on the standard prices. You should also check that the hotel has ample car parking if your guests will drive to the wedding.If you have decided that you will get married in a church then ideally find a church that is close to the hotel you choose for the reception. You then might want to consider hiring coach to take people from the hotel to the church and back to the hotel. We did this at our wedding, the cost of hiring a 50 seater coach with driver for 12hrs was £500, smaller mini buses for less time are cheaper.

The Food

After the ceremony we invited all our guests back for lunch there are two options a buffet or a sit down meal. A sit down meal is about 3 times more expensive than a buffet for the same quality of food. If you are hosting the party (we had a Marquee in the garden) then if you have a favourite local restaurant ask them if they would be interested in doing the catering often this will be the cheapest option that guarantees nice food. If you are holding the reception in a hotel check before booking that there catering meets your expectations, choose your menu and ask to taste a sample in advance. Don’t forget a % of your guests won’t eat meat and some might have special dietry requirements you should probably put a section about this in your invitation. One wedding I attended starters were served at your table but when you were ready you went up to the buffet to get your main course. This worked well because it naturally staggered the guests and kept the queue at the buffet reasonable. The sit down meal at our wedding cost £40 per head.

The Party

We had a party after the meal and invited some guests just for the evening, this worked well as we maxed out the guestlist for the ceremony but could easily add people to the evening. We hired a live band which cost about £1100 but they were really good and got everyone up to dance I would reccomend live entertainment over a DJ if the budget will stretch to it. The band came with PA system and lights included.

100 Person Wedding Example Costing with entire wedding held at hotel

£2500 – Buffet
£1500 – Champagne & Wine with meal and toasts (Check if hotel charges corkage as this will increase cost)
£1000 – Function Room & Chapel Hire
£1200 – Live Music swapping for a DJ would be cheaper say £400
£2000* – Pay Bar @ £20 head, optional let guests pay, they won’t get so drunk and thank you in the morning.

£1000+ – If you have a dress made min cost is £1000 sky’s the limit though
£1000+ – Simple flowers for the ceremony & tables, shop around and you might find cheaper
£500 – Morning Suit Hire, cost will vary depending on number of ushers, if money is tight you might ask guest to pitch in.
£1000 – Wedding rings, you can spend more and you wont get anything fancy for £1000.
£750 – Basic Photographer cost will go up if you do not own copyright and you order lots of sets of prints
£500 – Cake, personally I would not bother with a cake.
£300 – favours
£400 – Gifts for best man / bridesmaids / mother of the bride / mother of the groom
£50 – Wedding invitations if you make your own
£200 – registrar for ceremony
£500* – Cars / Limo for transport optional

New rig

Posted by admin on October 02, 2011
Hardware / Comments Off

I always blog about each pc I build as a way of remembering the bits that I purchased. My machine is left on 24/7 so I’m in the market for a pc that does not use much power when idle. This makes both cooling easy and my electricity bill lower. The total cost of this box including VAT came out at £530.

I have not measured the power consumption at idle but reading reviews of the cpu and motherboard it should be less than 15w. The case only has one 60mm fan but feels cool so it seems adequate. The fan is a little bit noisy especially as this is an HTPC case but I might be able to tweak the fan speed to make it quieter.

Putting it all together was easy as this type of case makes access simple. I fitted all components and cables before inserting the CPU and cooler. I installed Ubuntu 11.04 from a USB flash drive without any problems. The whole process took about 4 hours and my system building skills are very rusty as I built my last one five years ago.

I have split the drive into two partitions in case I need to dual boot Ubuntu and windows 7, i’m starting with Ubuntu and seeing how it goes. Ubuntu boots very fast from cold in only 22 secs from pressing the power button. I’m a Ubuntu noob so have nothing but windows 7 for comparison but this machine feels faster than my Acer 3810tz laptop (with SSD upgrade) but it is early days and I have not thrown anything heavy at it yet.

One issue I had during the build was that the media card reader USB cable would not reach the connection on the motherboard so is not operational at the moment. This does not bother me as I have  an external one.

Specs

Intel i3-2100T 2nd Gen Core 2.5GHz 35W TDP £92.00 ex vat
128GB Crucial m4 SSD 2.5″ £122.00 ex vat
DDR3 1333 DIMM £30.00 ex vat

Silverstone LC19B htpc Case £99. ex vat

silverstonelc19b.jpgSilverstoneCaseInsideView

Zotac H67-ITX-C-E Mini-ITX Motherboard £99.00 ex vat ZotacH67ITX.jpg

Ubuntu for windows users

Posted by admin on October 02, 2011
Ubuntu / 1 Comment

I am in the somewhat painful process of learning how to use Ubuntu to do the things I already know how to do in windows. Why? I hear you ask well to put it simply I like the Ubuntu philosophy and everytime I choose Ubuntu over windows for a new Pc it saves me £80 (often referred to as the windows tax), naturally I still spend the £80 but I get better hardware :) . The following notes are all along the lines of, I used to do X on windows how do I do it on Ubuntu?

How do I Browse the Web?

Ubuntu ships with Firefox but you can also install Chrome by visiting the chrome website.

How do I get to a command prompt on Ubuntu?

First of all cmd prompt in Ubuntu speak is called Terminal, click the Applications icon on the launcher and type Terminal then press enter or click the icon.

How do I get network adapter settings on Ubuntu?

In windows you would use the ipconfig command in Ubuntu use ifconfig.

How do I edit a text file on Ubuntu?

Ubuntu’s notepad equivalent is gedit. Open a Terminal window and type: gedit or run gedit from the Applications icon in the launcher. I’m sure there are countless applications that can edit text files but gedit is the built in editor.

How do I remote desktop from Ubuntu to windows?

You need a program called rdesktop to get this open Terminal and type the following:

sudo apt-get install rdesktop

You will be prompted to enter your root password (the one you entered during the ubuntu installation) then either the rdesktop program will be installed or if it is already present updated. Then to launch the program type the following and substitute the hostname or ip address (leave out the < >)

$ rdesktop <enter_hostname_or_ip_address_here>

More details can be found here

How do I connect to an FTP server on Ubuntu?

Again this post is written from the point of view of a windows user, this may not be the best way to use FTP on ubuntu but it should be a familiar way for windows users.

First install FileZilla, to do this click on the “Ubuntu Software Centre” icon in the launcher. In the search box type: FileZilla the press enter, then click install. Open filezilla by opening a Terminal windows and typing: filezilla or by using the Applications icon on the launcher.

How do I make a program icon stay on the launcher?

Easy, when the program has started right click on it’s icon in the launcher and click “Keep in launcher”.

How do I connect to Windows Home Server from Ubuntu?

You can use an application called rdesktop see “How do I remote desktop from Ubuntu to windows?” above.

You can also connect to network shares (shared folders) see here for details, the example talks about windows home server but I believe it should work for other servers as well.

How do I easily share files between Ubuntu and Windows machines?

In one word Dropbox, to install dropbox on Ubuntu visit the website and download the client. You will need to do the same for your windows machines. Dropbox comes with 2GB of free space if you need more you’ll have to pay a subscription.

How do I connect to a Cisco VPN on Ubuntu?

Install ShrewSoft VPN, click the application icon in the launcher and type Shrewsoft into the search box and press enter then click install. Import your Cisco VPN profiles and you are good to go.

How do I install spotify on Ubuntu?

Open a terminal window (see “How do I get a command prompt on Ubuntu?” above) then

type the following to edit your sources.list file:

sudo gedit /etc/apt/sources.list

Add these two lines to the bottom of the file:

## Spotify
deb http://repository.spotify.com stable non-free

Click Save then close gedit.

Go back to the Terminal window and type:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4E9CFF4E
sudo apt-get update
sudo apt-get install spotify-client-qt

These instructions may change so check the Spotify website if you have problems link

Test Post

Posted by admin on June 08, 2011
Uncategorized / Comments Off

tap tap tap… is this thing on?

I have just migrated from DasBlog => WordPress, it has been a bumpy ride due to my ineptitude in both DasBlog and WordPress, bear with me whilst I iron out the bumps!

 

 

 

PowerShell Community Extensions Pscx installation on Windows 7

Posted by admin on March 07, 2011
Powershell / Comments Off

I had some pain installing Pscx on Windows 7 some of the instructions that came in the download did not work for me and other instructions assumed knowledge. The following explains what worked for me.

My environment details:
OS: Win7 Home Premium 32bit     // echo  (Get-WmiObject Win32_OperatingSystem).Caption   $ENV:Processor_Architecture
Powershell Version: 2.0              // use get-host to check this

1) Ignore the instructions that come with Pscx download
2) After downloading Pscx-2.0.0.1.zip, right click on the file and UnBlock the file, then extract the contents.
3) Copy Pscx folder to: C:\Windows\System32\WindowsPowerShell\v1.0\Modules
4) Open a powershell prompt (powershell.exe) enter: set-executionpolicy unrestricted
5) Enter command: Import-Module Pscx

The instructions above worked for me, if they do not work for you please post a comment.

What the hell is Inversion of Control and why should I care?

Posted by admin on January 30, 2011
Patterns / Comments Off

I have been trying to deepen my understanding of IoC (Inversion of Control) or “Dependency Injection” as Martin Fowler prefers.

For the first time I heard a really good explanation of what IoC is and why it is useful. This was during a podcast with Scott Hanselmann whilst he was discussing MVCTurbine in his Hanselmiutes podcast.

Scott described the process of creating a new MVC app: After you have fired up Visual Studio and clicked file > new > MVC project you must then go about the business of creating a controller. Once that is done you need to create a view and then you can fire up your app and see a web page. Now you need to start adding some infrastructure to your controller to give it the ability do things like logging. At this point you need to make a decision about where the responsibility or ‘control’ will be placed for getting the logging implementation. Now logging is a great example, nearly all applications need to log information so it is likely that you will be making use of an existing library, it is also likely that logging is going to be performed by most handlers. If you opt to make it the responsibility of the controller to locate and instantiate your logging library then all controllers will need the code that does this. If instead you opt to invert the control of this location and
instatiation then you need a mechanism to do this… enter Dependency Injection. Instead of adding code to your controller that locates and instantiates a logger you place a dependancy into your controller on an interface that describes the interraction with your logger. Then you pick a container like Autofac or Windsor and configure it so that at runtime it knows how to instantiate the implementation that you want to use for logging.

With IoC when you look at the code of the controller class all you see is a public property of the logger interface type:

public ILog Logger{ get; set; }

Unless you first understand that the dependancy will be injected at runtime the code looks a bit weird and like it couldn’t possibly work because it is not obvious how the implementation will be located and instantiated. When your application starts you must add some code that configures your chosen IoC container so that it knows how to inject the logging implementation into your MVC controller at runtime.