[KYUUBI #4451] Skip etcd test if no docker env

### _Why are the changes needed?_

Skip etcd test if no docker env.

It would fail if no docker env
```
org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClientSuite *** ABORTED ***
  java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
  at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$6(DockerClientProviderStrategy.java:257)
  at java.util.Optional.orElseThrow(Optional.java:290)
  at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:247)
  at org.testcontainers.DockerClientFactory.getOrInitializeStrategy(DockerClientFactory.java:135)
  at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:171)
  at org.testcontainers.containers.Network$NetworkImpl.create(Network.java:69)
  at org.testcontainers.containers.Network$NetworkImpl.getId(Network.java:62)
  at io.etcd.jetcd.launcher.EtcdClusterImpl.start(EtcdClusterImpl.java:72)
  at org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClientSuite.beforeAll(EtcdDiscoveryClientSuite.scala:48)
```
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #4451 from ulysses-you/skip-etcd.

Closes #4451

a5e65adb4 [ulysses-you] isDockerAvailable
39baad662 [ulysses-you] Skip etcd test is no docker env

Authored-by: ulysses-you <ulyssesyou18@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
ulysses-you 2023-03-08 09:57:12 +08:00 committed by Cheng Pan
parent bc96038f8f
commit 86f7537a8e
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D

View File

@ -22,6 +22,9 @@ import java.nio.charset.StandardCharsets
import scala.collection.JavaConverters._
import io.etcd.jetcd.launcher.{Etcd, EtcdCluster}
import org.scalactic.source.Position
import org.scalatest.Tag
import org.testcontainers.DockerClientFactory
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.ha.HighAvailabilityConf.{HA_ADDRESSES, HA_CLIENT_CLASS}
@ -41,25 +44,38 @@ class EtcdDiscoveryClientSuite extends DiscoveryClientTests {
var conf: KyuubiConf = KyuubiConf()
.set(HA_CLIENT_CLASS, classOf[EtcdDiscoveryClient].getName)
private val hasDockerEnv = DockerClientFactory.instance().isDockerAvailable
override def beforeAll(): Unit = {
etcdCluster = new Etcd.Builder()
.withNodes(2)
.build()
etcdCluster.start()
conf = new KyuubiConf()
.set(HA_CLIENT_CLASS, classOf[EtcdDiscoveryClient].getName)
.set(HA_ADDRESSES, getConnectString)
if (hasDockerEnv) {
etcdCluster = new Etcd.Builder()
.withNodes(2)
.build()
etcdCluster.start()
conf = new KyuubiConf()
.set(HA_CLIENT_CLASS, classOf[EtcdDiscoveryClient].getName)
.set(HA_ADDRESSES, getConnectString)
}
super.beforeAll()
}
override def afterAll(): Unit = {
super.afterAll()
if (etcdCluster != null) {
if (hasDockerEnv && etcdCluster != null) {
etcdCluster.close()
etcdCluster = null
}
}
override protected def test(
testName: String,
testTags: Tag*)(testFun: => Any)(implicit pos: Position): Unit = {
if (hasDockerEnv) {
super.test(testName, testTags: _*)(testFun)
}
// skip test
}
test("etcd test: set, get and delete") {
withDiscoveryClient(conf) { discoveryClient =>
val path = "/kyuubi"