Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DockerClickhouseService to facilitate clickhouse integration in docker #152

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export DOCKER_HOST=unix:///var/run/docker.sock
- [Mongodb](https://github.com/whisklabs/docker-it-scala/blob/master/samples/src/main/scala/com/whisk/docker/testkit/DockerMongodbService.scala)
- [MySQL](https://github.com/whisklabs/docker-it-scala/blob/master/samples/src/main/scala/com/whisk/docker/testkit/DockerMysqlService.scala)
- [Postgres](https://github.com/whisklabs/docker-it-scala/blob/master/samples/src/main/scala/com/whisk/docker/testkit/DockerPostgresService.scala)
- [Clickhouse](https://github.com/whisklabs/docker-it-scala/blob/master/samples/src/main/scala/com/whisk/docker/testkit/DockerClickhouseService.scala)
- [Multi container test](https://github.com/whisklabs/docker-it-scala/blob/master/tests/src/test/scala/com/whisk/docker/testkit/test/MultiContainerTest.scala)

# Defining Containers

There are two ways to define a docker container.
Expand Down Expand Up @@ -76,7 +76,7 @@ You can check [usage example](https://github.com/whisklabs/docker-it-scala/blob/
- Mongodb => `docker.mongo`
- Neo4j => `docker.mysql`
- Postgres => `docker.postgres`

- Clickhouse => `docker.clickhouse`
### Fields

- `image-name` required (String)
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ lazy val tests =
name := "docker-testkit-tests",
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "42.1.4" % "test",
"mysql" % "mysql-connector-java" % "5.1.44" % "test"
"mysql" % "mysql-connector-java" % "5.1.44" % "test",
"com.clickhouse" % "clickhouse-jdbc" % "0.5.0" % "test"
)
)
.dependsOn(core, scalatest, samples % "test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ object DockerReadyChecker {
"mysql"
} else if (driverLower.contains("postgres")) {
"postgresql"
} else if (driverLower.contains("clickhouse")) {
"clickhouse"
} else {
throw new IllegalArgumentException("unsupported database for ready check")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.whisk.docker.testkit

import com.spotify.docker.client.messages.PortBinding
import com.whisk.docker.testkit.scalatest.DockerTestKitForAll
import org.scalatest.Suite

import scala.concurrent.duration._

trait DockerClickhouseService extends DockerTestKitForAll { self: Suite =>
override val dockerTestTimeouts: DockerTestTimeouts = DockerTestTimeouts(pull = 10.minutes, init = 10.minutes, stop = 1.minutes)

def ClickhouseAdvertisedPort = 8123
def ClickhouseExposedPort = 8123

val ClickhouseUser = "default"
val ClickhousePassword = ""

val clickhouseContainer = ContainerSpec("clickhouse/clickhouse-server:23.6")
.withEnv(s"CLICKHOUSE_USER=$ClickhouseUser", s"CLICKHOUSE_PASSWORD=$ClickhousePassword")
.withPortBindings((ClickhouseAdvertisedPort, PortBinding.of("0.0.0.0", ClickhouseExposedPort)))
.withReadyChecker(
DockerReadyChecker
.Jdbc(
driverClass = "com.clickhouse.jdbc.ClickHouseDriver",
user = ClickhouseUser,
password = Some(ClickhousePassword)
)
.looped(15, 1.second)
)
.toContainer

override val managedContainers: ManagedContainers = clickhouseContainer.toManagedContainer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.whisk.docker.testkit.test

import com.whisk.docker.testkit.{ContainerState, DockerClickhouseService}
import org.scalatest.funsuite.AnyFunSuite

class ClickhouseServiceTest extends AnyFunSuite with DockerClickhouseService {
test("test container started") {
assert(clickhouseContainer.state().isInstanceOf[ContainerState.Ready], "clickhouse is ready")
assert(clickhouseContainer.mappedPortOpt(ClickhouseAdvertisedPort) === Some(ClickhouseExposedPort),
"clickhouse port exposed")
}
}