Dynamic containers dynamic ports

How to run integration tests with Docker container on a random port

Apr 13, 2020

Running integration tests locally with Docker on fixed ports is not always possible due to port conflicts. This is especially true when running tests in shared CI environment.

Fortunately, testcontainers allow to start Docker containers listening on a random port. Here is an example:

// create and start container
val container = new GenericContainer("softwaremill/elasticmq-native")


// create sqsClient
val sqsPort = container.getMappedPort(9324)

val clientBuilder = SqsAsyncClient.builder()

val sqsClient = clientBuilder.build();

// get queue usr
val queueUrl = getQueueUrl(sqsQueueName);

    do some tests here

// close resources

See Also

Kotlin Playground Shortcode for Hugo

Kotlin Playground is HTML component which creates Kotlin-aware editors capable of running code from HTML block elements. Here I explain how to embed runnable Kotlin code block in your Hugo-powered blog.

Building Data Pipeline with Kotlin Coroutines Actors

In this post I will show how to build simple data-enriching pipeline using Kotlin coroutines. I will use Channels and Actors abstractions provided by kotlinx-coroutines. In Actors model “actors” are the universal primitives of concurrent computation. In response to a message that it receives, an actor can: make local decisions, create more actors, send more messages, and determine how to respond to the next message received. Actors may modify their own private state, but can only affect each other through messages (avoiding the need for any locks).

Customizing REST API Error Response in Spring Boot / Spring-Security-OAuth2

Defining error format is important part of REST API design.

Spring-Boot and Spring Security provide pretty nice error handling for RESTful APIs out of the box. Although it has to be documented, especially when contract-first approach to API design is used.

It is good idea to follow some common format for error responses. But OAuth2 specification and Spring Boot format may not satisfy those requirements.

logo   Never miss a story, subscribe to our newsletter