alpakka icon indicating copy to clipboard operation
alpakka copied to clipboard

Use testcontainers to setup DynamoDb docker

Open mdedetrich opened this issue 2 years ago • 1 comments

Replaces manual starting of dynamodb docker containers in github actions/docker-compose with https://github.com/testcontainers/testcontainers-scala.

In addition to using testcontainers the PR also improves and removes boilerplate for system/HTTP cleanup after test run (currently these tests throw an exception during cleanup phase of afterAll). There was also duplicate client.close() calls, i.e. client.close() was being called both manually in afterAll but also with system.registerOnTermination(client.close()) (which executes when actor system is shutdown).

Note that ForAllAnyWordSpecContainer/ForAllAsyncWordSpecContainer is necessary because both run/runTest is defined in both super traits.

There are also some slight improvements in generated documentation, i.e. before

import akka.actor.ActorSystem

import com.github.matsluni.akkahttpspi.AkkaHttpClient
import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider}
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient


// Don't encode credentials in your source code!
// see https://doc.akka.io/docs/alpakka/current/aws-shared-configuration.html
private val credentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))
implicit val client: DynamoDbAsyncClient = DynamoDbAsyncClient
  .builder()
  .region(Region.AWS_GLOBAL)
  .credentialsProvider(credentialsProvider)
  .httpClient(AkkaHttpClient.builder().withActorSystem(system).build())
  // Possibility to configure the retry policy
  // see https://doc.akka.io/docs/alpakka/current/aws-shared-configuration.html
  // .overrideConfiguration(...)
  .build()

system.registerOnTermination(client.close())

after

import akka.actor.ActorSystem

import com.github.matsluni.akkahttpspi.AkkaHttpClient
import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider}
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient


// Don't encode credentials in your source code!
// see https://doc.akka.io/docs/alpakka/current/aws-shared-configuration.html
implicit val client: DynamoDbAsyncClient = DynamoDbAsyncClient
  .builder()
  .region(Region.AWS_GLOBAL)
  .credentialsProvider(credentialsProvider)
  .httpClient(AkkaHttpClient.builder().withActorSystem(system).build())
  // Possibility to configure the retry policy
  // see https://doc.akka.io/docs/alpakka/current/aws-shared-configuration.html
  // .overrideConfiguration(...)
  .build()

system.registerOnTermination(client.close())

(notice removal of private val credentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x")))

References https://github.com/akka/alpakka/issues/2841

mdedetrich avatar Apr 18 '22 11:04 mdedetrich

Test failed due to unrelated link validation, i.e.

`[https://www.2uo.de/myths-about-urandom/`](https://www.2uo.de/myths-about-urandom/%60) status -1 akka.stream.StreamTcpException: Tcp command [Connect(www.2uo.de:443,None,List(),Some(10 seconds),true)] failed because of java.net.ConnectException: Connection refused
 - docs/alpakka/snapshot/ftp.html

mdedetrich avatar Apr 18 '22 12:04 mdedetrich

@mdedetrich Thanks for your contributions. I'm closing the PRs for switching to testcontainers because we have a setup with docker compose that is working pretty well and we don't have the bandwidth to change and risk instability at the moment.

patriknw avatar Aug 23 '22 12:08 patriknw