Posts

Showing posts from 2022

Running unit or integration tests in specific order with junit platform suite

The intention of this example is not to encourage running unit or integration test in a specific in the build. Instead this is a powerful and handy way to reproduce random build failure due to test clashing with each other or lack of isolation between tests. The fundamental idea is to temporarily create a junit platform suite and run the tests in the same order which caused the build failure and reproduce the failure in a consistent and deterministic way. Once the failure can be reliably reproduced, the clashing test can be easily narrowed down. In order to create this sample suite, we need the following test dependency: group id: org.junit.platform artifact id: junit-platform-suite version: <<latest>> Create a sample Junit suite and run it using your favourite IDE. package com.harishkannarao.test; import org.junit.platform.suite.api. SelectClasses ; import org.junit.platform.suite.api. Suite ; @Suite // order of the test classes is very important. E.g ExampleTest runs firs...

Docker save and load images offline

 In some rare occasions, it was beneficial for me to save (export) the docker as a local file and load (import) the local file as docker image. Hence, I am posting the commands to save, load and tag the images to enable offline working with docker. In order to save the image, first we need to pull the image from a docker registry (default docker hub or any other registry). Pull docker image: docker pull postgres:10.6 Save (export) docker image: docker save -o /tmp/postgres-10.6.tar postgres:10.6 Load (import) docker image: docker load -i /tmp/postgres-10.6.tar See the loaded image: docker images postgres:10.6 Create a new tag from the loaded image: docker tag postgres:10.6 org.example/postgres:10.6

minikube as drop in replacement for Docker Desktop (Mac and Windows)

For a very long time, development time dependencies like postgres (database), kafka (message broker) was run using docker desktop (Docker for Mac / Docker for Windows). However due to recent changes to licensing, docker desktop is not free for all organisations. As a developer, if you are in an organisation who can't provide Docker Desktop, then minikube can be used as a drop in replacement for Docker Engine, so that your dependency scripts using docker cli can continue to work. The following contents explains the bare minimal commands needed to run minikube which will work if you are running dependencies using docker cli via: Shell scripts Maven docker plugin Gradle docker plugin TestContainers IDE (Intellij / Eclipse / VS Code) Plugin Install minikube: https://minikube.sigs.k8s.io/docs/start/ Start minikube: minikube start Stop minikube: minikube stop Delete minikube cluster: minikube delete Delete all minikube clusters: minikube delete --all See minikube dashboard: minikube dash...

Google Auto Value with Jackson Json

 I got a chance to work on a code base which used Google's Auto Value library and Jackson library for serialising and deserialising Json request and response payload. I tried to get the sweet spot with minimal need of annotations from Auto Value and Jackson. The following example shows the bare minimal change need to generate Json payload. It has the flexibility to construct the value object using builder pattern and ability to handle optional fields, collections and change the field name if required. package com.harishkannarao.example; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.auto.value.AutoValue; import java.time.OffsetDateTime; import java.util.List; import java.util.Optional; import java.util.UUID; @AutoValue @JsonDeserialize(builder = AutoValue_ExampleModel.Builder.class) public abstract class ExampleModel { ...