Maven Failsafe Plugin environmentVariables Not Working (org.postgresql.Driver claims to not accept jdbcUrl)

A few months ago I had written about how one can setup a PostgreSQL database in a docker container during the Maven testing phase (part 1 and part 2). Today, I wanted to iterate on this topic using Testcontainers. Unfortunately, before I could get to that I ran into issues with the original project. For some reason I was now getting the following error:

Caused by: java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, jdbc:postgresql://localhost:${it-database.port}/docker_db_testing_tests

Maven did not replace the variable it-database in the integration test application.properties file. The question is: "why now"? It has worked before. Now, one thing that I changed is that this time I was using Linux instead of Windows. Either way, the fix was simple, although not obvious. It seems to be an issue with the Maven Failsafe plugin.

Not working:

<configuration>
    <environmentVariables>
        <it-database.port>${it-database.port}</it-database.port>
    </environmentVariables>
</configuration>

Working:

<configuration>
    <systemPropertyVariables>
        <it-database.port>${it-database.port}</it-database.port>
    </systemPropertyVariables>
</configuration>

Here is the link to the commit.

Spring Multipart File – Can I Read InputStream Multiple Times?

The short answer is Yes.

Here is the long version and why I even asked myself this question.

If you are familiar with ServletRequest then you probably know that calling its getInputStream method only works once. If you need to read the body data multiple times then it is up to you to cache it in a buffer or employ workarounds such as a "caching servlet request". Unfortunately, this fact is not stated in the Javadoc of ServletRequest#getInputStream so it is no wonder this question gets asked.

Spring’s MultipartFile is a bit different here. It, too, has a getInputStream method, but this one can be called multiple times. Again, it is not obvious from the documentation which is why I am making this mental note for myself and others who are researching this question because they know about the behavior of ServletRequest and assume – as I did – it is the same for MultipartFile. Fortunately, it is not.

In my case I needed to compute a hash of an uploaded file and then move the file to Azure’s Blob Storage. The Azure API used an InputStream and I assumed, once I had consumed the multipart InputStream that I could not use that API anymore.

As a side note: Using DigestInputStream it is possible to do this in one go, move the data to storage and while doing that compute the hash. In my case, I needed the hash first to compare it with a value that was provided on upload. Only when they match can the data be transferred to storage.

Star Wars Jedi Fallen Order Review

It was until the end of 2019 when the Star Wars franchise was blessed with another game that truly deserves to be part of the Star Wars universe. The last good Star Wars game I played was Bioware’s Knights of the Old Republic – and that was 2004! There were a few others in between and I may have played some. None left a lasting impression though, or otherwise I might still remember bits and pieces of them. And what did players get in recent history? Battlefront is what comes to mind. Well, it may have the Star Wars branding and characters and weapons and sounds. But to me, Star Wars is about a science-fiction fantasy story, a fairy tale if you will. I am not interested in a multiplayer shooter when I think about a Star Wars game. I am interested in an adventure and an adventure is what you get with Jedi Fallen Order. Is it a good adventure? Well, that is what I am here to tell you about.

Star Wars Jedi Fallen Order is a story driven, 3rd person action adventure. You play as a young Jedi that is hiding on a scrap planet until one day the Empire arrives and turns his life upside down. From there you fight your way through imperial troops, wildlife, and some zombies. Kind of.

Read More »

Automate Game Screenshot Capture: Windows API SendInput Function with C++

I am trying to write video game reviews after I have finished a game and I like to add some impressions in the form of screenshots to the reviews. There is one problem though: sometimes it is impossible to press the keyboard shortcut to capture a screenshot because the game requires my full attention – and all my fingers. Therefore, I miss out on a lot of action sequences. What does a programmer do in such a situation? Write a tool that scratches the itch.

Read More »

Assassin’s Creed Odyssey Review

