Archive for

April 2007

Make a Big Impact in a Small Area

I’ve been re-reading Evans’ Domain Driven Design recently and, whilst reading one night last week on the train home, something stuck.

It is more useful to make a big impact on one area, making a part of the design really supple, than to spread your efforts thin.

Although I’ve been very lucky in working on things I enjoy, over the past week I’ve particularly enjoyed the work I’ve been a part of. We’ve been trying to make some improvements to a section of code that hadn’t had so many tests around it. Initially, these were used to drive a couple of small refactorings to improve the readability of the class and better separate the responsibilities it had.

So, as good developers some fellow team-members earlier sat down to add good tests around the current behaviour to ensure that whilst things were being moved around nothing broke.

And, because my teammates are all excellent developers, they (and me) spent time ensuring that the tests we wrote were nice and small, communicative and focused. During this time we made sure that our tests were treated with the same respect as the rest of our code, keeping them clean and readable. When the test code got ugly, we refactored our tests (and our design under test) to reflect a cleaner design.

We’ve really felt the benefit of all this work. We started a card that involved adding much more behaviour to the same area of the system. The gateway was getting some brains.

We were able to take the nice, focused, behaviour explaining tests they had started and extend and build upon them easily for the behaviour we were going to add. And, by adding some automated higher-level integration tests, we were able to get even more confidence that we were retaining the behaviour we wanted, and adding the new behaviour we needed.

Thanks to the loving care shown by the previous developers those of us following in the footsteps had a much easier time, and our new design is much more consistent, useful, and ultimately valuable.

Because we chose to make a big impact on a very small area of the system, we felt a large benefit on our productivity. Our tight focus helped us evolve a more supple and elegant design.

Posted

A Little Capistrano Recipe for Joyent Accelerator

I’ve started putting together some Capistrano goodness to help automate the process of getting a new application deployed onto a Joyent Accelerator using the default Apache 2.2/Mongrel stack.

