<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>the higher you fly &#187; Uncategorized</title>
	<atom:link href="http://mikemclean.ca/wp/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikemclean.ca/wp</link>
	<description></description>
	<lastBuildDate>Tue, 22 Nov 2011 23:33:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Hibernate, Spring Security and list paging</title>
		<link>http://mikemclean.ca/wp/2011/11/22/hibernate-spring-security-and-list-paging/</link>
		<comments>http://mikemclean.ca/wp/2011/11/22/hibernate-spring-security-and-list-paging/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 23:33:58 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=528</guid>
		<description><![CDATA[Of the dangers of using Spring Security, Hibernate and paging Here&#8217;s a tricky one; we need to do paging on one of our listing pages. The obvious solution was the following, which is a common pattern: @Secured(value={Roles.PERSON_READ}) public List&#60;Person&#62; getPeople(int offset, int max) { Criteria criteria = getSession().createCriteria(Person.class); criteria.setFirstResult(offset; criteria.setMaxResults(max); return criteria.list(); } Can you]]></description>
			<content:encoded><![CDATA[<p>Of the dangers of using Spring Security, Hibernate and paging</p>
<p>Here&#8217;s a tricky one; we need to do paging on one of our listing pages. The obvious solution was the following, which is a common pattern:</p>
<pre class="brush:java">
@Secured(value={Roles.PERSON_READ})
public List&lt;Person&gt; getPeople(int offset, int max) {
   Criteria criteria = getSession().createCriteria(Person.class);
   criteria.setFirstResult(offset;
   criteria.setMaxResults(max);
   return criteria.list();
}
</pre>
<p>Can you see it? The bug I mean? See it? How about now? Now?</p>
<p>The problem lies in the @Secured annotation. This little guy is SOOOOOO useful for us, but it will burn you once in a while. This annotation will proxy the method and remove any objects which you aren&#8217;t allowed to get back. i.e.: It will filter the returned list.</p>
<p>I guess you see it now: If I ask Hibernate to give me rows from 20 to 50, I am in no way garanteed to get back 30 results since Spring will remove items from my list AFTER the query has run and Hibernate has created the list.</p>
<p>The solution? I guess that really depends on your own requirements. Given our own volume and requirements, pulling out all the data on each page request is acceptable (we have a query cache enabled, so it&#8217;s not as bad as it may sound).</p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2011/11/22/hibernate-spring-security-and-list-paging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing http calls with NanoHTTPD</title>
		<link>http://mikemclean.ca/wp/2011/08/02/testing-http-calls-with-nanohttpd/</link>
		<comments>http://mikemclean.ca/wp/2011/08/02/testing-http-calls-with-nanohttpd/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 01:53:31 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=520</guid>
		<description><![CDATA[Well, we finally got tired of over engineering 2 lines of code just to make it testable. I&#8217;m talking about those classes which have some http calls done throughout some code; intermingled with maybe some error handling, some conditional logic, etc .. In other words, you want to test everything around the http call, but]]></description>
			<content:encoded><![CDATA[<p>Well, we finally got tired of over engineering 2 lines of code just to make it testable. I&#8217;m talking about those classes which have some http calls done throughout some code; intermingled with maybe some error handling, some conditional logic, etc ..</p>
<p>In other words, you want to test everything around the http call, but don&#8217;t care about the call actually being made or not. Yes, yes, yes. I know; just abstract out the call to another class, then mock that &#8230; pain in the ass! Use Spring rest template. Pain in the ass and overkill and doesn&#8217;t work well in multi threaded setups.</p>
<p>The solution we now use here is called <a href="http://elonen.iki.fi/code/nanohttpd/" target="_blank">NanoHTTPD</a> which is a tiny, tiny, miniscule http server which can easily run inside a suite of tests. It can easily be extended to intercept calls. For example, we have:</p>
<ul>
<li>A HitCountingNanoHTTPD implementation which counts how many times the server was hit (good for testing that a multi-threaded class actually does the amount of call outs you need)</li>
<li>Another implementation that given a file with key value pairs, will set the response headers using that file.</li>
</ul>
<div>We use it in the following way:</div>
<pre class="brush:java">class HttpHitTest {
     private NanoHTTPD nano;

     @Before
     public void setup() throws Exception {
          nano = new Nano(9999);
     }

     @After
     public void tearDown() throws Exception {
          nano.stop();
     }

     @Test(expected=NoSuchFileException.class)
     public void testHttpHit() {
           HttpGetClass hgc = new HttpGetClass();
           hgc.doGet("http://localhost:9999/resources/myfile.mp3");
      }
}</pre>
<p>See the beauty! NanoHTTPD simply exposes all files found in it&#8217;s working directory. So all test resources simply go into a folder inside the project and the CI server runs it without a hitch. Bonus: test performance and speeds are not affected (this thing is just so tiny).</p>
<p>As well, here&#8217;s what an extension to NanoHTTPD would look like. This example is a very simple something I whipped up to count how many times a server is hit (I needed the counter to be thread safe)</p>
<pre class="brush:java">
public class HitCountingNanoHttpd extends NanoHTTPD {
	private AtomicLong hits = new AtomicLong(0);

	public HitCountingNanoHttpd(int port) throws IOException {
		super(port);
	}

	@Override
	public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
		hits.incrementAndGet();
		return super.serve(uri, method, header, parms, files);
	}

	public long getHitCount() {
		return hits.longValue();
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2011/08/02/testing-http-calls-with-nanohttpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveMQ vs. PrimeTime</title>
		<link>http://mikemclean.ca/wp/2011/05/26/activemq-vs-primetime/</link>
		<comments>http://mikemclean.ca/wp/2011/05/26/activemq-vs-primetime/#comments</comments>
		<pubDate>Fri, 27 May 2011 01:58:58 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ActiveMQ]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=513</guid>
		<description><![CDATA[Well &#8230; what have we here. My assessment just might not be as out of line as some may have thought. Good to get a bit of validation. I may sound like I&#8217;m gloating (I sort of am, because honestly some of what happened in the back streets of this story was a bit disgraceful &#8230;), but I&#8217;m]]></description>
			<content:encoded><![CDATA[<p>Well &#8230; what have we <a href="http://goodstuff.im/activemq-not-ready-for-prime-time" target="_blank">here</a>.</p>
<p>My <a href="http://mikemclean.ca/wp/2010/12/07/activemq-not-what-it-used-to-be/" target="_blank">assessment</a> just might not be as out of line as some may have thought. Good to get a bit of validation. I may sound like I&#8217;m gloating (I sort of am, because honestly some of what happened in the back streets of this story was a bit disgraceful &#8230;), but I&#8217;m not; I find it really unfortunate. I am still of those that badly wants ActiveMQ to make it.</p>
<p>&nbsp;</p>
<p><em>Edit: Another follow up entry <a href="http://goodstuff.im/activemq-not-ready-for-prime-time-a-follow-up" target="_blank">here</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2011/05/26/activemq-vs-primetime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveMQ issues update</title>
		<link>http://mikemclean.ca/wp/2011/01/27/activemq-issues-update/</link>
		<comments>http://mikemclean.ca/wp/2011/01/27/activemq-issues-update/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 14:08:59 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=490</guid>
		<description><![CDATA[This is a follow up to a previous entry I made about problems experienced with ActiveMQ 5. First, let&#8217;s get this out of the way: I get what open source is; I get that there are a LOT of people who invest a LOT of their personal time; I get that while these people are]]></description>
			<content:encoded><![CDATA[<p><em>This is a follow up to a <a href="http://mikemclean.ca/wp/2010/12/07/activemq-not-what-it-used-to-be/" target="_blank">previous entry</a> I made about problems experienced with ActiveMQ 5.</em></p>
<p>First, let&#8217;s get this out of the way: I get what open source is; I get that there are a LOT of people who invest a LOT of their personal time; I get that while these people are working hard, I&#8217;m climbing cliffs instead of helping them even though I have the capacity and knowledge to do so; I get that criticism isn&#8217;t cool, especially when voiced publicly; and I get that I can be abrasive :).</p>
<p>With that said, in the last couple of months, we&#8217;ve worked hard to give ActiveMQ an n<em>th</em> chance. Unfortunately to no avail. The good folks at ActiveMQ have mentioned that we may be the first to use ActiveMQ the way we are. There has been a lot of effort into debugging the problem and there may be light at the end of the tunnel, but a fix is most likely a ways off.</p>
<p>The good news (for us that is), is that we have decided to keep ActiveMQ but in single broker configurations. Obviously, this is far from ideal, but all our products are currently programmed and architected around the possibility of a broker being unavailable, so we&#8217;ll keep on programming in the safeguards. I repeat: ActiveMQ is awesome in a single broker or embedded scenario.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2011/01/27/activemq-issues-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending Spring-Data to select a database index with Jedis pools</title>
		<link>http://mikemclean.ca/wp/2011/01/16/extending-spring-data-to-select-a-database-index-with-jedis-pools/</link>
		<comments>http://mikemclean.ca/wp/2011/01/16/extending-spring-data-to-select-a-database-index-with-jedis-pools/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 21:35:22 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Jedis]]></category>
		<category><![CDATA[Spring-Data]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=482</guid>
		<description><![CDATA[We came up with a not so un-common use-case of wanting to setup a Jedis connection pool that would automatically select a given database index on each connection. A colleague and I were about to patch the Spring-Data source code (we are already running a patched version), but instead found a very elegant solution by]]></description>
			<content:encoded><![CDATA[<p>We came up with a not so un-common use-case of wanting to setup a Jedis connection pool that would automatically select a given database index on each connection. A colleague and I were about to patch the Spring-Data source code (we are already running a patched version), but instead found a very elegant solution by digging in a bit more:</p>
<h2>The problem</h2>
<p>The spring-data org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory class offers no way to configure it to use a specific database. It defaults to database index 0 (in other words, does nothing on a new connection &#8211; so Redis automatically works on index 0).</p>
<p>Given that we will be running automated integration tests on a single Redis server instance, and that those tests will flush the database on each run (i.e.: select 2; flushdb), we needed an easy way to get a new connection factory instance that would first select the configured database index when a connection is created.</p>
<p>Without that database index selection, any integration tests running concurrently would flush or interfere with the data of the other running tests.</p>
<h2>The solution</h2>
<p>We simply extended the org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory class and overrode the fetchJedisConnector() protected method:</p>
<pre class="brush:java">public class MyCustomJedisConnectionPoolFactory extends JedisConnectionFactory {

private static final int DEFAULT_REDIS_DATABASE_INDEX = 0;

private int databaseIndex = 0;

@Override

protected Jedis fetchJedisConnector() {

Jedis jedis = super.fetchJedisConnector();

if (this.databaseIndex != DEFAULT_REDIS_DATABASE_INDEX) {

jedis.select(this.databaseIndex);

}

return jedis;

}

public void setDatabaseIndex(int databaseIndex) {

this.databaseIndex = databaseIndex;

}

}</pre>
<p>The if statement isn&#8217;t strictly necessary in the fetchJedisConnector() method, but given that most of the time we will be using the default database, it seemed like it was worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2011/01/16/extending-spring-data-to-select-a-database-index-with-jedis-pools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joda Time if you appreciate a good quality of life</title>
		<link>http://mikemclean.ca/wp/2010/12/07/joda-time-if-you-appreciate-a-good-quality-of-life/</link>
		<comments>http://mikemclean.ca/wp/2010/12/07/joda-time-if-you-appreciate-a-good-quality-of-life/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 23:22:53 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Joda]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=475</guid>
		<description><![CDATA[I&#8217;ve had it! When I go out clubbing and hit on women, one of the things that invariably comes up in the conversation is which date library I code to when using my made skillz in Java. Word to the wise: Do NOT answer that you use the Java Date or Calendar classes. Too many]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had it! When I go out clubbing and hit on women, one of the things that invariably comes up in the conversation is which date library I code to when using my made skillz in Java.</p>
<p>Word to the wise: Do NOT answer that you use the Java Date or Calendar classes. Too many times have women straight out told me that I was a looser with no self respect because of that answer.</p>
<p>I&#8217;m now at a point where I use exclusively <a href="http://joda-time.sourceforge.net/" target="_blank">Joda Time</a>. And you should to. No bullshit formatting, date math and time zones. Add to that great documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2010/12/07/joda-time-if-you-appreciate-a-good-quality-of-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HornetQ dynamic destination creation and references through Spring</title>
		<link>http://mikemclean.ca/wp/2010/12/07/hornetq-dynamic-destination-creation-and-references-through-spring/</link>
		<comments>http://mikemclean.ca/wp/2010/12/07/hornetq-dynamic-destination-creation-and-references-through-spring/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 19:45:21 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HornetQ]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=465</guid>
		<description><![CDATA[As per my last post, we are currently looking into migrating from ActiveMQ towards HornetQ. One of the missing features which we used and depend on are dynamic queues and topics. Our main goal is to avoid touching any java code and depend solely on Spring configuration changes. Non dynamic destination configuration through spring &#60;bean]]></description>
			<content:encoded><![CDATA[<p>As per my last post, we are currently looking into migrating from ActiveMQ towards HornetQ. One of the missing features which we used and depend on are dynamic queues and topics. Our main goal is to avoid touching any java code and depend solely on Spring configuration changes.</p>
<p><strong><span style="text-decoration: underline;">Non dynamic destination configuration through spring</span></strong></p>
<pre class="brush:xml">&lt;bean name="myDestination" class="org.hornetq.api.jms.HornetQJMSClient" factory-method="createQueue"&gt;
   &lt;constructor-arg index="0" value="ExampleQueue"/&gt;
&lt;/bean&gt;
&lt;bean name="jmsTemplate"&gt;
   &lt;property name="connectionFactory" ref="connectionFactory"/&gt;
   &lt;property name="defaultDestination" ref="myDestination"/&gt;
&lt;/bean&gt;</pre>
<p>In the above example, the queue TestQueue will already need to be defined on your HornetQ server.</p>
<p><strong><span style="text-decoration: underline;">Dynamic creation through a Spring FactoryBean implementation</span></strong></p>
<p>Using a simple FactoryBean implementation and the HornetQ management api, we can achieve dynamic destination creation.</p>
<pre class="brush:xml">&lt;bean name="myDestination" class="com.mikem.HornetQueueFactory"&gt;
   &lt;property name="name" value="TestQueue"/&gt;
&lt;/bean&gt;
&lt;bean name="jmsTemplate"&gt;
   &lt;property name="connectionFactory" ref="connectionFactory"/&gt;
   &lt;property name="defaultDestination" ref="myDestination"/&gt;
&lt;/bean&gt;</pre>
<p>Notice the different class used to define the myDestination bean. This is a simple implementation of a Spring FactoryBean.</p>
<pre class="brush:java"> public class HornetQueueFactory implements FactoryBean {
	private String name;

	@Override
	public Class getObjectType() {
		return Queue.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Queue getObject() throws Exception {
		boolean created = false;

        ObjectName on = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();
        JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1097/jmxrmi"), new HashMap());
        MBeanServerConnection mbsc = connector.getMBeanServerConnection();
        JMSServerControl serverControl = (JMSServerControl)MBeanServerInvocationHandler.newProxyInstance(mbsc, on, JMSServerControl.class, false);

        String[] queueNames = serverControl.getQueueNames();
        if (!ArrayUtils.contains(queueNames, this.name)){
        	created = serverControl.createQueue(name);
        	System.out.println("Created new queue with name " + name);
        } else {
        	created = true;
        }

        if (!created) {
        	throw new RuntimeException("Queue isn't created. Not sure why.");
        }

        return HornetQJMSClient.createQueue(name);
	}

	@Required
	public void setName(String name) {
		this.name = name;
	}}</pre>
<p>Notes:</p>
<ul>
<li>JMX/RMI needs to be configured and on for this to work</li>
<li>Obviously, this is a naive implementation only used to see if it could be done.</li>
<li>Once it&#8217;s all cleaned up, I will probably use a single factory for both Queues and Topics</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2010/12/07/hornetq-dynamic-destination-creation-and-references-through-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveMQ &#8211; not what it used to be?</title>
		<link>http://mikemclean.ca/wp/2010/12/07/activemq-not-what-it-used-to-be/</link>
		<comments>http://mikemclean.ca/wp/2010/12/07/activemq-not-what-it-used-to-be/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 17:39:46 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=459</guid>
		<description><![CDATA[I&#8217;ve posted a quick update to this here. When I started this job a couple years ago, we were mildly invested in ActiveMQ with a single queue for some mission critical work. Since I&#8217;d had good experience with ActiveMQ 4.x in previous jobs, I didn&#8217;t hesitate to push forward and suggest we invest more in]]></description>
			<content:encoded><![CDATA[<p><em>I&#8217;ve posted a quick update to this <a href="http://mikemclean.ca/wp/2011/01/27/activemq-issues-update/" target="_blank">here</a>.</em></p>
<p>When I started this job a couple years ago, we were mildly invested in ActiveMQ with a single queue for some mission critical work. Since I&#8217;d had good experience with ActiveMQ 4.x in previous jobs, I didn&#8217;t hesitate to push forward and suggest we invest more in ActiveMQ and architect solutions around it&#8217;s usage.  After all, I had experienced flawless performance and up time with 4.x.</p>
<p>Forward 2 years: We now have 30 or so topics and queues with moderate usage and it&#8217;s incapable of staying up more than a few minutes when configured as a network of brokers.</p>
<p>We&#8217;ve gone so far as paying the big bucks to get consulting from the folks at FuseSource. Unfortunately, the suggestions and help have been &#8230; uh &#8230; expensive with no results at all.</p>
<p><strong>The setup</strong></p>
<p>The setup is relatively straightforward:</p>
<ul>
<li>3 brokers in different cities in different countries which need to work as a network of brokers.</li>
<li>Latency can be high (80ms)</li>
<li>Java clients using the client libraries over the tcp protocol</li>
<li>C++ clients using the ActiveCPP library</li>
<li>A few dozen topics and queues</li>
<li>No big messages (5MB max with the average being closer to a few hundred k)</li>
<li>Moderate traffic (a few hundred thousand messages per day overall)</li>
</ul>
<p>Everything performs well enough in a single broker setup, but that&#8217;s un-acceptable for us.</p>
<p><strong>What was done</strong></p>
<p>Pretty much everything :)</p>
<p>Our expert had us upgrade to the latest version (5.4.2) with horrendous results; the KahaDB would continuously corrupt. Let me say this about trying to fix a basic problem with a minor upgrade: It&#8217;s bullshit. If version 5.4.1 can&#8217;t do something as straightforward as we&#8217;re trying to do, some suggestion about upgrading a point release isn&#8217;t going to do anything.(<em>edit: The language was harsh. As it turns out, the minor upgrade was to adress another issue and not the network of brokers issue).</em> And don&#8217;t be mistaken; our usage is basic and reasonable and definitely falls into the advertised set of features touted by ActiveMQ.</p>
<p><strong>What&#8217;s next</strong></p>
<p>We&#8217;re throwing all our weight behind JBoss HornetQ right now. The team is pretty psyched because they&#8217;re all fed up and disillusioned with the ActiveMQ product. Obviously, the migration path will not be easy, but at least we should no more be prisoner to a buggy product. (<em>edit: Again, harsh: I&#8217;d say &#8216;prisoner to a product that doesn&#8217;t work in our configuration&#8217;)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2010/12/07/activemq-not-what-it-used-to-be/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unit vs. Integration vs. Functional testing</title>
		<link>http://mikemclean.ca/wp/2010/11/06/unit-vs-integration-vs-function-testing/</link>
		<comments>http://mikemclean.ca/wp/2010/11/06/unit-vs-integration-vs-function-testing/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 21:31:01 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/?p=428</guid>
		<description><![CDATA[In a recent conversation with a colleague we discussed where the line was drawn between types of tests. Unit tests Unit tests usually won&#8217;t cross the boundaries of a class. There are definitely times when it&#8217;s acceptable, but generally speaking, you would almost always inject any dependencies as mock objects. Integration tests Integration tests will]]></description>
			<content:encoded><![CDATA[<p>In a recent conversation with a colleague we discussed where the line was drawn between types of tests.</p>
<p><a href="http://mikemclean.ca/wp/wp-content/uploads/2010/11/testing.png"><img class="size-full wp-image-429 alignnone" title="testing" src="http://mikemclean.ca/wp/wp-content/uploads/2010/11/testing.png" alt="" width="453" height="339" /></a></p>
<p><strong>Unit tests</strong></p>
<p>Unit tests usually won&#8217;t cross the boundaries of a class. There are definitely times when it&#8217;s acceptable, but generally speaking, you would almost always inject any dependencies as mock objects.</p>
<p><strong>Integration tests</strong></p>
<p>Integration tests will take one (or more classes) <em>inside the same component/functionality</em> and test those together. At this point, I have no problem crossing the file system boundary, but I would hesitate to go to a database or send messages to a broker (for example)</p>
<p><strong>Functional tests</strong></p>
<p>Puts a whole system to the test and usually will use most of it&#8217;s external dependencies (DB, JMS, &#8230;). A functional test will check that the system and data flow is ok.</p>
<p><strong>For example</strong></p>
<p>At work, we&#8217;ve grouped together to work on a complex Camel route that includes many processors, daos, file system operations, etc &#8230; I&#8217;ve tasked myself with writing the message writing component, specifically the component that receives messages and writes them to disk (Yes! I&#8217;m aware that Camel has this, but ours needs to be much more custom).</p>
<p>My message writer looks something like this:</p>
<div id="attachment_430" class="wp-caption alignnone" style="width: 375px"><a href="http://mikemclean.ca/wp/wp-content/uploads/2010/11/classes.png"><img class="size-full wp-image-430 " title="classes" src="http://mikemclean.ca/wp/wp-content/uploads/2010/11/classes.png" alt="" width="365" height="222" /></a><p class="wp-caption-text">(Obviously, much more complex, but this will do for examples sake)</p></div>
<p>I have 2 unit test clases:</p>
<ul>
<li>One for the factory class. In the unit tests, the factory builds mock MessageWriter instances.</li>
<li>Another for the MessageWriter class. This class has a FileSystemWriter instance injected so that I can actually get full test coverage. Without its, my unit tests would have crossed the file system boundary. This injected dependency allows me to replace it in unit tests with a mock.</li>
<li>FileSystemWriter isn&#8217;t unit tested &#8230; This is left up to the integration tests</li>
</ul>
<p>As for integration tests, we use Spring. So in another suite of JUnit tests, I use the actual Spring context with test properties, and run the whole component. Obviously, assertions are much more complicated as I need to go to the file system and read file content to ensure all is good.</p>
<p>This very loosely coupled system gives the team members a tremendous amount of confidence, flexibility and autonomy while developing their own components; they need only a smart interface describing the component, and they can develop in complete isolation.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2010/11/06/unit-vs-integration-vs-function-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading &#8216;The 21 Irrefutable Laws of Leadership&#8217;</title>
		<link>http://mikemclean.ca/wp/2010/10/01/reading-the-21-irrefutable-laws-of-leadership/</link>
		<comments>http://mikemclean.ca/wp/2010/10/01/reading-the-21-irrefutable-laws-of-leadership/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 02:25:29 +0000</pubDate>
		<dc:creator>mikem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikemclean.ca/wp/2010/10/01/reading-the-21-irrefutable-laws-of-leadership/</guid>
		<description><![CDATA[Firstly, the use of the word &#8216;Irrefutable&#8217; given a subject mater that is so subjective seems a bit odd. Second, the atheist in me gets easily annoyed at a book that uses pastors and churches in examples &#8230; But I&#8217;ll stick to it until the end :)]]></description>
			<content:encoded><![CDATA[<p>Firstly, the use of the word &#8216;Irrefutable&#8217; given a subject mater that is so subjective seems a bit odd.</p>
<p>Second, the atheist in me gets easily annoyed at a book that uses pastors and churches in examples &#8230; </p>
<p>But I&#8217;ll stick to it until the end :)</p>
]]></content:encoded>
			<wfw:commentRss>http://mikemclean.ca/wp/2010/10/01/reading-the-21-irrefutable-laws-of-leadership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

