Reuse test code between Maven projects

Maven is a tool that keeps surprising. Ever had a multi-module project with test utility classes, that would be nice to reuse down the line, but that cannot easily be moved? A typical and simple setup would be a model project with JPA classes and one or several downstream service projects that import the model. If the model has test utilities that create test data, that would surely come in handy in the service projects as well.

The officially recommended solution is to move the test utilities to a project of their own and import with test scope. However, most likely the utilities need the JPA classes, so the test utility project must import the model project. Circular dependencies are out, hence the model project cannot import the utility project. What a snag. The solution is to move the model project’s tests to a separate project, that can import the model with compile scope and the test utilities with test scope. That works, but now the tests do not run in the model project, so it gets lousy ratings in test coverage… It also succeeds even if there are test errors. The build may still fail, but not in the right place.

Another option is to duplicate the code. That works if it is only a class or two, but it feels dirty. The code rot is setting in.

However, there is actually a third and much better alternative! Maven can produce a real jar and a test jar from a single project, for example like this:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>test</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>
<include>**/testutil/**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

Now, the test utilities (in the testutil package) can live in the model package, where they are used by unit tests. Downstream projects import the dependency with type test-jar. They will not get transitive dependencies, but that is fine. They can always be added and we are talking about a few test classes only.

Share and enjoy.

Categories: Java

Naturally nothing was found

Queue number 404

Somehow I knew when I got the ticket in the waiting room that the tests would find nothing…

Categories: Uncategorized

Playing with Quarkus

It is vacation time, so why not try something new? I’ve been playing around with Quarkus a bit. It is incredibly cool to get native code from Java with blindingly fast startup times, but it makes me remember the old days with C++. Building the simple toy application in the getting started tutorial takes ages and the first few times it failed as the build ran out of memory. Increasing the memory reserved for Docker to 8G helped, but build times are still very long.

To get the startup times of C++ we are stuck with the build times of C++. Perhaps not surprising, but there it is.

Categories: Docker, Java

The right time to throw out JUL

There is an old Swedish saying: tjugondedag Knut åker julen ut. JUL is Christmas in Swedish and on this day, twenty days after Christmas Eve, we celebrate the end of Christmas, i.e. end of JUL. It was thus with great pleasure we got rid of JUL (java.util.logging) from one of our Java projects Today in favor of YAL (Yet Another Logger alias System.Logger that shipped with Java 9). The timing could not have been better.

Categories: Java

ZFS on Linux with native encryption finally released

The title really says it all, https://github.com/zfsonlinux/zfs/releases/tag/zfs-0.8.0 was released 13 hours ago. Check it out!

Categories: Linux

Quick guide to typeperf for Windows performance monitoring

The typeperf command is an underused gem in the Windows world. It is basically iostat/vmstat/sar for Windows on steroids and is available out of the box from Windows 2000 and up.

With typeperf it is possible to sample any performance counter on the local computer or by all means remotely and write it to the console or to a file at a specified rate, by default once per second. That is perfect when you want to instrument something during a performance test and keep the raw data afterwards.

To get the names of the available counters, run:


typeperf -q >counters.txt

This gets all the installed counters without instances. The same command but with -qx gets the counters with instances. An example of a counter with an instance is \Process(notepad)\% Processor Time which gets the processor time for the notepad process specifically. Without instances notepad becomes *.

To write to a file, include -o. To change the sample rate, use -si. To stop after a given number of samples, use -sc. To connect to another computer, use -s.

To check the total processor time every second:


typeperf "\Processor(_Total)\% Processor Time"

Available memory every ten seconds:


typeperf "\Memory\Available Bytes" -si 10

Pid, processor time and working set for notepad every second (no newlines):


typeperf "\Process(notepad)\ID Process"
  "\Process(notepad)\% Processor Time"
  "\Process(notepad)\Working Set"
  "\Process(notepad)\Working Set - Private"

Disk queue length every second :


typeperf "\PhysicalDisk(*)\Avg. Disk Queue Length"

This just scratches the surface. Happy monitoring!

Categories: Windows

Delete StatefulSet in Kubernetes fails with NotFound

I have created a stateful set with MongoDB databases in Kubernetes with AKS. In order to test the persistent volumes I tried to delete it, but to my surprise that failed:

Error from server (NotFound): the server could not find the requested resource

What? Getting the resource worked, but kubectl describe failed. What to do? I finally found out that my kubectl client was incompatible with the server. Apparently Kubernetes supports one version higher or lower, but kubectl is at 1.10 and the server at 1.8.

Categories: Kubernetes

Terminal in docker exec a mess

Fairly recently the terminal for docker exec has started to misbehave. When I enter a running Wildfly container to view the logs the output becomes garbled with less, vi and other tools. It appears the reason is that the terminal size is not detected (#33794). The solution on Linux/Mac is to pass in the size:


docker exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" -it imagename

Unfortunately that doesn’t work on Windows. The mode command can provide the columns, but not the number of lines, which must be hard-coded.

Categories: Docker

Azure SQL Server VM backup failures

SQL Server VMs in Azure can be backed up using the SQL Server configuration blade in the portal. When this has been enabled the logs can be swamped by errors similar to:

2018-06-04 11:44:59.88 Backup BACKUP failed to complete the command BACKUP LOG master. Check the backup application log for detailed messages.

Fear not, it is only temporary. A SQL Server backup consists of two parts: a full backup of the database(s) and transaction logs. When no full backup has been done the transaction log backups fail with the error above. The errors should go away when the first full backup has been completed successfully.

As a side note there is no “application log”, the message refers to the calling application and in this case that is the Azure SQL Server extension. It doesn’t log anything useful.

Categories: Database

Biztalk 2016 wants to disable private key protection

Biztalk 2016 failed to receive AS/2 messages with this error:

The MIME encoder failed to sign the message because the certificate has private key protection turned on or the private key does not exist. Please disable private key protection to allow BizTalk to use a certificate for signing.

Sounds straightforward except that private key protection was disabled already. And the user profile for the Biztalk user was loaded, nothing wrong there. I went through the documentation several times, nothing wrong. Finally I found that it was the cryptographic provider.

Basically the problem is that Biztalk 2016 still relies on the ancient .NET 3.5, which lacks support for KSP. Check the certificate:


certutil -p password cert.pfx

If it says “Provider = Microsoft Software Key Storage Provider” then Biztalk will fail and complain about private key protection. Fix it with openssl:


openssl pkcs12 -in my-original-cert.pfx -out temp.pem
openssl pkcs12 -export -in temp.pem -out my-fixed-cert.pfx

Import my-fixed-cert.pfx to the personal certificate store (and if self-signed also import as CA key). Update Biztalk to use the updated certificate and hopefully the problem should be solved. If you are starting from scratch, specify the old provider instead:


New-SelfSignedCertificate -Provider "Microsoft Strong Cryptographic Provider" ...
Categories: Windows