<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0' xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>David Sowerby</title>
    <description>Author of Krail</description>
    <link>https://dsowerby.silvrback.com/feed</link>
    <atom:link href="https://dsowerby.silvrback.com/feed" rel="self" type="application/rss+xml"/>
    <category domain="dsowerby.silvrback.com">Content Management/Blog</category>
    <language>en-us</language>
      <pubDate>Tue, 15 Mar 2016 15:31:19 +0000</pubDate>
    <managingEditor>david.sowerby@virgin.net (David Sowerby)</managingEditor>
      <item>
        <guid>https://dsowerby.silvrback.com/a-small-ship-in-the-devops-sea--2#23309</guid>
          <pubDate>Tue, 15 Mar 2016 15:31:19 +0000</pubDate>
        <link>https://dsowerby.silvrback.com/a-small-ship-in-the-devops-sea--2</link>
        <title>A Small Ship in the DevOps sea</title>
        <description>Part 2 - Selecting the DevOps Tools</description>
        <content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>

<p><a href="https://dsowerby.silvrback.com/a-small-ship-in-the-devops-sea">Part 1</a> looked at some of the basic principes of DevOps and Continuous Development as they relate to small projects.</p>

<h1 id="the-starting-point">The Starting Point</h1>

<p>Currently I use:</p>

<ul>
<li>Java for development</li>
<li><a href="http://gradle.org/">Gradle</a> for build management (although not very well - this needs improvement)</li>
<li><a href="https://github.com/">GitHub</a> for issue tracking and central repo for open source projects</li>
<li><a href="https://bitbucket.org/">BitBucket</a> for issue tracking and central repo for closed source projects</li>
<li><a href="http://spockframework.github.io/spock/docs/1.0/index.html">Spock</a> for unit and integration testing</li>
<li><a href="https://travis-ci.org/">Travis CI</a> but really only to provide the &quot;passing&quot; badge ... Gradle does the work</li>
<li><a href="https://coveralls.io/">Coveralls</a> as a way of presenting coverage stats on GitHub.</li>
<li><a href="http://findbugs.sourceforge.net/">FindBugs</a> for static analysis</li>
<li><a href="https://www.docker.com/what-docker">Docker</a> to create test environments</li>
<li><a href="https://vaadin.com/add-ons/testbench">Vaadin TestBench</a> for functional testing of Vaadin apps - only useful if you use <a href="https://vaadin.com/framework">Vaadin</a> of course</li>
<li><a href="https://www.jetbrains.com/idea/download/">Intellij IDEA</a> Ultimate Edition as IDE</li>
</ul>

<p>Test coverage is generally good, and static analysis fully managed (that is, raised issues are dealt with).</p>

<p>I have a release process which generates release notes and partly automates the process, but it is a bit flaky and needs rework.  It is this which started me off on the DevOps journey.</p>

<h1 id="selecting-the-tools">Selecting the Tools</h1>

<p>This list may grow .. or change ... as I progress, but there are so many tools to choose from I need to start somewhere.</p>

<p>Some are self-selecting because I already use them and am happy with them.  Gradle, Spock and Vaadin TestBench fall into this category. (An earlier post describes my <a href="https://dsowerby.silvrback.com/spock-the-difference">experiences of Spock</a>)</p>

<p>One specific consideration is that whatever environments I need (including a build environment) should be definable as code - infrastructure &amp; Ops are definitely my weak points, so would benefit massively from automation.</p>

<ul>
<li><strong><em>Principle 5:</em></strong> Environments / infrastructure defined in code and version controlled.</li>
</ul>

<h2 id="docker">Docker</h2>

<p>At  the moment Docker is the only serious candidate to meet Principle 5.</p>

<h3 id="composing">Composing</h3>

<p>Docker compose and/or Terraform</p>

<h2 id="ci-task-orchestration">CI / task orchestration</h2>

<p>The obvious candidate is Jenkins although there are quite a few others, particularly if you include hosted services.  I do not want to incur costs at this stage though, so I am restricting the choice to installable tools, and in particular those which have a Docker image.</p>

