Confoo 2013

Confoo 2013 is just over !

From Wednesday 27th to Friday March 1st, I had the chance to be the speaker of 2 talks :

  • Make your Java app Rest enabled : feedback about implementing the Rest agent in Terracotta products, and the Terracotta Management Console ) along with Rest, JAX-RS , JEE security and Shiro intros
  • Spring for Android : presentation about the Spring for Android Rest/OAuth library for Android (note to myself : stupid mac to vga adapter that made me lost 10 minutes !!! I should stop buying cheap adapters…)

While I was there, I could also attend several very interesting sessions (french & english)!

Here are some notes about some of them : (some of the speakers did not share their slides :-(   — yet ? )

Java EE 7 Platform : Productivity and WebSockets JSR 356  by Arun Gupta, technology evangelist at Oracle

Interesting sessions, WebSockets ,  JAX-RS 2.0 and concurrency utilities were the technologies that stroke me most for this new release.

Here are several links from Arun to get you started :

Git(hub) for padawans by Ben Straub

Very cool session for Git beginners (and not only I think); that session was very interactive and provided good insight on the different staging areas in Git, before your changes get committed

Better eight than never by Nick Maiorano

This session could have been named :  » What Java 8 lambdas are going to be »; very interesting to discover the power of the lambdas; coming soon in JDK 8 September 2013

Redis by Ross Tuck

Redis, yet another key value store, was being explained by the great show man Ross Tuck : brilliant slides, cool examples; that was a very good one !

Du legacy au cloud par David Gageot

Comme son nom l’indique, cette session montre à l’audience comment emmener du code java très complexe et peu compréhensible à du code testé et déployé en application web. (session pratique, aucune diapo n’était projetée)

  1. test en boite noire (alternative etant de dupliquer la classe et comparer les resultats entre l’originale et le nouvelle, pour etre sur que la nouvelle se comporte à l’identique); c’est l’etape la plus importante pour ete sur que rien ne sera cassé dans l’avenir (David utilise infintest pour lancer les tests automatiquement)
  2. dupliquer pour mieux extraire : en cassant en plusieurs conditions des conditiosn multiples; les choses s’eclaircissent (des conditions inutiles apparaissent et des motifs de code recurrent apparaissent); if qui englobe peut etre dupliqué et etre englobé
  3. extraction des méthodes et de classe
  4. passer sur le web : en lancant depuis une methode main le serveur web du JDK : HttpServer (Java >6 ) ; refresh à chaud si les signatures de méthodes ne changent pas (ou sinon JRebel); passage en Json des items; et consommation des items en Json depuis 1 page html en utilisant angularJS; et twitter bootstrap pour le css
  5. pour le passage sur le « cloud », David a utilisé Heroku.

Arquillian, quand écrire des tests devient un plaisir par Jean Louis Monteiro

Arquillian, framework de tests pour JEE, était brillament présenté par Jean Louis; de la problématique à écrire des tests pour al plate forme JEE, en utilisant des mocks notamment, il nous a montré comment Arquillian pouvait lancer facilement et légèrement des tests d’intégration  dans le containeur de son choix (s’il existe un connecteur Arquillian)

Scala est il fait pour moi, par Nicolas Martignole

Session très sympa et détendue pendant laquelle Nicolas nous a fait part de son retour d’expérience sur son apprentissage de Scala ; avec des bons conseils à la clef (Coursera Scala revient le le 25 Mars 2013 !)

Final words

All in all, those 3 days at Confoo  (the second time I attend this conference) were really great : good talks, good organization, and very interesting people I met (or had the pleasure to see again) !

 

Verify your photos are not corrupted, even from your Synology Diskstation, with jpeginfo

It was talking about backups with my colleague Ludovic, that I got aware of a danger threatening my backups : the bitrot.
Oh sure I got my backups redundant and stored in different places, but what if my master copy gets corrupted due to bitrot, and then propagates the corrupted files across my backups ?
Ludovic told me about ZFS, the filesystem designed with checksums and data protection services at the filesystem level; unfortunately my (beloved) NAS, the Synology DS211J does not support zfs (it is using ext4 by default)…
But if my filesystem can not detect corrupted data, jpeginfo can detect corrupted jpeg files : so I would just need to run jpeginfo on my photo collection before any new backup !
Now, jpeginfo is widely spread across classic linux distributions, such as Ubuntu or Debian (sudo apt-get install jpeginfo) and even Mac OS X (brew install jpeginfo), but it does not come pre-installed on the Synology Diskstation.

Installing jpeginfo on the Synology Diskstation

  • install ipkg on your diskstation, this post sums it up nicely
  • then from your workstation, download the debian sid jpeginfo package (this is important: more recent releases have a dependency on libjpeg.8 which is not provided by the ipkg feed) : wget http://archive.debian.org/debian/pool/main/j/jpeginfo/jpeginfo_1.6.0-4_armel.deb
  • unpack it : ar x jpeginfo_1.6.0-4_armel.deb
  • unpack the archive containing the binary : tar xvzf data.tar.gz
  • copy to your diskstation the binary : scp ./usr/bin/jpeginfo root@192.168.0.100:
  • login to your diskstation, jpeginfo is available from /root/jpegingo (move it to the path then)

I also published this howto replying to a Synology forum thread , which actually got me started for the next step.

Running jpeginfo before backing up

Let’s say you want to make sure your photos are not corrupted before running cron against your collection (or a sub part of it), here is the one-liner :

find . \( -iname "*.jpg" -o  -iname "*.jpeg" -o -iname "@eaDir" -a -type d -prune  \) -print0 | xargs -0 /root/jpeginfo -cv | grep "ERROR"

In other words : find all files ending with jpg or jpeg , not in a directory named @eaDir (where the Diskstation stores its thumbs), check them with jpeginfo, whenever it returns a result with an ERROR print it on the console.
Now you just need to make sure that whenever an ERROR is found, you log it somewhere and you abort the backup.

Skipping a JUnit 4 test using @BeforeClass and a custom hamcrest matcher

Working on a test depending on an external Ldap server (yeah, I know, this sounds bad, but sometimes you just want to make sure your code works against the real thing, not only embedded servers, such as the excellent Apache DS — which I use for other integration tests though!!!) I wanted to make sure this test would not fail when this server was down.
I wanted to tell Junit4 to skip the whole test class if I could not reach the server during an @BeforeClass method.
But how could I tell Junit4 to fail because of a condition in an @BeforeClass method ?

This is when I got 2 precious pieces of advice from my colleague (and hamcrest lover) Chris :

  • use org.junit.Assume.assumeThat(T actual,  Matcher<T> matcher)
  • and eventually create a custom matcher

let’s have a look at the first version of the code :

@BeforeClass
public static void checkServerIsOnline() throws IOException {
  InetAddress address = InetAddress.getByAddress(new byte[]{42, 42, 42, 42});
  Assume.assumeThat(address.isReachable(5000), IsEqual.equalTo(true));
}

so if the server is not responding after 5 secs, the test class won’t go further, and return without failing or returning an error; great !

But we can do better than that… what about :

@BeforeClass
public static void checkServerIsOnline() throws IOException {
  InetAddress address = InetAddress.getByAddress(new byte[]{42, 42, 42, 42});
  Assume.assumeThat(address, IsReachable.isReachable(5000));
}

we have now to create the IsReachable matcher :

public class IsReachable extends TypeSafeMatcher<InetAddress> {
 
  private final int timeout;
 
  public IsReachable(int timeout) {
    this.timeout = timeout;
  }
 
  @Override
  public boolean matchesSafely(InetAddress item) {
    try {
      return item.isReachable(timeout);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return false;
  }
 
  @Override
  public void describeTo(Description description) {
    description.appendValue(timeout);
  }
  /**
   * Is the address reachable as per
   * {@link java.net.InetAddress#isReachable(int)} ?
   */
  @org.hamcrest.Factory
  public static Matcher<InetAddress> isReachable(int timeout) {
    return new IsReachable(timeout);
  }
 
}

Did you notice I extended a TypeSafeMatcher and not a plain Matcher ? that way I could avoid casting an Object into an InetAddress in the matches[Safely] method !