Thursday 28 June 2012

Expanding TFS 2010 Database post Lab Management setup

Monday Morning:

I usually love Mondays. A brand new week, so much to look forward to, UNLESS you get an angry email from your System Administrator & you know you have a plethora of other development tasks you need to finish this week.

The Email:



Findings:

After some digging around, here is what I had discovered:

  • Our Team Foundation Server database [it uses Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64)]
  • The highest recorded growth was in the following few tables




Post our initial investigation, it became clear that TFS had decided to store binary build objects in the attachment tables after we had set-up Lab Management & decided to use Test Driven Development (Unit Tests run on Gated Check Ins, Unit + Integration Tests run on Nightly Builds & Unit + Integration + UI Tests run on Staged & Release Builds.) I wrote the following scripts:



It was interesting to see that on every test run (triggered by a Gated Check In or a Release/Staged build) we were adding > 250 files to the Attachment Content table. Yikes!! This was looking more and more like an episode of  "When good servers go bad!"

Test Attachment Cleaner:

A couple of interesting google searches later I discovered the Test Attachment Cleaner [http://visualstudiogallery.msdn.microsoft.com/3d37ce86-05f1-4165-957c-26aaa5ea1010/]


The MSI installs itself to "C:\Program Files (x86)\Microsoft\Test Attachment Cleaner". The readme file explained it all ...

In Dev10, with the introduction of Visual Studio Test Professional 2010 & Visual Studio Premium/Ultimate 2010, testers can author manual and automated Test cases, configure the different diagnostic data collectors (as part of Test Settings), associate the Test Settings with Test Plan/Suites and then execute these test cases as part of Test Runs. The execution of a Test Run (whether automated or manual) generates a bunch of diagnostic data, which may be captured either automatically by the system or manually by the tester. This diagnostic data is critical in eliminating the “no repro” bug scenarios between the testers and developers. However, the downside of this rich diagnostic data captures is that the system/user generated diagnostic data, over a period of time, can grow at a rapid pace and start taking up database space.

With Dev10, the database admin has little or no control over what data gets attached as part of Test Runs – i.e., there are no policy settings he can control to limit the size of the data capture OR no retention policy to determine how long to hold this data before initiating a cleanup. In such scenarios, the Admin has no mechanism to:

a.       Determine which set of diagnostic captures is taking up how much space AND
b.      Reclaim the space for runs which are no longer relevant from business perspective.

The “Test Attachment Cleaner” tool fills this void by serving both the above points. 

I ran the following commands on each project:

tcmpt.exe attachmentcleanup /collection:http://localhost:8080/tfs/TFS2008_Migrated_Projects /teamProject: ProjectName  /settingsFile:.\SampleSettings\CustomScenario.xml /mode:Preview


tcmpt.exe attachmentcleanup /collection:http://localhost:8080/tfs/TFS2008_Migrated_Projects /teamProject:ProjectName /settingsFile:.\SampleSettings\CustomScenario.xml /mode:Delete

The CustomScenario xml file I used was as follows:


Additional Patches & Test Settings:

Additionally, it turns out that we needed the following patches/updates/hotfixes applied to TFS:
  1. Microsoft Team Foundation Server 2010 Service Pack 1: http://support.microsoft.com/kb/2182621
  2. Cumulative update package 2 for Visual Studio Team Foundation Server 2010 Service Pack 1: http://support.microsoft.com/kb/2643415#appliesto
  3. A hotfix that can reduce the size of the test data saved to the TFS database is available for Team Foundation Server 2010 Service Pack 1: http://support.microsoft.com/kb/2608743


Also, we need to ensure that the test settings file referenced in the build has the "Enable Deployment" option unchecked.



Post these updates, our test runs showed a significant reduction in the attachments saved to TFS as shown by the following query:



Monday 11 June 2012

Writing your own JQuery Plugin and Widget



Ok, I'll admit it. When I was initially asked to work on the front-end components of our web application, I wasn't too happy. I thought I'd be writitng lines and lines of procedural Javascript code because Javascript is an inadequate language which does not supoort OOP principles ... or so I thought.

A few pluralsight videos later I discovered how JQuery was a brilliant JavaScript library that just simplified way I wrote javascript. Don't get me wrong, There is still room for improvement but it does let you do some pretty funky things.

In this post I'll be talking about writing your very own JQuery plugin and widget. My main reason of writing this post was for it to facilitate as a prequel to my next post about wrapping the Slick Grid. I've used a lot of recommendations from Project Silk.

So here we go ..


JavaScript, jQuery and jQuery UI.


JavaScript is a client-side scripting language, and also a prototyping language which means that its objects can have properties added dynamically at any time. The language itself is fine, but can be quite frustrating when different browsers get involved, and there are a few things that need smoothing over.

So, this is where jQuery steps in. jQuery is a JavaScript library that's been developed to get rid of most of those annoyances. The library simplifies a lot of common tasks, such as:
  • Selection, traversal and modification of DOM elements
  • Making AJAX requests
  • Cross-browser support (this is built into jQuery and virtually becomes a non-issue)
  • Extensibility and modular development with plugins and jQuery UI widgets
jQuery UI is a plugin for the jQuery library, that simplifies the process of creating specialised widgets to use in the web. You can think of widgets as being similar to ASP.NET user controls. A jQuery widget is targetted at an HTML element, and augments that element with richer functionality. You might have a simple, empty <div>, which is then used by a jQuery widget to display a customisable grid, or a text <input> that is turned into a date/time picker, or an autocomplete input.

JavaScript Objects, jQuery Plugins, and jQuery UI Widgets

Most of the client-side code that you're writing will fall into one of three categories:
  • UI Modules - Adding, removing and modifying UI elements
  • Behavioural Modules - Adding behaviour to elements
  • Infrastructural Modules - Completely separate from UI concerns
And the types of objects we work with will be:
  • JavaScript Objects - Collection of properties which may be functions, or just simple data.
  • jQuery Plugins - Extending the functionality of the jQuery framework
  • jQuery UI Widgets - Similar to User Controls, associated with HTML / DOM elements, encapsulates complexity

JavaScript Objects

These can be:
  • Native objects - Supplied by JavaScript, e.g. String, Number, Array, Image, Date, Math... etc.
  • Host objects - Supplied by the client/browser environment, e.g. window, document, forms... etc.
  • User-Defined objects - Defined by you, the programmer.

jQuery Plugins

Notice how an anonymous function is declared, which accepts a single argument ($). On the final line, the anonymous function is called with (jQuery).


The plugin itself is defined within an object, which is passed to jQuery's extend function.



jQuery UI Widgets

This offers a clear way of developing widgets that will require some setup, cleanup and a way of passing arguments in (similar to a normal constructor).

Some of the standards functions in a jQuery UI widget are:
  • _create - Used to perform all the general setup and attaching bindings to various different elements, instantiating children and injecting elements into the HTML as necessary.
  • destroy - Used to perform a complete cleanup of the widget and its elements.
  • options - Allows us to pass options into the widget when it is being instatiated.

Project Silk Recommendations