Cleaning Up with MSpec

I use MSpec for testing my code.  I love the behavior driven approach, for me it just makes sense.  I love how if my boss asks where are we with component XYZ, I can just run all my tests and give him the output.  It shows what’s working and what’s not.  Further more, we can say or make a rule that software doesn’t have a feature until there’s an mspec test saying that it does.

I was recently working with mspec doing integration tests – these I usually do to make sure my DAL and my database are structurally compatible – and I kept getting database constraint errors when I reran tests.  It didn’t make a lot of sense as I had a cleanup section in my code and I wasn’t seeing any errors.

It turns out, that if an exception is thrown in the cleanup section you’ll never hear about it.  At least for me, it doesn’t bubble up.  Once I put a breakpoint on the first line of the cleanup I figured it out.  Previously I was thinking it wasn’t even hitting my cleanup code.  It was hitting the cleanup section however, only there was an error in that section.  Hopefully this gets into the googles and helps someone.

using Machine.Specifications;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace My.Project.Integration.Tests
{
    public class when_creating_a_mything_record
    {
        protected static IMyThingService MyThingService { get; set; }

		protected static MyThing MyThing { get; set; }
		protected static MyThing SavedMyThing { get; set; }

		Establish context = () =>
        {
            MyThing = new MyThing() {
				Name = "thing",
				Description = "thing one"
			};
			MyThingService = ServiceLocator.Instance.Locate<IMyThingService>();
        };

        Because of = () => Exception = Catch.Exception(() =>
        {
            SavedMyThing = MyThingService.Insert(MyThing);
        });

        It should_not_have_thrown_an_exception = () => Exception.ShouldBeNull();
        It should_have_an_id_that_does_not_match_guid_empty = () => SavedMyThing.ID.ShouldNotEqual(Guid.Empty);

        Cleanup after = () =>
        {
           // If this does not appear to get called. put a breakpoint here.  You may have an exception.
           MyThingService.Delete(SavedMyThing);
        };
    }
}

Leave a comment

Git Helpful Hint – Just Trust Remote branch

At work I’m often working with others.  However at times we’ll be working in our own projects (read git repositories) and then working together in common shared projects.  The repository that I’m the main developer on and all the shared ones are always up to date but there repositories that I don’t often commit to can find itself lagging quite far behind.  Recently I saw a large number of merge failures when trying to get the latest version of one of these repositories.

Essentially what I wanted to do was to say hey Git, I don’t work on this repository often so trust everything that is coming from upstream and overwrite my stuff.  There were many things that the googles suggested that I could do, but quite a few wouldn’t work in the midst of a merge failure that had already occurred.

This stackoverflow post did work though.

Here’s how you do it:

git fetch --all

git reset --hard origin/master

Be warned, this essentially tosses out all your local changes. So make sure your situation is like mine or similar before doing it.   I figured if I blogged about this, it would help me remember the next time it came up.

Leave a comment

Fearless

Yesterday amidst a sea of tears and in front of a hot grill I finished reading Fearless – http://fearlessnavyseal.com   I was delaying my grilling responsibilities for the evening to cram in the last few pages.  I love reading and recently I’ve been on a biography kick, I read Howard Wasdin’s biography a year or so ago, and Chris Kyle’s biography just this weekend.  All of these books, have been biographies of Navy Seals, and when on friday I saw a book titled “Fearless” the story of Seal Team Six member advertised on Amazon, I gave it a look and ended up buying it.

This book I knew would be different, the others were written by the SEALs themselves, sometimes with co-authors.  This book, Adam Brown’s story was written after he was killed in action.  I knew it would be sad, I knew it would be touching.  Even though I was armed with that knowledge, I wasn’t prepared for this book. I’ll challenge anyone to read the first two pages, and put the book down from there.  I couldn’t and I don’t think you’ll be able to either.

