sebastiandaschner news


monday, february 27, 2023

Welcome to another newsletter!

These days and week are quite relaxed, which for me translates to quite full of coding work, mostly working from home, and in general a relaxed and enjoyable time. I’m working a lot with Quarkus and Kubernetes-related stuff, and also have release quite a few YouTube videos, and am planning to continue to do so. So if you haven’t you can stop by my YouTube channel.

Conference-wise, this year is also quite relaxed so far. I’ll be speaking at the GeeCON and JAX Mainz conferences in April and May and am looking forward to these trips. Since I’ve been doing that much traveling until 2020, I do enjoy now a more relaxed schedule and also spending a bit more time in each conference location.

The other thing that’s new is the layout of this very newsletter. I’ve noticed that in the past the font sizes were sometimes a bit weird, especially for inline code, and I’ve now re-worked that a bit. So, if you have any layout issues, improvement ideas, or general feedback, kindly reply to this and let me know, always happy to hear your feedback.

 

What’s New

(And wow, that’s the longest what’s new list I ever had in a newsletter)

 

IntelliJ Coding & Navigation Shortcuts

As you might now, I’m a big fan and user of the IntelliJ IDE. I’ve created a few videos on what I think are the most essential tips and keyboard shortcuts one needs to know. The keyboard concept of an IDE such as IntelliJ can easily become overwhelming, since so many actions are available as shortcut. However, there are a few that we use most of the time, and I wanted to point out my personal favorites:

Check out the following videos:

 

Programmatically Listen to JUnit Test Results

There are many ways available to run JUnit tests, from the IDE, build tool, or development modes. To process and use the test results, however, one has to either read the output or parse result files (such as the XML surefire reports). It’s also possible to define result listeners programmatically in JUnit:

You can register a custom TestExecutionListener, that will be notified at certain events that happen during testing, such as when the whole test plan as well as individual executions start or stop. We define our own implementation, TestResultNotifier that gathers and uses the overall result. This class resides under src/test/java:

import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.TestPlan;

public class TestResultNotifier implements TestExecutionListener {

    private boolean passed = true;

    @Override
    public void executionFinished(TestIdentifier testIdentifier,
            TestExecutionResult testExecutionResult) {

        if (testExecutionResult.getStatus() == TestExecutionResult.Status.FAILED)
            passed = false;
    }

    @Override
    public void testPlanExecutionFinished(TestPlan testPlan) {
        if (!passed) {
            System.out.println("!!!");
            System.out.println("Tests NOT passed!");
            System.out.println("!!!");
        } else {
            System.out.println("All tests passed!");
        }
    }
}

In order to register the JUnit listener automatically, we add a file under src/test/resources/META-INF/services/ named org.junit.platform.launcher.TestExecutionListener. The content of the file points to our class, a single line containing:

com.sebastian_daschner.coffee.TestResultNotifier

Then, we can execute the tests in any way we like, and we will see the output.

This approach is used not that often but can be very helpful for overall listeners that integrate with external tooling or your custom workflow. Have a look at my blog post for an example that integrates with a hardware LED feedback device.

 

Discovering Local Multicast DNS Network Devices

You can discover local network devices via the multicast DNS (mDNS) protocol. Needless to say, there’s a way to do this in Java as well.

Why would you want to do this? If you’re using Elgato Lights, for example, they connect to your local WiFi and can be discovered by this protocol.

For this, you can query the _elg._tcp type via mDNS, using the jmDNS library:

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
import java.io.IOException;
import java.net.InetAddress;

public class Resolver {

    public static void main(String[] args) throws IOException {
        JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());

        ServiceInfo[] elgatoServices = jmdns.list("_elg._tcp.local.");
        for (ServiceInfo elgatoService : elgatoServices) {
            System.out.println("elgato = "
                               + elgatoService.getInet4Addresses()[0].getHostAddress()
                               + ':' + elgatoService.getPort());
        }
    }

}

The dependency can be added in your Maven build:

<dependency>
    <groupId>org.jmdns</groupId>
    <artifactId>jmdns</artifactId>
    <version>3.5.8</version>
</dependency>

Running the Resolver class detects your local Elgato lights:

elgato = 192.168.1.111:9123
elgato = 192.168.1.112:9123

Then, we can use the HTTP API that these lights expose to query and control them. If we don’t change the light setup often, we can hard code these addresses and save time compared to discovering them at every control action. This is what I’m doing on my setup now, using a custom command line script. On my blog, I’m describing this in more detail.

 

Quarkus Workshops in April 2023

And this is your reminder that there are still places left for my virtual, interactive workshop on on effective Quarkus development and testing, in April 2023. In these two days, we’ll cover everything on modern application development and testing with Quarkus; the most important concepts, topics, and technologies to be able to develop with Quarkus.

You can register for the days individually, or both (and save some money). If you show up with one or more colleagues (or friends) or a whole team, you’ll get a further discount.

Would be great to see you there!

 

Thanks a lot for reading and see you next time!

 

Did you like the content? You can subscribe to the newsletter for free: