Friday, March 29, 2013

Measuring overall code coverage in multi-module Maven project

As we know unfortunately Maven has no out of the box support for different test types. There are in fact few open tickets for adapting Maven to different test strategies, like adding integrationTestSourceDirectory to POM model (MNG-2009) or new lifecycle phases for operating on integration test sources (MNG-2010) to replace necessity of using build-helper-maven-plugin.

But apart from separating varying tests from each other how can we use available mechanisms to invoke both unit and integration tests and measure theirs code coverage? I want to achieve such situation (maybe except the number of tests because I usually want to have a little bit more :)) on the Sonar dashboard:

We'll work on a simple maven project with the popular layout:

Tuesday, March 19, 2013

33rd Degree to knowledge


I'm not sure I can be treated as a java master, but fortunately thanks to Warsaw Java User Group I had a chance to attend the 33 Degree Conference. Schedule looked very impressive as there were many rock-star speakers and outstanding talks. It was really hard to choose valid path, but after taking some hard decisions I've created the custom agenda. I've never liked keynotes, so let me start from regular talks :)

I've already noticed that Estonia is quite unique in the market of superior Java tools - companies like ZeroTurnaround and Plumbr are doing really nice job. I like them especially when they are talking about as interesting things as JVM internals :) Nikita Salnikov-Tarnovski made very nice presentation titled How much memory do your objects really need? Apart from the fact that he is showman the talk was really interesing! He introduced java-object-layout tool which can analyze object layout schema in different JVM's - another advantage is that this project uses internally sun.misc.Unsafe ;)

I've also decided to check what Sławek Sobótka knows about my mother, and why she has never told me something important about automated testing. Fortunately after one hour of listening accurate metaphors and well grounded strategies I see that she didn't do that intentionally - ufff.... In the other case it would be very depressing fact.

Next step on my list was Baruch Sadogursky talking about Developing for multi-component environment while keeping your sanity. He described (IMHO very mature) process for maintaining developers environments in JFrog - using Chef, Vagrant and GIT. It was so professional that I still can't understand why he uses Windows instead of Linux? :)

Another good presentation was about Architecture without Architects. Erik Dörnenburg exchanged term "architect" with "gardener" - which sometimes adds new plants but mostly takes care of the existing ones. I totally agree with him! Especially when we compare the level of the details between software systems and civil engineering plans. The conclusion was that each developer has to take care of the system quality - not only "the chosen one". At the end he also shown some nice tools for visualizing source code like CodeCity - it looks delightful.

Last but not least (unfortunately aggrieved by going parallel with Venkat Subramaniam) was Andres Almiray. Groovy developer is definitely competent to talk about Polyglot Programming in the JVM. He  described similarities and differences between Groovy, Scala and Clojure. As Groovy has very nice and close to Java syntax, Scala is very powerful I thoroughly can't understand pros of Clojure... but I really understand why there are so many haters of this specific language ;)

Sadly I had no chance to attend the last day of the conference and listen about polyglot persistence and Vaadin 7 but maybe I'll have another opportunity in the next year :)

Monday, March 11, 2013

As a developer I want to use XML extremely easily

A few days ago I needed to parse some reports in Java application. Recently I used for such tasks built-in features, but I can say they are not very user-friendly or intuitive. And I think that there's no reason to use something strange for implementing such simple things. I'll be much better to find very cool replacement. After spending some time googling I've checked that unfortunately there were nothing satisfactory. I've even started thinking about using Scala but luckily in last-ditch attempt I've found JOOX. Really weird name, but I've found out it's abbreviation from Java Object Oriented XML... hmmm - sounds promising :) Authors described it as "simple wrapper for the org.w3c.dom package, to allow for fluent XML document creation and manipulation where DOM is required but too verbose". For me it's enough to start looking for maven artifact:
         
             org.jooq
             joox
             1.1.0
         
Core element is the org.joox.JOOX class with static $ method (yes, yes - jQuery clutches) returning org.joox.Match interface - another very important element.

Let's start - method Match $(File file) seems to be good entry point. Now I need file for testing - the nearest one is my pom.xml - why not? :)
public class JooxSandbox {
  public static void main(String[] args) 
      throws IOException, SAXException {
    Match document = $(new File("pom.xml"));
  }
}

Monday, March 4, 2013

Speed Up with Fast Java and File Serialization

Since the first version of Java, day-by-day many developers have been trying to achieve at least as good of performance as in C/C++. JVM vendors are doing their best by implementing some new JIT algorithms, but there is still a lot to do, especially in how we use Java.

For example, there is a lot to win in objects<->file serialization - notably in writing/reading objects that can readily fit in the memory. I’ll try to shed some light on that topic.

All the tests were executed on the simple object shown below: 

public class TestObject implements Serializable {
  private long longVariable;
  private long[] longArray;
  private String stringObject;
  private String secondStringObject; //just for testing nulls

  /* getters and setters */
}

To be more concise I’ll show only the write methods (though the other way is quite similar, too). Full source code is available on my GitHub (http://github.com/jkubrynski/serialization-tests).