The first cut is working (for me at least) and I’ve put up a SVN repository at http://svn.oobaloo.co.uk/svn/accelerator_recipe/ that people can grab the recipe from.


  • accelerator_tasks.rb contains the Accelerator specific tasks. This includes one for creating the Apache 2.2 proxying configuration file, and, the Solaris Service Management Facility configuration file (which lets the accelerator boot mongrel when necessary.

  • apache_vhost.erb is the template for the Apache configuration file

  • smf_template.erb is the template for the SMF configuration file

To use, export the files from SVN to your config directory. So, inside your application’s home directory do

svn export http://svn.oobaloo.co.uk/svn/accelerator_recipe config

Ensure you’ve got a working mongrel_cluster.yml configuration file, and if you haven’t already, create the capistrano deployment recipe cap –apply-to /my/rails/app

Then, add the following to the top of deploy.rb

require ‘config/accelerator_tasks’

and add two new properties (used to configure Apache for the new domain name)

set :server_name, “www.myapp.com”set :server_alias, “myapp.com”

See the Apache docs for more info about the ServerName and ServerAlias directives if you don’t know what they do.

Finally, change the restart task to use the new smf_restart task (which in turn calls the smf_start and smf_stop tasks):

task :restart do  smf_restartend

Once you’ve added everything to Subversion, you ought to be able to do cap setup to create the initial app directories, create your SMF configuration file, and, Apache 2.2 virtual host configuration file. The SMF configuration file goes into your application’s shared directory (that Capistrano creates). The Apache 2.2 configuration file goes to /opt/csw/apache2/etc/virtualhosts/myapp.conf.

Finally, try cap deploy to do a new release, and call restart which will try and start your Mongrel service. I’ve also created a svcs task that will show you all the services installed into the SMF. If your Mongrel instances don’t fire up, check the result by running svcs -x, or check out the /var/svc/log/network-mongrel-myapp-production:default.log and see whether there’s any info about why it didn’t start.

Disclaimer

This is pretty rough and ready, but, it works for me with a stock Accelerator. However, this recipe does assume you are deploying your web and application servers to the same accelerator. It shouldn’t be tough to fix it up to figure out how to deploy to different accelerators, but I haven’t done it yet. Also, I’m still not overly familiar with Capistrano so if I’ve made some glaring mistakes in how things are done, also, please let me know (this is more of a first guess than anything, I’m hoping people will correct me).

I’ve posted something similar to the TextDrive forum, check out that thread in case people post follow-ups there too.

Most importantly, if people do use it and fix stuff up, please, please send the fixes back and I’ll get them committed into SVN for everyone.

Thanks!

Posted

DNS Hosting Recommendations Requested

Dear Lazyweb,

I am in the process of consolidating a lot of the various VPSes and hosting accounts I’ve accumulated over the years. I’ve had a great time with RimuHosting and would still absolutely recommend them to people, but, I ended up hosting most of my apps at my MediaTemple GridServer account, leaving my VPS at Rimu to just serve up SVN and some static stuff for friends.

One of the things I love about RimuHosting is they provide a great little DNS administration area, providing realtime-ish DNS updates. I can host as many domains as I like, and it’s nicely redundant with a couple of servers across their various datacenters.

I’m sticking with my $15 entry-level Joyent/TextDrive account for email (roll on the IronPort filtering!) and simple site hosting for friends. I’ve got a Small Accelerator for deploying other apps I’m working on, and, this blog.

I only have a handful of domains, but, I’d like to have a nice clean consolidated interface for managing it all, allowing easy updates and management.

EasyDNS is the obvious choice (to my mind). But, it’s a little more expensive (at $20 per domain per year) than I’m prepared to go for. It would work out to over $120 for the year!

So, what else is there? Anyone have any good recommendations?

Posted

Checking Object Equality In Mocha

I’m working on a little pet Rails project and wanted to use Mocha to isolate my controller tests a little from what is usually encouraged, especially in light of what happened last time. I figured I’d give Mocha a go.

I wanted to verify that my service was called with objects that look equal to what I was expecting. Ordinarily, it will compare instances - are they the same object. I didn’t want that, but rather wanted to test that the values of my (ActiveRecord) objects were the equal. Easy. Mocha allows with to be called with a block that is evaluated to compare the objects.

My tests look something like this

def test_should_ask_service_to_calculate_new_prices_for_booking  address = Address.new(:postcode => "W1 1QE")  booking = create_booking  OrderBookingService.expects(:calculate_price).with(booking, address) do |b, a|    b.attributes == booking.attributes && a.attributes == address.attributes  end
  post :calculate_price, :booking => booking, :collection_address => addressend

It’s something I’ve had to do many times in the past with JMock and NMock - I want to test equality for an aspect of some other object but it’s always meant writing rather a lot of code. Neat.

Posted

I'm not so sure I LoveFilm

So here’s one for Marc McNeill.

I received a promotional offer from LoveFilm.com (one of the UK DVD rental companies) over Christmas and I figured I’d take advantage and give it a go again (I found I never used it last time).

Well, turns out I was wrong, I haven’t changed. I borrowed some DVDs of Lost (in the incorrect order I might add) and I’m yet to watch the episodes. Today I received another email with recommendations, prompting me that I needed to do this.

I logged into my account and found where I could cancel my account. I click the button to cancel and then see the following:

To confirm your cancellation please call us on 0800 091 1514.
A member of our Customer Services team is standing by waiting to speak to you they will be able to take you through the rest of the cancellation process as there are a couple of questions we need to ask you.

Why is it so complicated? What a sucky experience.

Posted

Running on the Joyent Accelerator

I finally received the connection details to my shiny new Solaris-based Joyent Accelerator over the weekend - apparently some hardware delays pushed things back a bit. Getting my Mephisto install running was pretty painless, here’s how I did it.

After logging in, I checked I had ruby

:~] admin$ ruby -vruby 1.8.5 (2006-12-25 patchlevel 12) [i386-solaris2.8]

Thinking I might have to install Ruby Gems, I checked that also:

~] admin$ gem -v0.9.2

Excellent, so no need to install anything there, brilliant.

The most stable setup I’ve had so far has consisted of running Apache and Mongrel. My preference is to run a couple of Mongrel instances proxied to from Apache. For that, we need mod_proxy_balancer and for that we need Apache 2.2

~] admin$ apachectl -vServer version: Apache/2.2.4 (Unix)Server built:   Feb 19 2007 00:18:52

So, to install Mongrel I did (following a little from TextDrive’s notes)

~] alias make=/opt/csw/bin/gmake~] alias install=/opt/csw/bin/ginstall~] sudo gem install mongrel~] sudo gem install mongrel_cluster

Sweet. So, all that remained was to get my existing database copied over using mysqldump, a quick rake db:migrate to bring my database schema up-to-date (so I can work with the latest Mephisto code) and all is well.

Finally, all that was left was to add a new virtual host configuration file for Apache. I used the sample that Joyent/TextDrive provided.

In total, it took me about 15/20 minutes this morning whilst eating breakfast. Pretty easy!

Posted
Fork me on GitHub