<p>I installed Jenkins(via Docker) and that worked Ok, but I did find Jenkins quite hard to set up and in danger of conflicting with what was set up in Gradle.  </p>

<p>I will come back to this, but at the moment I am wondering whether a &quot;proper&quot; CI server is really necessary given the simple orchestration I need, and a distributed build probably unnecessary. (This assumes that Gradle is the primary tool (Principle 3 in <a href="https://dsowerby.silvrback.com/a-small-ship-in-the-devops-sea">previous post</a>))</p>

<p>On the other hand, I really do not want to be re-inventing anything.</p>

<h2 id="repository-manager">Repository Manager</h2>

<p><strong>Artifactory</strong> for artifacts through the build process<br>
<strong>Bintray</strong> for released artifacts</p>

<h1 id="lifecycle-tasks">Lifecycle tasks</h1>

<p>Given Principle 3, each step in the <a href="https://docs.google.com/drawings/d/1rwwwh1gS3BskwXDrnDsL0Cc_XdXlU1j37hu68gxyWD0">diagram</a> should have an associated Gradle task.   </p>

<ol>
<li> Trigger from Git - <strong>TBD</strong></li>
<li> Unit Tests - <strong>Spock / JUnit</strong></li>
<li> Integration Tests - <strong>Spock / JUnit</strong></li>
<li> Sonar scan - <strong>Sonar plugin</strong></li>
<li> Quality gate - <strong>coded in Gradle</strong>, using Jacoco report (experimental version looks good)</li>
<li> Sonar gate - deferred;  there are some notes on the Sonar site</li>
<li> Create build info - <strong>bespoke</strong></li>
<li> Changelog and Release Notes - <strong>GitPlus plugin</strong> - in progress</li>
<li> Push to Artifactory - <strong>Artifactory plugin</strong></li>
<li> Pull from Artifactory - <strong>Artifactory plugin</strong></li>
<li>Deploy to test - <strong>Docker plugin</strong></li>
<li>Functional test - app specific.  <strong>Vaadin TestBench</strong> for Vaadin apps</li>
<li> Pull from Artifactory - <strong>Artifactory plugin</strong></li>
<li> Deploy to UAT - <strong>Docker plugin</strong></li>
<li> UAT  - manual. <strong>Needs something</strong> to flag completion / failure</li>
<li> Pull from Artifactory - <strong>Artifactory plugin</strong></li>
<li> Tag release - <strong>GitPlus plugin</strong></li>
<li> Merge to master - <strong>GitPlus plugin</strong></li>
<li> Push master and tags to origin - <strong>GitPlus plugin</strong></li>
<li> Push to Bintray - <strong>Bintray plugin</strong></li>
<li> Deploy to Production - <strong>Docker plugin</strong></li>
</ol>

<h2 id="notes">Notes</h2>

<p>The <a href="https://github.com/davidsowerby/gitplus">GitPlus</a> plugin is currently being developed</p>
]]></content:encoded>
      </item>
      <item>
        <guid>https://dsowerby.silvrback.com/a-small-ship-in-the-devops-sea#23300</guid>
          <pubDate>Tue, 15 Mar 2016 11:32:25 +0000</pubDate>
        <link>https://dsowerby.silvrback.com/a-small-ship-in-the-devops-sea</link>
        <title>A Small Ship in the DevOps sea</title>
        <description>Part 1 - Setting out on the journey</description>
        <content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>

<p>DevOps is clearly the Big Thing of the moment in the development world.  I don&#39;t intend to describe it here, there are many good articles to do that, but what I am going to do is chronicle my own voyage of discovery and my thoughts on how DevOps could or should apply to small projects.  </p>

<p>I am hoping that will help me later to remember why I made the decisions I did (good or bad), and with luck will also help others on the same journey.</p>

<p>So if you develop smaller projects, particularly Open Source, I hope these posts may be of help to you.  Your feedback, comments and suggestions would be very welcome.</p>

<h1 id="context">Context</h1>

<p>I now write software almost full time, and most of that is open source, but in the scheme of things these are small projects.</p>

<p>In my past I have been in development roles and management roles, and worked in small and large organisations, so I have a fairly broad perspective both technically and organisationally.  At heart, though, I am a developer.  The Ops part is the scary part!</p>