Put quite simply, I’ve never read anything that had that big an impact on me before.  I found myself in awe and inspired by Adam Brown in many parts of the book, and in full tears in many other parts.  The story is so unbelievable that it couldn’t be fiction.  The old adage or saying, that the Truth is Stranger than fiction is very true for this story.   I won’t give away details, and please if you have read this book do not post spoilers in the comments.   I would be lying if I said after reading this book I wouldn’t look at life at least a little differently.

It is a book about the military, it is a book about a warrior.  Most of all though its a book about humanity, the struggles and obstacles that Adam had to overcome.  Definitely read this book.

Leave a comment

Last Day at Telligent

Today was my last day at Telligent.

My first day was February 4th 2005.  By my math – or by datediff() in SQL – that’s 2,646 days.  I started there as a contract employee wondering how long it would last.  I remember leaving a job that I had been in for about three years when I accepted the position at Telligent.  I remember how scared I was of telecommuting.  No office, no managers to watch over me.  What’s to stop total anarchy and no work?  Well absolutely amazing people, incredible clients and the most challenging work of my career.  That’s what.  When asked by friends how I could work from home for a company so far away, and not just play games all day – they didn’t understand the work was the fun and still is up till this very day.  I worked on amazing projects right up until my final hours at Telligent.  I’ll always be more grateful to Rob Howard and Jason Alexander for giving me the opportunity in those early days.  What started as a small group of .net geeks who sometimes did meetings over xbox live & madden football morphed into something amazing.  An incredible company that I still absolutely love and know will continue to do amazing things.   I’m waiting for the day that I hear Telligent’s name in accolades on CNBC , it will come and I will cheer on that day.   To everyone at Telligent, Thank You so much for the amazing seven years.   I think I got to do almost everything a software developer could do at Telligent.  It wasn’t always easy, was sometimes very hard, but I’d not trade any of it for the world.

I look back at the time with incredible fondness and take away many memories.  I look forward to the very near future when I start my new job at Orcsweb.  I’m leaving one amazing place to go to another amazing place.  I could not be happier and couldn’t think of a better place to move on to.   Expect to hear quite a bit more from me about some of the very cool things I’ll be doing at Orcsweb.  I know I’ve been somewhat silent in the past as I worked on other non technical things, writing etc..  But there definitely will be more posts about amazing technologies and what I’m discovering along the way.

Thank You Everyone.

Scott

5 Comments

Major News Coming Soon

Keep tuned, and check back soon.  Perhaps Friday, at say 5-ish eastern time.  There’s big news coming to this blog.  No Hints and I’m not telling till Friday 🙂

Leave a comment

Database Schema Changes with Postgresql

I’ve been playing with linux recently and really enjoying it.  Quite quickly however I began looking for a good database to use in linux.  The obvious choice if you look around the internets is mysql.  Its the easy one to use, most people use it and as such there’s a ton of documentation etc..  Well for those that know me, the easiest and simplest way is not always what I choose.  So I began to look at postgresql.  PostgreSQL has more in common with databases like Oracle or DB2 than mysql, for some this is a minus but for me that’s a definite plus.  I’ve a lot of oracle experience and skills that can be applied to postgresql quite nicely.  One thing I absolutely love in postgres & oracle is the create or replace functionality for functions.  Gone are the days of if object_id(my_function) is not null…  now I can just create or replace my_function.  That’s killer in my opinion.  So now I’ve got my database (postgresql 9.0) and its time to create some tables.  This was a bit of a dilemma for me, in my native environment (oracle or sql server) I create database change scripts that safely and reentrantly ( you can run repeatedly w/o error) create the objects that are needed in a transactional manner.  But how to do this in postgresql?  Well this post is about what I’ve figured out, and how I’m currently solving that problem.

First, take a look at my postgresql github repository.  What I wanted was a way to have controlled, scripted database changes that were transactional.  They would either entirely succeed or entirely fail and leave the database unmodified.  Also the individual script files would have to have a way of saying I am change #X and I need change #Y to be present first.

