Posts

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 { ...

ReactJs + NodeJs for Java Developers

  Background I am a Java Developer who enjoyed developing both server side web (frontend) and server side (backend) Http API. In recent years, Java or other JVM languages are predominantly used for server side API and NodeJs stack is the defacto standard for Frontend. This page explores the frontend (UI) development using ReactJs + NodeJs stack using Java lens by comparing tools and framework in Java stack. Source code available at:  https://github.com/harishkannarao/react-nextjs-rest-api In this repository, I explored the ReactJs ecosystem to build, test (unit and integration) and deploy a pure client side rendering (CSR) web application. Development Stack ReactJs is the basic building block to build the UI components and NextJs is built on top of ReactJs to create pages with routing and deployment tools for application built with ReactJs. Axios is a very popular Http Client library to fetch data from server side Http APIs NodeJs Java ReactJs  ...

nodeenv: Isolated node runtimes on MacOS

nodeenv allows to create isolated node runtimes per project which resembles to virtual environments in python world. In enterprise projects, where multiple projects are built against different versions of node runtime and dependencies, it is advantageous to have nodeenv to install multiple versions of node runtimes at project level. Install nodeenv brew install nodeenv or pip install nodeenv List available node runtime versions nodeenv --list Create latest node version as virtual environment nodeenv .nodeenv Create a specific node version as virtual environment nodeenv --node=14.15.0 .nodeenv Activate a virtual environment source .nodeenv/bin/activate Verify node and npm version node --version npm --version Install a package scoped to the virutal environment npm install -g cypress Deactivate or exit from virtual environment deactivate_node Delete the virtual environment rm -rf .nodeenv

GitOps - Viewing and Creating git tags

In a team following continuous delivery based on git tags or otherwise popularly known as GitOps, there will be a frequent need to list the existing tags in a repository in chronological order so that a new tag can be created based on recent commit (HEAD) from master / main branch. The following chained command will list all the remote tags in chronological order along with latest commit, so that new release tags can be quickly created through command line. List all annotated tags name with the commit SHA in chronological order along with recent commit id git fetch origin && git checkout master && git pull && git ls-remote --tags --sort=creatordate origin && git log -n 1 Create a new tag based on master / main branch or specific commit SHA and push the tag to remote server tag_name="production-v1.0" && git tag -a $tag_name master -m "Production version 1.0" && git push origin $tag_name