Assassin’s Creed Odyssey is my first Assassin’s Creed ever. The first time I encountered Assassin’s Creed 1 I did not really like the concept. It felt weird to me that the actual interesting and cool gameplay was constantly interrupted by the modern-day stuff. It also did not help the game’s case that the German translation was atrocious. I had to revisit this series a few years later to get more interested. I did so by watching videos on YouTube where all cutscenes had been edited into one large video, effectively turning the game into a movie, sans the gameplay. Ultimately, I have come to like the presentation of the main stories. They are interesting enough and the cutscenes are of very high quality. As a result, I have seen about four or five of these “movies” and watched some gameplay of AC Origins. This really caught my attention and because Odyssey was supposed to be even more like an RPG, I snatched myself a copy once there was a good deal for it. But honestly, given the time I have spent with this game so far, the full price would have been warranted without question. I have finished the game including the DLCs, I am close to 200 hours and I think I am ready to share my thoughts.

Read More »

Mockito “when” vs. “verify”

Recently, during a code review at work there was a discussion about whether Mockito’s verify is necessary when when (or given, which is a synonym) is parameterized. The quick answer is "no".

Imagine this contrived example. I have two classes, Calculator and ComplexOperationService, where the latter requires the former. The goal is to write a unit test for ComplexOperationService and mock all usages of Calculator.

Here are the two classes.

public class Calculator {

    public int sum(final int a, final int b) {
        return a + b;
    }
}

@RequiredArgsConstructor
public class ComplexOperationService {
    
    private final Calculator calculator;

    public void doComplexOperation(final int a, final int b) {
        System.out.println(calculator.sum(a, b));
    }
}
Read More »

How Corona Virus and Lockdown Affect Me

I guess everybody has a story about how the current situation affects them. Since I share a few of my thoughts on the Internet and this one also has to do with technology, usually the main topic of my musings, I think this is something worth addressing.

I do not know if it makes any difference, but I will say it anyway for the sake of context. I live in Germany and of all the countries in the world we are in fairly good shape so far. We have had lockdown procedures for a while, but nothing so restricting that forbade leaving the house for anything other than going to work, the doctor or buy groceries. We could go for walks or outdoor sports if we were not meeting with other people. It was social distancing, but not hiding at home.

I work as a software developer at an IT company and my employer, like many others, relaxed the usual home office regulations month after month and basically the whole company started to work from their homes, me included. There are a few that do not like it and rather go to the office – which is safe, I presume, as there is basically no one there. I, on the other hand, prefer working from home and this is where the story of this blog post starts.

Read More »

GTA V: Play Your Own Music Library on Radio

GTA V was available for free on Epic’s Game store recently and so I snatched a copy. There is the option to listen to your own music as one of the radio stations. Unfortunately, GTA V does not ask you for a location of your music. Instead it expects that you copy the files you want to listen to to a folder in your user directory. Now, although my collection isn’t insanely huge, I still do not want to copy 30 GB of files. There is a better way though, one that I have not found on any other site: A Junction Point.

This is a symbolic link from where GTA V expects the music file to where they are actually located on your computer. This way you are not wasting any space and changes you make to your collection are immediately reflected in the game.

mklink /J "C:\Users\<Your Username>\Documents\Rockstar Games\GTA V\User Music" D:\Music

Remember to use quotes around paths that contain spaces.

Integration Testing with Docker Maven Plugin, PostgreSQL, Flyway (Update)

Recently I have written about how one can create a PostgreSQL Docker image with the Docker Maven Plugin to run integration tests that require a database. While this worked all nice and well during development, the concept has one flaw: the plugin will push the database Docker image to a Docker registry during the deploy phase. I do not want this temporary image to end up there. This is the behavior of the Docker Maven Plugin and I have not found a way to work around this. By “work around this” I mean somehow configure the plugin to ignore this custom PSQL image during the “deploy” phase. Unfortunately, there is only a global <filter> that applies to all the phases of the plugin.

There is a proper solution however, at least for what I was using the database.

Read More »

Assassin’s Creed Valhalla: A Reason Not To Play?

The next Assassin’s Creed will let you play as a Viking that is trying to settle in a new world with his tribe. I am genuinely excited about the setting. As a person that likes Metal music, I have certainly come in contact with Norse Mythology by ways of Amon Amarth and other bands. There is also a bit of that in some of the Marvel movies and a lot of that in the Netflix show Vikings.

Now what does that have to do with not wanting to play Assassin’s Creed Valhalla?

