Posts

Verify logging with Logback

Last updated

Sometimes you have a piece of logging that is very important, maybe even part of a business requirement. In that case, you might want to verify that in a unit test, so you can rest assured that this requirement is actually met. How to do that?

Mock it away

A first approach might be to just mock your logging framework in a unit test and verify it was called as you expected. It might sound tempting, and easy to do, but not everybody likes it. And in fact, you might run into some issues when walking this path, because some libraries tend to make classes and/or methods final so they can’t always be mocked away. Also, a lot of people tend to create a logger by doing private static final Logger LOG = ..., which makes it even harder to mock it away. Making your logger an instance variable just so you can test it? Nah…

Read more... →

Blah blah Microservices blah blah

Last updated

As a closing keynote on the second day of Jfokus, Jonas Bonér took the stage under the very clarifying title “Blah blah Microservices blah blah”, which turned out to mean “From microliths to microsystems”.

As a first observation, he stated that no-one really likes microservices. They are kind of a necessary evil - because “doing” microservices comes at a cost. In fact, microservices are just a specialisation of an older concept called distributed systems. But what we often build are microliths - an application that might be called a microservice except for the fact that it lives alone. No failover, no resilience, nothing. But just like actors, microservices should come in systems. And just as important, microservices should come as systems, designed as a distributed system, which each microservice focussing on a single responsibility.

Read more... →

Jfokus, Day 2

Last updated

The second day of Jfokus is just as action-packed as the first one. However, part of the action is me giving two talks. Both of them scheduled today, so a little less time for attending other sessions and blogging about them. I did attend some other sessions after lunch time, on which I’ll report below.

Introduction to Machine Learning

Directly after the lunch, James Ward gave an introduction to machine learning. He started with a very recognizable story about how humans (in casu his daughter) learn new facts about the world around them. Machine learning is in fact no different than human learning: building a model, trying something, seeing whether and how it changes reality and updating the model.

Read more... →

Quickly switch Java versions on macOS

Last updated

Inspired by a Jfokus session I attended today I decided to download and install a preview of Java 9 on my MacBook. That went pretty quick and without much trouble. But when I issued java -version on my terminal, I was greeted with

Java(TM) SE Runtime Environment (build 9-ea+155)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+155, mixed mode)

Although that’s nice - you’d even expect it, maybe - I realised I often need Java 8 as well. How to quickly switch between the two?

Read more... →

Jfokus, Day 1

Last updated

These days, I’m in Stockholm, attending and speaking at the Jfokus conference. Yesterday night was a great opportunity to get to know a few other speakers during dinner. We were even surprised by an act of the Lemon Squeezy barbershop quartet singing for us - very beautiful!

But today, the serious stuff started. In the following sections, I have written down my notes and observations of each of the sessions I attended.

Read more... →

Long time, no blog

Last updated

Recently, I was asked to write a blog about a side project I did. That question reminded me of the blog I used to have… long time ago.

I stopped blogging due to changes in my personal situation, which led to a priority shift. Being a father to two beautiful daughters sure takes a lot of time! But I missed the possibility to share some notes, thoughts, ideas and the like. So I decided to resurrect my blog, although in fact it’s more of a notebook. In the coming period, I’ll be adding some historical notes which I earlier stored privately. Stay tuned!

Read more... →

Automatic scan for known vulnerabilities in dependencies

Last updated

When using third-party components (be it open source or not), we all know it’s a good practice to keep your frameworks and libraries up to date. This is also one of the spearhead in the OWASP Top 10 (2013 edition): A9 - Using Components with Known Vulnerabilities. To help you assess your projects status with regard to this, OWASP.org developed the tool Dependency Check. This tool is primarily intended code bases in Java, .NET, Ruby, Node.js, and Python. Integration with various build tools is also provided for.

Read more... →

Tweaking nginx for serving static content

Last updated

For a recent project, we decided to use the nginx webserver as our primary web server. It is easy, relatively light-weight, and it seemed to suit our needs quite well. The project had a lot of static content - HTML, JavaScript, CSS and image files. Of course, we wanted to achieve a high performance with as many concurrent requests being served as possible. This is what we did.

Setup

First of all, it is worth to mention the setup. Our staging environment had just one virtual machine with nginx running. This was an Azure Standard A2 VM with 2 cores and 3,5 GB of RAM. That’s not a lot, and in a real production environment you would definitely go for more web servers, with some kind of load balancing. But the goal of this experiment was mainly to experiment with the many options nginx provides for tweaking. The virtual was located in the same region as where the project will be deployed. Also, we used a similarly sized machine for putting load on our web server. This machine was located in that same region as well.

Read more... →

Quickly count your code base

Last updated

Often, the size of a code base is measured in terms of “source lines of code” (SLoC). If you’re interested in the size of your code base - or your client is - this metric provides a way to express that size. Of course, comments and the like are not considered to be code, so how to determine this metric? Using grep is tempting, but it quickly results in a very complex and hard-to-understand approach.

Read more... →

Easily upgrade Java dependencies

Last updated

To start with a cliche: the Java ecosystem continues to develop at a high pace. Various open source frameworks releasing versions, sometimes even multiple versions at the same time. This may quickly turn into a risk But how to deal with it?

Basically, you have two options. We’ll take a typical Maven-project as an example, which uses Commons Lang 3. See the end of this post if you prefer Gradle over Maven.

Automatic upgrades

Maybe the simplest way is automatic upgrading. You can achieve this by not specifying an exact version of your dependency, but instead specify a version range. If you would normally have this snippet in your POM:

Read more... →