<h1 id="aim">Aim</h1>

<p>Like most developers, I want to be achieve:</p>

<ul>
<li>A rapid release cycle for the benefit of end users, while developing and maintaining a reliable system</li>
<li>The highest possible proportion of effort is applied to developing for end user benefit (which simply means automating as much as possible)</li>
</ul>

<p>In my case, end users could be other developers (if I am producing an open source component) or real users (for cloud hosted solutions).</p>

<h2 id="devops-or-continuous-delivery">DevOps or Continuous Delivery?</h2>

<p>There is so much overlap between DevOps and  Continuous Delivery I wondered whether I was actually using the wrong terminology.  This <a href="http://workingwithdevs.com/devops-vs-continuous-delivery/">excellent blog</a> helped me make up my mind.  It is worth reading the whole blog, but this for me was the conclusive statement: </p>

<blockquote>
<p>DevOps starts with manufacturing principles and a pragmatic understanding of human and team behaviour. Continuous delivery starts with academic and scientific principles.</p>
</blockquote>

<p>On that basis, I am going with the DevOps label, simply because I recognise it as the kind of pragmatic approach I am familiar  with.  On the other hand, anything I can take from Continuous Delivery will be enthusiastically included!</p>

<h1 id="practical-principles">Practical Principles</h1>

<p>After saying I would use the DevOps label, I watched this Continuous Delivery <a href="https://www.youtube.com/watch?v=V0FpbDkKYtA">video</a> from the Gradle team.  It is an excellent resource if you use Gradle, and useful even if you do not - the discussion of the pipeline is valuable on its own.</p>

<p>The video was incredibly useful in describing some principles based on vast amounts of practical experience.  </p>

<h2 id="which-branch">Which branch?</h2>

<p>The generally recommended Continuous Delivery approach seems to be to merge and deploy from the master branch, and then treat any failures in the &#39;master&#39; build as highest priority.  That is probably good for enterprise projects, but does not suit my circumstances well.</p>

<p>It makes the &#39;master&#39; unstable - and I would rather that the master branch in my public repos are always stable.  I will therefore only merge <em>releases</em> to the master branch.</p>

<p><a id='principle1'> </a><br>
* <strong><em>Principle 1</em></strong>: Use the develop branch for build, merge and test.  Treat the &#39;master&#39; branch as a release into production</p>

<p>As a side effect, that means the default branch for my public repos must be &#39;develop&#39;, so that Pull Requests are from  &#39;develop&#39;.  I really must do that!</p>

<p>It also means that:</p>