It is about the premise. You and your tribe sailing to England and taking land by force. The last part is the important one: “taking land by force”. From what is known about the game at the time of writing this blog post, one central element of the game will likely be that you and your comrades must raid random villages to expand your settlement. That means threatening or even killing innocent people, robbing them of their goods and burning down their houses. You are basically starting a war and civilians will be caught in the crossfire. That is what I have an issue with.

It is a similar experience with the Netflix Vikings show. I am not sure if I should like it or not – ignoring that sometimes it moves very slowly and treads on the brink of utter boredom.

I am not averse to violence in games. Apart from the Anno series and maybe some racing games like Dirt, almost everything I play revolves around violence – now that I think about it… that’s kind of sad. But I do not want to swing the anti-violence Mjölnir and debate whether violence in games is good or bad. I am certainly not that morally correct, at least not in video games. However, there is something about purposefully harming innocent civilians that makes me think twice.

It is too early to know anything for sure and I am basing my opinion on trailers and discussions that you can find on the YouTube. It is just something that came to mind and made me think about it for a moment. It depends on how violence in general, and with regards to the raids in this game in particular, is implemented. I hope it will not just be a mindless slaughter.

Windows Subsystem for Linux (WSL) Docker: error storing credentials – err: exit status 1, out: Cannot autolaunch D-Bus without X11 $DISPLAY

Recently at work, when copying an application from our internal Docker Registry to Azure, I ran into the following error in my WSL Ubuntu installation.

Login at docker..com
Username: 
Password:
Error saving credentials: error storing credentials - err: exit status 1, out: `Cannot autolaunch D-Bus without X11 $DISPLAY`
ERROR: source registry login failed

The easiest fix I found was to install the gnupg2 and pass packages.

sudo apt install gnupg2 pass 

One important thing to note regarding security: the output mentioned storing the credentials in plain text as a result somewhere in the WSL user’s /home directory. If you are very conscious about where passwords are stored, do not use this solution or remove the password file afterwards. That’s good enough for me at the moment, I just needed to get this to work somehow.

The Worst “Accept Cookie Policy” Implementation

All the cookie policy notifications on every website are a nuisance in and of itself. There is one special kind however, that not only bugs you to accept it, but also throws a giant blocking “dialog” in your face that prevents you from using the site while it’s doing… well… I have no friggin’ clue what it’s doing. What I know is that it takes forever to get out of my way.

There’s not much content here other than this short rant about this terrible TrustArc / TRUSTe cookie accepting widget thingy that takes about a minute to do its thing. Why do websites add this to their page? Don’t they test it first? Does that save so much time in development that annoying the users is worth it? How much does that tell you about a website’s owner? I hate these things!

Integration Testing With Docker Maven Plugin, PostgreSQL, Flyway

Some things in software development require more than mocks and unit testing. If your application uses a database it makes sense to also hit that database in automated testing to ensure custom SQL queries work correctly, Hibernate relations are set up properly and also that database migrations are successful.

This blog post was written with a focus on the latter. I will be using Spring Boot talking to a PostgreSQL database. The database structure is managed via Flyway and, basically customary for Java applications, Maven serves as the build and dependency management tool. Docker will also play a role because we’ll be creating and running a PostgreSQL docker image for testing. From Maven. Every time the test is executed. And to spice things up, we’ll also create a custom database and user in that dockerized PSQL image.

I have created a working sample on Github and you can follow every single step by taking a look at the commit history. There you can see individual changes, starting from an empty Spring Boot application with no database to the final solution with Spring Data JPA and Flyway.

In the following sections and snippets, I will highlight the important parts of each step.

Read More »

OneDrive Sync On Linux With RCLONE

In my quest to move to Linux as a daily driver it was important for me that I could continue to use Microsoft’s OneDrive cloud storage. Unsurprisingly, Windows 10 comes bundled with a OneDrive sync client. There is no official Linux support though, so I had to resort to a 3rd party tool. Luckily, there is a very powerful utility called rclone that does almost exactly what I want and I’ll explain how I have it set up to suit my needs.

Spoiler: it’s not as convenient as Microsoft’s sync client, but it has other things going for it.

Read More »