Below is how I’ve accomplished this.  What this does is it applies database change 1.0.0 to a database that is of change 0.0.0  (see dbc_0.0.0 in the github rep for how schemaversion, and the initial record get put in place).  Hopefully this is of some help to someone.

create or replace function dbc_1_0_0() returns void as
$$
declare
_old_major integer := 0;
_old_minor integer := 0;
_old_revision integer := 0;
_major integer := 1;
_minor integer := 0;
_revision integer := 0;
_schemaname varchar := 'my-application-name';
begin
if exists(select 1 from schemaversion where major = _old_major and minor = _old_minor and revision = _old_revision and schemaname = _schemaname and current_version = true) then
create sequence user_id_seq;
create table users
(
userid int8 default nextval('user_id_seq') not null,
email varchar(64) not null,
password varchar(128) not null,
fullname varchar(64) not null,
created_date timestamptz not null,
modified_date timestamptz not null,
constraint pk_users_userid primary key (userid)
);
update schemaversion set current_version = false where major = _old_major and minor = _old_minor and revision = _old_revision and schemaname = _schemaname;
insert into schemaversion
(major,minor,revision,schemaname,installed_date,current_version)
values
(_major,_minor,_revision,_schemaname,current_timestamp, true);
else
select 'Missing prerequisite schema update ' || _schemaname || 'version ' || _major || '.' || _minor || '.' || _revision;
end if;
exception
when others then
raise exception 'caught exception - (%) - when applying update %.%.% to % ', SQLERRM, _major,_minor,_revision,_schemaname;
end
$$
language 'plpgsql';
select dbc_1_0_0();
drop function dbc_1_0_0();

 

1 Comment

Massive Data Access Library

Today I got introduced to Massive.  Massive is a data access library written by @robconery.  My co workers @jaymed and @mgroves introduced me to it, and I’ll admit I was somewhat reluctant to give it a shot.  I’m normally of the opinion that the simplest DAL is just pure simple SqlCommands, SqlConnections and a stored procedure call.  However after using Massive for a few hours, I’m really excited about this new tool in my tool chest.  Of course massive has been out for a while, I’m quite slow to the party sometimes.

Massive is great though, I love how in a single line of code I can have data back.  Alternatively I can update the table, or run any other query that I want.  This library if it did nothing else makes integration testing a breeze.  Usually for my tests I prefer to stub out a DAL repository via the interface/repository pattern.  The tests get a FakeSomethingRepository to use that uses List<TheObject> as its in memory store.  What I love about massive is that my unit tests which are really simple because they can test DataRepository.SomeList  can quickly become Integration tests with almost no additional complexity.  For me that’s Huge.  I’m trying a new thing, and that’s not to check in any code that doesn’t have full unit test coverage and Massive is making that happen in a Massive way.  (couldn’t resist)

I’m still learning about these Dynamic things, but a bit of learning never hurt anyone and I know @mgroves will help me out when I get confused.

@robconery If we ever meet, I owe you a beer! Massive is awesome!

If you’re not familiar with Massive, I urge you to check it out here.

1 Comment

P90X First Day

Started my first day of p90X today!  I’m doing the lean track first, I’ll then work though the classic and then maybe the Double or Dual track if I’m really brave.  Its kind of rough getting up earlier so we can work out in the morning but its going to be well worth it in the end.  Today’s workout was core synergistics.  Tomorrow is Cardio X.  I won’t blog after every one, but every so often.  So far my only complaint is that they should have added a “1st” time version or selection where they took an extra minute to explain everything how to do, alternatives etc..  Otherwise I find myself having to look up to see and that often disrupts the exercise.  This might just be a problem because my TV is mounted up high though.

,

Leave a comment

Nix is Whispering

Here’s another sample of my writing.  Similar disclaimer, this was written while trying to go through the exercises from 3AM Epiphany and while trying to develop an evil character.  This is a work of fiction, this character is not nice.