<p><a id='principle2'> </a><br>
* <strong><em>Principle 2</em></strong> Every commit (to &#39;develop&#39;) should be fit for release.  </p>

<p>Standard CD practice, and fits well. The decision to release may be manual, but the idea is that the commit should be of sufficient quality to be released.</p>

<h2 id="overlapping-tools">Overlapping tools</h2>

<p>There is a massive overlap between, for example, Gradle and Jenkins (or any other CI server).  Both have an enormous range of plugins, often achieving the same thing. That could easily get confusing, so one or other should take precedence.</p>

<p>I have elected to treat Gradle as the dominant player - I found Jenkins a bit confusing to use, but the main reason is that Gradle is naturally code driven (and therefore testable and under version control).  </p>

<p><a id='principle3'> </a><br>
* <strong><em>Principle 3</em></strong>:  Gradle is treated as the primary tool for the lifecycle pipeline, in the sense that the tasks are all defined in Gradle.  The lifecycle process (the order of task execution) may become the province of the CI Server.</p>

<p>Of course, a fully-fledged CI Server will do a lot more than that, particularly for distributed builds, but we will see how this principle stands up.</p>

<h1 id="defining-the-lifecycle">Defining the Lifecycle</h1>

<p>My <a href="https://docs.google.com/drawings/d/1rwwwh1gS3BskwXDrnDsL0Cc_XdXlU1j37hu68gxyWD0">first cut at defining the lifecycle</a> is little different from the <a href="https://www.youtube.com/watch?v=V0FpbDkKYtA">video</a>  above - there&#39;s no point in reinventing well tested wheels.</p>

<p><a id='principle4'> </a><br>
* <strong><em>Principle 4</em></strong>:  A single lifecycle definition with optional steps is easier to understand and maintain</p>

<p>It seems probably that this can be achieved   - for example, some small projects will not need integration testing, but it is better to have that as an optional step than a different lifecycle.  Of course, a complex standard lifecycle with masses of optional steps would be a poor idea!</p>

<h1 id="next-steps">Next Steps</h1>

<p>That is enough for one post ... the next will be looking at the plethora of tools available and trying to select just those which would serve my needs.</p>
]]></content:encoded>
      </item>
      <item>
        <guid>https://dsowerby.silvrback.com/spock-the-difference#23229</guid>
          <pubDate>Sat, 12 Mar 2016 13:15:35 +0000</pubDate>
        <link>https://dsowerby.silvrback.com/spock-the-difference</link>
        <title>Spock the Difference</title>
        <description>Spock vs AssertJ/Mockito</description>
        <content:encoded><![CDATA[<h1 id="back-to-testing">Back to Testing</h1>

<p>It is quite a while ago since I blogged about testing (or about anything else ...) but my last post on the subject  concluded that AssertJ was the best option, for me at least.</p>

<p>I was using AssertJ with Mockito and the Mycila runner to support Guice. I was generally happy with that combination, although there were one or two odd syntactical problems in the transition from Java 7 to 8.</p>

<p>And then there was <a href="http://spockframework.github.io/spock/docs/1.0/index.html">Spock</a>.</p>

<h2 id="first-thoughts">First thoughts</h2>

<p>I&#39;m not even sure why I tried Spock in the first place - I didn&#39;t think there was anything especially wrong with the libraries I was using.</p>

<p>I also have to admit I am not a huge fan of Groovy in itself, although I am using Gradle (also written in Groovy of course) more and more.  The power of Groovy, though, is when it is used to provide a well designed DSL.</p>

<p>Spock demonstrates this really well, so I gave it a try ... this post is a quick overview of my experience, based on several months of use.  I am not trying to cover all of Spock&#39;s functionality here, but I can say that I have not found anything yet which the AssertJ/Mockito combination could do that Spock cannot do.</p>

<h2 id="the-classic-approach">The &quot;classic&quot; approach</h2>

<p>Using the AssertJ/Mockito approach, a trivial test might look like this</p>
<div class="highlight"><pre><span></span><span class="nd">@Test</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">doTest</span><span class="o">()</span> <span class="o">{</span>

    <span class="c1">//given</span>
    <span class="n">objectUnderTest</span><span class="o">.</span><span class="na">prepare</span><span class="o">(</span><span class="mi">5</span><span class="o">);</span>
    <span class="n">when</span><span class="o">(</span><span class="n">mockCollaborator</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()).</span><span class="na">thenReturn</span><span class="o">(</span><span class="s">&quot;x&quot;</span><span class="o">);</span>

    <span class="c1">//when    </span>
    <span class="n">objectUnderTest</span><span class="o">.</span><span class="na">doSomething</span><span class="o">();</span>

    <span class="c1">//then</span>
    <span class="n">assertThat</span><span class="o">(</span><span class="n">objectUnderTest</span><span class="o">.</span><span class="na">getState</span><span class="o">()).</span><span class="na">isEqualTo</span><span class="o">(</span><span class="s">&quot;OK&quot;</span><span class="o">);</span>
    <span class="n">assertThat</span><span class="o">(</span><span class="n">objectUnderTest</span><span class="o">.</span><span class="na">isActive</span><span class="o">()).</span><span class="na">isTrue</span><span class="o">();</span>
    <span class="n">verify</span><span class="o">(</span><span class="n">mockCollaborator</span><span class="o">,</span> <span class="n">times</span><span class="o">(</span><span class="mi">2</span><span class="o">)).</span><span class="na">getStatus</span><span class="o">();</span>
<span class="o">}</span>
</pre></div>
<h2 id="the-spock-approach">The Spock approach</h2>

<p>The equivalent in Spock would look like this:</p>
<div class="highlight"><pre><span></span><span class="kt">def</span> <span class="s2">&quot;prep value 5, Out returns OK and calls collaborator twice&quot;</span><span class="o">(){</span>
    <span class="nl">given:</span>
    <span class="n">objectUnderTest</span><span class="o">.</span><span class="na">prepare</span><span class="o">(</span><span class="mi">5</span><span class="o">);</span>

    <span class="nl">when:</span>
    <span class="n">objectUnderTest</span><span class="o">.</span><span class="na">doSomething</span><span class="o">();</span>

    <span class="nl">then:</span>
    <span class="n">objectUnderTest</span><span class="o">.</span><span class="na">getState</span><span class="o">().</span><span class="na">equals</span><span class="o">(</span><span class="s1">&#39;OK&#39;</span><span class="o">)</span>
    <span class="n">objectUnderTest</span><span class="o">.</span><span class="na">isActive</span><span class="o">()</span>
    <span class="mi">2</span> <span class="o">*</span> <span class="n">mockCollaborator</span><span class="o">.</span><span class="na">getStatus</span><span class="o">()</span> <span class="o">&gt;&gt;</span> <span class="s1">&#39;x&#39;</span>
<span class="o">}</span>
</pre></div>
<p>There are a few things to note:<br>
 * The name of the test, which also appears in the test results, is far more expressive<br>
* The given / when / then causes are part of the DSL, not just comments, and will tell you if you have got it wrong<br>
* The static imports have all gone<br>
* The comparison methods in the &#39;then&#39; clause are all &#39;native&#39;<br>
* The last line of the &#39;then&#39; clause is an example of the one thing that may trip you up.  It is saying that the mock is expecting to be called twice, and will return a value of &#39;x&#39; on both occasions.</p>

<p>Spock processes mock interactions in a different way to Mockito, and that can cause some misunderstandings when migrating from one to the other.  It is worth reading that part of the documentation thoroughly.</p>

<h2 id="not-much-difference">Not much difference?</h2>

<p>At a quick look, apart from being neater, there does not seem to be a massive difference.  In practice, though, I have found that neatness very productive ... even with code completion, &#39;assertThat  .. isEqualTo&#39; is a bit cumbersome, where using the native comparison methods is far more fluent.</p>

<p>The failure output from Spock is also an improvement on the classic approach, giving a better indication which part of a check has failed:</p>
<div class="highlight"><pre><span></span><span class="n">Condition</span> <span class="n">not</span> <span class="nl">satisfied</span><span class="p">:</span>

<span class="n">stack</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">==</span> <span class="mi">2</span>
<span class="o">|</span>     <span class="o">|</span>      <span class="o">|</span>
<span class="o">|</span>     <span class="mi">1</span>      <span class="nb">false</span>
<span class="p">[</span><span class="n">push</span> <span class="n">me</span><span class="p">]</span>
</pre></div>
<p>The only thing I miss are the collection methods of AssertJ - containsOnly(), containsExactly() - for example.  But if I miss them too much, I can still use them in Spock.</p>

<p>Oh, and the Spock data driven tests are neat ...</p>

<h1 id="conclusions">Conclusions</h1>

<p>Spock seems to be one of those tools which grows on you very quickly.  At first, it seemed that its advantages were not that great, but after just a few days, the increase in fluency and productivity convinced me that the change would be worthwhile.</p>

<p>I don&#39;t generally convert existing tests unless they need modification, but conversion is not difficult either.</p>

<p>Now,it is all I use in <a href="https://github.com/davidsowerby/krail">Krail</a> for new unit, and usually integration testing ... and on the rare occasion when I add a test method to existing JUnit tests, the  &quot;classic&quot;method feels very clunky.</p>

<p>The learning curve for Spock is not steep - I just found that the way interactions are used take a little bit of getting used to, but the end result is extremely powerful.</p>

<p>If you are writing tests - I would strongly recommend that you give it a go.  And if you are not writing tests ... well, it might be a very good idea to start :-)</p>
]]></content:encoded>
      </item>
  </channel>
</rss>