a blog about programming

  • Graceful shutdown of Kubernetes pod when using istio

    Recently I worked on a project for which we noticed a lot of database connection errors when a new version of the pod was deployed on Kubernetes. At first we thought that the during the shutdown the application cleaned up the database connection pool too soon, but it appeared the application had database connection errors…

  • Combining fixed arguments with variable arguments in Mockito with Scala

    When you use Mockito to mock an object and add behavior, you sometimes need to combine variable arguments with fixed arguments. When you do that in this way when(client.execute(“myId1”, any[String]) You get as error Invalid use of argument matchers with the explanation that you should use eq as a matcher for the fixed argument. However,…

  • Using eventually in an AsyncWordSpec

    This is my second post regarding the use of eventually in an AsyncWordSpec. The previous post was about using futures in an eventually block in an AsyncWordSpec. This one deals with how to use eventually in an AsyncWordSpec when you don’t use a future. The way to use eventually is this case applies to ScalaTest…

  • Using different event journal configurations in one actor system

    If you use multiple persistent actors with Akka, you normally configure one event journal, but in case you want to configure different event journals for different persistent actors, you need to be careful to configure everything correctly, otherwise the events are persisted, but when the persistent actor is reinstantiated, the state isn’t recovered because the…

  • Using futures in eventually with an asynchronous ScalaTest

    In ScalaTest you can use asynchronous specs, like AsyncWordSpec. In the tests you can then use the assertions like you do in a non-asynchronous spec, like WordSpec, but if a method you want to test returns a Future, you can map the result of the method to an assertion. E.g.: class AsyncTestSpec extends AsyncWordSpec with…

  • Using Akka Streams with Kafka and Avro

    The easiest way to use Akka Streams with Kafka is by using the Alpakka Kafka Connector.  The documentation page describes in detail how to use Akka Streams both as a Kafka producer and as a consumer. Even though Kafka is agnostic regarding to the message format, the preferred message format is Avro and the preferred solution…

  • Loading a configuration in Scala

    For reading a configuration in Scala, TypeSafe Config is often used. This blog post discusses the  problems with TypeSafe Config and a better alternative, PureConfig. As an example I’m using the following small configuration file: database { schema = “jdbc:postgresql://localhost:5432/my_database” user = “username” password = “pw” } TypeSafe Config TypeSafe Config is a well known and…

  • Integration tests using databases in Scala

    If you use a SQL or NoSQL database, you want to have an integration test in place that tests the code that uses the database. One way to do this, is to require that an actual database is running, but this requires a database to be running on your build server and you need to…

  • cats’ IO Monad

    As a functional programmer, we want to push the side effects to the border of our program, to reason easier about our program. We want to use pure functions, so when reasoning about a program, we can replace the function call with the result, without changing the meaning of the program. Using standard Scala futures…