<?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>Morris &#34;Mojo&#34; Jones &#187; Spring</title>
	<atom:link href="http://mojo.whiteoaks.com/tag/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://mojo.whiteoaks.com</link>
	<description>Code Monkey, Astronomer, Photographer, Bridge Player</description>
	<lastBuildDate>Mon, 31 Oct 2011 01:03:48 +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>Finding the test that corrupts the suite</title>
		<link>http://mojo.whiteoaks.com/2010/04/27/finding-the-test-that-corrupts-the-suite/</link>
		<comments>http://mojo.whiteoaks.com/2010/04/27/finding-the-test-that-corrupts-the-suite/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 16:59:03 +0000</pubDate>
		<dc:creator>Morris Jones</dc:creator>
				<category><![CDATA[Software and Systems]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[unit tests]]></category>

		<guid isPermaLink="false">http://mojo.whiteoaks.com/?p=424</guid>
		<description><![CDATA[<p>(Finally a tech blog post &#8230;)</p>
<p>Stop me if you&#8217;ve heard this one before!  </p>
<p>The web application has excellent coverage in unit tests and integration tests that run continuously, but some time ago (weeks actually) some number of tests began failing with strange state errors. In our case, out of 138 test classes and 1176 tests, [...]]]></description>
			<content:encoded><![CDATA[<p>(Finally a tech blog post &#8230;)</p>
<p>Stop me if you&#8217;ve heard this one before! <img src='http://mojo.whiteoaks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The web application has excellent coverage in unit tests and integration tests that run continuously, but some time ago (weeks actually) some number of tests began failing with strange state errors. In our case, out of 138 test classes and 1176 tests, 82 would error out.</p>
<p>The errors were all strange platform related things, like:</p>
<p><code>org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC Connection found! JpaTransactionManager does not support running within DataSourceTransactionManager ...</code></p>
<p>Or:</p>
<p><code>java.lang.NoSuchMethodError: org.hibernate.cache.CacheException.</code></p>
<p>Naturally the failing tests all work when they&#8217;re run individually. Heard that one before?</p>
<p>I started out trying different combinations of tests. I could make a list of all the running test classes by grepping for &#8220;^Running &#8221; in the test output log. I started out using the maven option &#8220;-Dtest=TestClassOne,TestClassTwo,&#8230;&#8221; to try tests in different combinations. Most of the time, the erroring tests would work perfectly. When they didn&#8217;t, the errors would occur in different tests or be different errors.</p>
<p>The failure now was non-deterministic! One of the difficulties is that Maven/Surefire would run the tests in whatever order it wanted to. That approach wasn&#8217;t going to work at all.</p>
<p>From studying the Spring references a little, I understood that Spring would cache the application contexts created for unit tests in order to improve the run time of tests. Wiring up a large application is slow when it&#8217;s done once &#8212; multiply that by 138 test classes and a slow test suite becomes glacial.</p>
<p>Clearly some test class being run prior to the error tests was corrupting the cached Spring context, and ruining the downstream environment. Spring provides a <code>@DirtiesContext</code> annotation specifically to label tests that require Spring to reload the application context. The problem is finding the test doing the dirty work!</p>
<p>I needed to make the test runs deterministic &#8212; run the test classes in the same order, and start eliminating classes one at a time from the top of the order. Surefire doesn&#8217;t have a property to exclude a test on the command line, so it required editing the POM file to exclude each test class in order from the top.</p>
<p>It was a tedious task, as many hidden software problems can be. I had to keep careful track of the list of test classes, and change the <code>&lt;exclude&gt;TestClassExample&lt;/exclude&gt;</code> element for each test run. Fortunately each test run only required about two and a half minutes. After each test with one class excluded, I would examine the final result line for any change.</p>
<p>I was pretty confident that the culprit had to be an early test in the sequence, so I should only have to go about halfway through the successful test classes. Finally thirty-four classes into the list, I had my culprit.</p>
<p>Ironically enough, the test class causing all the problems was named <code>TestSpringConfigurations</code>. It had two tests that would simply verify that all of our wiring would successfully produce an application context. Marking the tests with the <code>@DirtiesContext</code> annotation made all of the following error tests run successfully.</p>
<p>Actually the @DirtiesContext annotation wasn&#8217;t necessary: The tests themselves included one fatal line: <code>context.close()</code>. By not closing the contexts after the test load, the cached application context was just fine for all the following tests.</p>
<p>One might argue that this class is pointless when run as part of a large test suite, since earlier tests have already loaded the application context. When Surefire arrives at <code>TestSpringConfigurations</code>, it is only using the already-cached context rather than loading a new one. Good point. But having the test in the suite also gives us a quick way to verify changes made to the application context configuration without running the whole set.</p>
<p>And finally the punch line: When the Spring configuration errors were finally vanquished, four test failures were revealed that were legitimately testing application code. Those test failures were completely masked by the Spring context corruption error.</p>
<p>Oh yes, that <code>TestSpringConfigurations</code> class has been in the suite for many months. Why did we only recently find it causing this corruption? No one here is quite positive, but the only major platform change we can point to is a switch from Java 5 to a Java 6 runtime. Maybe that triggered the original problem, and maybe sometime I&#8217;ll be interested enough to test that proposition.</p>
]]></content:encoded>
			<wfw:commentRss>http://mojo.whiteoaks.com/2010/04/27/finding-the-test-that-corrupts-the-suite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Spring for the Advanced Java Developer&#8221; Rod Johnson</title>
		<link>http://mojo.whiteoaks.com/2009/03/19/spring-for-the-advanced-java-developer-rod-johnson/</link>
		<comments>http://mojo.whiteoaks.com/2009/03/19/spring-for-the-advanced-java-developer-rod-johnson/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 19:41:20 +0000</pubDate>
		<dc:creator>Morris Jones</dc:creator>
				<category><![CDATA[Software and Systems]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[TheServerSide]]></category>

		<guid isPermaLink="false">http://mojo.whiteoaks.com/?p=54</guid>
		<description><![CDATA[<p>Notes from a session at TheServerSide Java Symposium March 2009</p>
<p>Rod addressed some emerging best practices based around annotation-based application configuration using Spring 2.5 and later.</p>
<p>The emerging best practice is to use the @Autowired annotation rather than @Resource. He demonstrated how to disambiguate bean references with @Qualifier. He also showed how to create your own custom annotations [...]]]></description>
			<content:encoded><![CDATA[<p><em>Notes from a session at TheServerSide Java Symposium March 2009</em></p>
<p>Rod addressed some emerging best practices based around annotation-based application configuration using Spring 2.5 and later.</p>
<p>The emerging best practice is to use the @Autowired annotation rather than @Resource. He demonstrated how to disambiguate bean references with @Qualifier. He also showed how to create your own custom annotations and use them to disambiguate similar types:</p>
<p><code>@Autowired<br />
public void setOrderServices(@Emea OrderService emea, @Apac OrderService apac) { ... }</code></p>
<p><code>@Emea<br />
public class EmeaOrderService implements OrderService { ... }</code></p>
<p><code>@Apac<br />
public class ApacOrderService implements OrderService { ... }</code></p>
<p>(What was unclear to me at the time is whether or not these custom annotations required some definition elsewhere, but I&#8217;m not entirely conversant on how annotations work.)</p>
<p>He also spent some time on the @Component meta-annotation, and the concept of stereotypes.  Spring comes with several pre-configured stereotypes:</p>
<ul>
<li>@Service</li>
<li>@Repository</li>
<li>@Aspect</li>
<li>@Controller</li>
</ul>
<p>It&#8217;s a powerful concept.</p>
<p>So here&#8217;s the big question for me. Why are we configuring with annotations now? It doesn&#8217;t do away with the need for context XML files. He indeed mentioned the pros and cons for using Spring 2.5 annotations:</p>
<p>Component scanning pros:</p>
<ul>
<li>No need for XML (potentially)</li>
<li>Changes picked up automatically</li>
<li>Works great with annotation driven injection</li>
<li>Highly configurable (whatever that means)</li>
</ul>
<p>Component scanning cons:</p>
<ul>
<li>Not a 100% solution (can&#8217;t do everything with annotations)</li>
<li>Requires classes to be maintained</li>
<li>Need to take care not to scan an excessive number of classes (use filtering)</li>
<li>Don&#8217;t get valuable application blueprints documented in application XML</li>
</ul>
<p>He makes a decent case for mixing and matching XML configuration with annotation configuration.</p>
<p>The emerging best practices (he says) include:</p>
<ul>
<li>Use XML for classes that you can&#8217;t or won&#8217;t annotate, such as third party components (data sources, message queues)</li>
<li>Use annotations and classpath scanning for application objects</li>
<li>Jump into XML for complex injection behavior and per-instance configuration (like injecting lists and maps)</li>
</ul>
<p>He suggests the Spring Web Flow example application for examples.</p>
<p>He recommends moving away from the old Spring MVC inheritance model in favor of the @Controller stereotype. (Need to go back to his slides for other recommendations.)</p>
<p>The rest of the presentation covered features coming up in Spring 3.0. One nice feature is the ability to embed property value injection with a @Value annotation and a new expression language. Example:</p>
<p><code>@Value("#{systemProperties.favoriteColr}")<br />
private String favoriteColor;</code></p>
<p><code>@Autowired<br />
public void init(@Value("{systemProperties.databaseName") String dbName)</code></p>
<p>I was happy to see this presentation, because I&#8217;ve really been resistant to using annotation based configuration and component scanning. I do like the XML blueprint for an application, and I like having one place to look for how my application is configured. (I even try to avoid using multiple application context XML files, which avoids having to hunt through several files to find my bean configuration.)</p>
<p>Things that happen by magic like autowiring make me a little uncomfortable. He pointed out that the Spring IDE is a good practical solution for actually browsing through your app configuration.</p>
]]></content:encoded>
			<wfw:commentRss>http://mojo.whiteoaks.com/2009/03/19/spring-for-the-advanced-java-developer-rod-johnson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;How Spring Fits into the Java Landscape&#8221; Rod Johnson</title>
		<link>http://mojo.whiteoaks.com/2009/03/19/how-spring-fits-into-the-java-landscape-rod-johnson/</link>
		<comments>http://mojo.whiteoaks.com/2009/03/19/how-spring-fits-into-the-java-landscape-rod-johnson/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 18:28:59 +0000</pubDate>
		<dc:creator>Morris Jones</dc:creator>
				<category><![CDATA[Software and Systems]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[TheServerSide]]></category>

		<guid isPermaLink="false">http://mojo.whiteoaks.com/?p=50</guid>
		<description><![CDATA[<p>Notes from TheServerSide Java Symposium March 2009</p>
<p>At a keynote talk, you expect sweeping generalizations and &#8220;big picture&#8221; insights.</p>
<p>Rod pointed out some things that I have watched happening over the past two decades, namely the rise and fall of complex monolithic software systems as an expensive luxury that falls in favor of simplicity along with economic cycles.</p>
<p>&#8220;Enterprise [...]]]></description>
			<content:encoded><![CDATA[<p><em>Notes from TheServerSide Java Symposium March 2009</em></p>
<p>At a keynote talk, you expect sweeping generalizations and &#8220;big picture&#8221; insights.</p>
<p>Rod pointed out some things that I have watched happening over the past two decades, namely the rise and fall of complex monolithic software systems as an expensive luxury that falls in favor of simplicity along with economic cycles.</p>
<p>&#8220;Enterprise Java&#8221; has a reputation for complexity, based on the early (failed) J2EE platform, and giant enterprise software systems like those from IBM and BEA. &#8220;Complexity is the single biggest killer of projects,&#8221; he says. I concur.</p>
<p>&#8220;Economic downturns reduce software complexity. Truly bad ideas need a booming economy to survive.&#8221; I never thought of it like that, but it should have been obvious.</p>
<p>Service Oriented Architecture (SOA) is one of those complex frameworks that he claims is doomed at this point.</p>
<p>So the movement now is to &#8220;lean software,&#8221; simpler modular systems that don&#8217;t try to solve every problem but focus on doing one or two things well.</p>
<p>His examples, past giants of complexity: IBM, BEA, Sun. Today&#8217;s leaders: Spring, Hibernate, Ruby on Rails, Django, Grails, Eclipse ecosystem.</p>
<p>In terms of business management, this means that companies move away from the large portfolio software solutions that require huge quantities of support and complexity. The movement is toward point solutions that are smaller and more targeted. This is a pendulum that directly follows the economic cycle.</p>
<p>Nicely done.</p>
]]></content:encoded>
			<wfw:commentRss>http://mojo.whiteoaks.com/2009/03/19/how-spring-fits-into-the-java-landscape-rod-johnson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

