scala - 从 docker-it-scala 旋转 redis

标签 scala docker redis sbt

我正在尝试从 docker-it-scala 旋转一个 docker 容器. 目标是能够针对容器中的 redis 运行单元测试,而不是作为托管服务 (AWS ElastiCache) 的产品

我构建了一个服务,紧跟

import com.spotify.docker.client.{DefaultDockerClient, DockerClient}
import com.whisk.docker.impl.spotify.SpotifyDockerFactory
import com.whisk.docker.{DockerContainer, DockerFactory, DockerKit, DockerReadyChecker}

// Look at https://github.com/whisklabs/docker-it-scala
// .. and let yourself be inspired
trait DockerRedisService extends DockerKit {

  val redisDefaultPort = 6379

  val redisContainer = DockerContainer("redis")
    .withPorts(redisDefaultPort -> None)
    .withReadyChecker(DockerReadyChecker.LogLineContains("Ready to accept connections"))

  abstract override def dockerContainers: List[DockerContainer] =
    redisContainer :: super.dockerContainers

}

从那里,我应该能够运行一些单元测试

class ElastiCache extends FlatSpec with Matchers with BeforeAndAfter with ScalaFutures with DockerRedisService {

  private val client: DockerClient = DefaultDockerClient.fromEnv().build()
  override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory(client)

  implicit val pc = PatienceConfig(Span(40, Seconds), Span(1, Second))

  "the redis container" should "be ready with log line checker" in {
    isContainerReady(redisContainer).futureValue shouldBe true
    redisContainer.getPorts().futureValue.get(6379 ) should not be empty
    redisContainer.getIpAddresses().futureValue should not be Seq.empty
  }

单元测试只是在没有太多信息的情况下超时。

看看我如何从那个 redis 中 hset 和 hget 一些值会很有用。

最佳答案

您缺少指定 java-docker 后端的执行特征。

您的 ElastiCache 类 应该扩展一个或另一个:

使用docker-testkit-impl-docker-java

with DockerTestKit with DockerKitDockerJava

使用docker-testkit-impl-spotify

with DockerTestKit with DockerKitDockerSpotify

关于scala - 从 docker-it-scala 旋转 redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48510658/

相关文章:

Redis 设置默认顺序

redis - 有没有公​​司提供redis的企业支持?

scala - 如何将时间戳添加到我的用户 session 中并设置最长不活动持续时间?

docker - 通过 docker compose 重新使用现有卷

docker - 更改构建 docker 镜像的 PATH

Redis 在负载繁忙时无法连接

scala - 高级类型的辅助模式

scala - 返回会破坏引用透明度吗?

scala - 如何在 case 类中指定多个构造函数?

docker - 无法在 kubernetes 上运行 docker