<?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>ALTERthought Blogs &#187; Persistence</title>
	<atom:link href="http://alterlabs.com/category/technologies/persistence/feed/" rel="self" type="application/rss+xml" />
	<link>http://alterlabs.com</link>
	<description>Results through imagination</description>
	<lastBuildDate>Tue, 13 Apr 2010 19:19:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grails Testing Tip (DO&#8217;s, DONT&#8217;s and DOH&#8217;s): Fixture Data vs. Dependent Data</title>
		<link>http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-fixture-data-vs-dependent-data/</link>
		<comments>http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-fixture-data-vs-dependent-data/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 13:16:13 +0000</pubDate>
		<dc:creator>don</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Groovy/Grails]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-fixture-data-vs-dependent-data/</guid>
		<description><![CDATA[DO: Distinguish between Fixture Data and Dependent Data
Integration testing can be painful enough under the best of circumstances. Confusion around where data comes from, when it should be deleted, rolled back or committed can derail the even the best laid plans.  (This is especially true in more complicated projects that involve multiple datasources, that [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: larger"><strong>DO</strong>: Distinguish between Fixture Data and Dependent Data</span></p>
<p><a href="http://grails.org/doc/1.0.x/guide/9.%20Testing.html#9.2%20Integration%20Testing">Integration</a> testing can be painful enough under the best of circumstances. Confusion around where data comes from, when it should be deleted, rolled back or committed can derail the even the best laid plans.  (This is especially true in more complicated projects that involve multiple datasources, that are managed outside the GORM.)</p>
<p>To better manage testing, we (<a href="http://www.alterthought.com">ALTERthought</a>) classify the persistent data to be used in our integration tests into two categories: <em>Fixture Data</em> and<em> Dependent Data &#8230;</em></p>
<p><span id="more-98"></span></p>
<p><strong><em>Fixture Data</em></strong> is data that is pertinent to the test case in particular. Data is considered to be Fixture Data if the following core conditions are true:</p>
<ul>
<li>The data is represented by a Domain Object in your system</li>
<li>The data is writable (create/update/delete)</li>
</ul>
<p>Fixture Data should be provisioned in one of the following ways:</p>
<ol>
<li>Through a provisioning tool like <a href="http://www.dbunit.org/">DBUnit</a></li>
<li>Explicitly in the TestCase setUp()</li>
</ol>
<blockquote><p>NOTE: The decision as to whether we  provision data using a tool like DBUnit or &#8216;locally&#8217; in the TestCase setUp() is largely based on the complexity of Domain relationships. The more complicated the Domain Object graph, the more likely we are to use DBUnit to set up the data relationships. This has proven particularly true on projects where we must integrate with legacy databases that are highly normalized, and/or we have multiple datasources.  Test fixtures for simple data can easily be provisioned in the setUp() method.</p></blockquote>
<p>Upon test case completion, any Fixture Data that was added to the system should be removed, leaving the database in a clean state (see <a href="http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-the-clean-slate-principle/">The Clean Slate Principle</a>), containing only Dependent Data. Data should be removed in one of the following ways:</p>
<ol>
<li>Through DBUnit processing</li>
<li>In the TestCase tearDown()</li>
<li>As part of the transactional TestCase rollback</li>
</ol>
<blockquote><p>NOTE: It is generally discouraged to explicitly remove the Dependent Data in the test method themselves! Unexpected test case errors can leave your DB in an unstable state with partially populated data.</p></blockquote>
<p><strong><em>Dependent Data</em></strong> is data that must be present in order for your test environment to simulate the real world, but is largely tangential to the test cases at hand. Ex: A code table containing the 50 US states, valid zip codes, etc.</p>
<p>Data is considered dependent data if all of the following conditions are true:</p>
<ul>
<li>The data is tangential to the test cases at hand</li>
<li>The data in question is read only. Your test cases will never update or delete the data in question.</li>
<li>The data can safely live in the DB between test cases.</li>
</ul>
<p>Dependent data should be provisioned in SQL scripts that are run prior to any tests as part of the environment setup. Once it has been provisioned it need not be re-provisioned for every individual test case.</p>
<p>OK, that&#8217;s it! It may seem like obvious advice, but establishing a few simple rules can go a long way towards making testing of your next Grails app much less painful.  Subsequent posts will talk a bit about using tools like dbunit to help achieve your testing goals, testing with multiple datasources, as well as advice/hints on testing the various components of a Grails app.<br /><p>Technorati Tags: <a href="http://technorati.com/tag/grails+tests" rel="tag"> grails tests</a>, <a href="http://technorati.com/tag/integration+testing" rel="tag">  integration testing</a>, <a href="http://technorati.com/tag/unit+testing" rel="tag"> unit testing </a></p>
<hr /> <span style="font-size: 11px">This entry is part of a series on testing standards and advice that we (<a href="http://www.alterthought.com">ALTERthought</a>) have found useful as part of our Grails development initiatives.</span></p>
   ]]></content:encoded>
			<wfw:commentRss>http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-fixture-data-vs-dependent-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails Testing Tip (DO&#8217;s, DONT&#8217;s and DOH&#8217;s): The Clean Slate Principle</title>
		<link>http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-the-clean-slate-principle/</link>
		<comments>http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-the-clean-slate-principle/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 14:58:20 +0000</pubDate>
		<dc:creator>don</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Groovy/Grails]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Persistence]]></category>
		<category><![CDATA[Technology/Technical Approaches]]></category>

		<guid isPermaLink="false">http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-the-clean-slate-principle/</guid>
		<description><![CDATA[DO: Follow the Clean Slate Principle
Its happened to all of us, a test that was working just fine, suddenly starts failing because the test database was left in an unstable state. Enter the Clean Slate Principle.
Grails integration tests should endeavor to follow a simple rule:

Leave the database in the state in which you found it.
In [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: larger"><strong>DO</strong>: Follow the <em>Clean Slate Principle</em></span></p>
<p>Its happened to all of us, a test that was working just fine, suddenly starts failing because the test database was left in an unstable state. Enter the <em>Clean Slate Principle</em>.</p>
<p>Grails <a href="http://grails.org/doc/1.0.x/guide/9.%20Testing.html#9.2%20Integration%20Testing">integration</a> tests should endeavor to follow a simple rule:</p>
<blockquote><p>
<em>Leave the database in the state in which you found it.</em></p></blockquote>
<p>In other words, if your tests perform <em>any</em> write operations on your datasource(s) (Create/Update/Delete) they are responsible for undoing said operation upon test completion.  </p>
<p>This &#8216;Clean Slate Principle&#8217; applies to Test Cases as a we as Test Methods within Test Cases&#8230; i.e., if a Test Method inserts a row into the DB as part of a test, it should be removed upon completion (regardless of success or failure).</p>
<p>Subsequent posts will discuss approaches for accomplishing this, as well as the types of pre-existing test data and techniques for provisioning. Until then, keep your slate clean! </p>
<p/>
<hr /> <span style="font-size: smaller">This entry is part of a series on testing standards and advice that we (<a href="http://www.alterthought.com">ALTERthought</a>) have found useful as part of our Grails development initiatives.</span></p>
<p>Technorati Tags: <a href="http://technorati.com/tag/grails+tests" rel="tag"> grails tests</a>, <a href="http://technorati.com/tag/integration+testing" rel="tag">  integration testing</a>, <a href="http://technorati.com/tag/unit+testing" rel="tag"> unit testing </a></p>
   ]]></content:encoded>
			<wfw:commentRss>http://alterlabs.com/technologies/java/grails-testing-tip-dos-donts-and-dohs-the-clean-slate-principle/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Access denied error in MySQL</title>
		<link>http://alterlabs.com/technologies/infrastructure-design/access-denied-error-in-mysql/</link>
		<comments>http://alterlabs.com/technologies/infrastructure-design/access-denied-error-in-mysql/#comments</comments>
		<pubDate>Tue, 14 Mar 2006 03:44:49 +0000</pubDate>
		<dc:creator>Manohar Viswanathan</dc:creator>
				<category><![CDATA[How-Tos]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://alterlabs.com/mysql/access-denied-error-in-mysql/</guid>
		<description><![CDATA[Have you been frustrated with Access denied for user &#8216;chinnu&#8217;@'localhost&#8217; errors even though as root you granted following privileges:
GRANT ALL PRIVILEGES ON MyDb.* to 'chinnu'@'%' WITH GRANT OPTION;
While % means any host, you probably did not see the behavior you expected.
MySQL performs access control in two stages. First, it tries to connect you with the [...]]]></description>
			<content:encoded><![CDATA[<p>Have you been frustrated with <em>Access denied for user &#8216;chinnu&#8217;@'localhost&#8217;</em> errors even though as <em>root</em> you granted following privileges:</p>
<p><code style="color: #009900">GRANT ALL PRIVILEGES ON MyDb.* to 'chinnu'@'%' WITH GRANT OPTION;</code></p>
<p>While <strong>%</strong> means any host, you probably did not see the behavior you expected.</p>
<p>MySQL performs access control in two stages. First, it tries to connect you with the username/password provided. Next, it checks if you have the privileges to perform your request. Entries in tables <span style="font-style: italic">user</span>, <span style="font-style: italic">db </span>and <span style="font-style: italic">host </span>of <span style="font-style: italic">mysql </span>database are used for access control.</p>
<p>Lets say this is our <span style="font-style: italic">user </span>table:</p>
<pre><span style="color: #009900">----------------------------------------------</span>
<span style="color: #009900">Host      |  User</span>
<span style="color: #009900">----------------------------------------------</span>
<span style="color: #009900">%         |  root</span>
<span style="color: #009900">%         |  chinnu</span>
<span style="color: #009900">localhost |  root</span>
<span style="color: #009900">localhost |  </span>
<span style="color: #009900">----------------------------------------------</span></pre>
<p><span style="font-weight: bold">%</span> in Host means &#8216;any host&#8217; and <span style="font-weight: bold">blank </span>in User means any user or anonymous user. Note that the value <span style="font-weight: bold">%</span> is less specific when compared to value <span style="font-weight: bold">localhost</span>. MySQL, when performing access control, sorts this table with the most-specific Host at the top. So, we have something like</p>
<pre><span style="color: #009900">-----------------------------------------</span>
<span style="color: #009900">Host      |  User</span>
<span style="color: #009900">-----------------------------------------</span>
<span style="color: #009900">localhost |  root</span>
<span style="font-weight: bold; color: #009900">localhost |   </span>
<span style="font-weight: bold; color: #009900">%         |  chinnu</span>
<span style="color: #009900">%         |  root</span>
<span style="color: #009900">------------------------------------------</span></pre>
<p>When <span style="font-weight: bold">chinnu </span>tries to login from <span style="font-weight: bold">localhost</span>, there are two matching rows. Guess what, the first match wins. This means that <span style="font-weight: bold">chinnu </span>is effectively logged in as an anonymous user. The anonymous user may not have privileges for MyDb, hence the access denied errors.</p>
<p><span style="font-weight: bold">How to verify?</span><br />
If you managed to connect execute <code style="color: #009900">SELECT CURRENT_USER()</code>. If you get result as <code style="font-weight: bold">@localhost</code> and not <span style="font-weight: bold">chinnu@localhost</span>, you have the issue described above.</p>
<p><span style="font-weight: bold">How to solve this?</span><br />
Solution-1: Grant privileges for &#8216;chinnu&#8217;@'localhost&#8217; in addition to &#8216;chinnu&#8217;@'%&#8217;<br />
Solution-2: Just get rid of the anonymous user.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/mysql" rel="tag">mysql</a></p>
   ]]></content:encoded>
			<wfw:commentRss>http://alterlabs.com/technologies/infrastructure-design/access-denied-error-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