3AM Epiphany – Challenge 2 – Write a fragment of a story that is made up entirely of imperative commands, e.g. “Do this; do that; contemplate the rear end of the woman who is walking out of your life.” This exercise will be a sort of second-person narration.

Wordcount: 500 (+/- 10%)

You’re getting very sleepy.  Very tired, just lay down on the bed now and rest your head.  That’s right just close your eyes now.  Shh baby don’t fret, don’t stir.  Sleep little one, rest your eyes and drink deeply of your dreams.  That’s right, perfect sleep soundly.  Now listen, but remain asleep little one.

There’s nothing to worry about.  Let your fears fall beside you.  There’s no need for your guard to be up, you’re safely asleep in your bed what could hurt you here.  Just relax and sleep deeply my darling one.  That’s a good boy.

You must sleep, you must rest, you have a big game coming up tomorrow.  It’s the championship game for you and your team, you’ve worked hard for it and must be ready.

But are you really ready?  Do you think you’re really strong enough and quick enough for this game?  Think of all the times you’ve thrown the ball only to see it intercepted by the other team.  Quite a few times if you think about it, think about it now – so many interceptions.  Or maybe think about the times you have fumbled and the other team has gotten the ball, how many games you have been responsible for the team losing.  Quite a few, if you think about it.

Think about the other team.  They have been so dominant in their wins, and your team has been well, less so.  You barely made it to this game in fact.  Do you really think you can defeat them?  Think about whether your team is infact strong enough and good enough to win the game tomorrow.  Maybe they are, maybe they are not.  But are you strong enough to be the deciding factor?  You wouldn’t want to cause your team to lose the game would you?

How could you live with that, how would it feel to know that you were the reason that all your teammates were disappointed and forever known as losers?  You couldn’t live with that could you?  Try to think about it, try to imagine in your dream what it would be like.  There are so many of your teammates that have promising futures ahead of them – if they win this game.  Is that something you could deal with, is that something you could hold in your conscience?

Tell the coach you cannot play.  Tell the coach that your arm hurts or that you feel sick.  You can tell him anything but you can’t play you can’t be the reason your team fails.  Do not be the one who steals your teammate’s futures from them.  You don’t want to be that, the source of their future struggles and failures.  You can’t play.  There is no way you can win if you play.  Tell the coach that, tell the coach to pull you from the game.  You’re not ready.

Now Wake Up!  Wake up this moment.  Its important for you to awaken, wasn’t there something you were going to do?  Don’t you have someone you must call?  Tell that person what you believe, tell them what you now understand.

, ,

Leave a comment

Adventures in Linux Ubuntu 10.10

I recently decided to get back into working with Linux.  My previous experience was running Redhat 6.2 and then 7.0 to support an Oracle 8/9 Server.   My first instinct was to install CentOS on my spare laptop – No VM for me! Well I did get CentOS 5x installed and configured with wireless it was an extreme fight.  I decided on a whim to dump the install and go with Ubuntu mainly because that’s what Rob Conery was using on his Tekpub videos.   I was astonished that installing ubuntu was a 1000x easier than was Centos.  I also loved the install process for the Server version and plan to work more with the Ubuntu Cloud offering soon.

The biggest and most exciting thing for me was that the ubuntu install instantly picked up the wireless card in my laptop.  This was huge as it took hours for me to get Centos to pick it up and had to go through many hoops and a lot more googling than I would have expected.  Now this isn’t hugely unexpected as CENTOS is meant to be an enterprise os and not a desktop operating system.  Mostly this was #ScottFail for not using the right tool for the job from the start.  That being said, I can’t state how awesomely pain free the process was.  I’m an ubuntu convert and for me that’s saying a lot.  I have a habit of sticking with one brand, what can I say? Marketing folks must love me.

 

, , , ,

2 Comments