This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-management.git


The following commit(s) were added to refs/heads/main by this push:
     new 91862572 use org.testcontainers:consul (#298)
91862572 is described below

commit 918625729bba0e50679b717fa7343375ff0b4d1f
Author: PJ Fanning <[email protected]>
AuthorDate: Wed Aug 28 12:23:13 2024 +0100

    use org.testcontainers:consul (#298)
    
    * use org.testcontainers:consul
    
    * Update ConsulDiscoverySpec.scala
    
    * fix test
    
    * scalafmt
---
 .../bootstrap/discovery/ConsulDiscoverySpec.scala  | 36 ++++++++++++++++------
 project/Dependencies.scala                         |  2 +-
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git 
a/discovery-consul/src/test/scala/org/apache/pekko/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala
 
b/discovery-consul/src/test/scala/org/apache/pekko/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala
index 064d6c53..dfde9f54 100644
--- 
a/discovery-consul/src/test/scala/org/apache/pekko/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala
+++ 
b/discovery-consul/src/test/scala/org/apache/pekko/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala
@@ -17,7 +17,7 @@ import com.google.common.net.HostAndPort
 import com.orbitz.consul.Consul
 import com.orbitz.consul.model.catalog.ImmutableCatalogRegistration
 import com.orbitz.consul.model.health.ImmutableService
-import com.pszymczyk.consul.{ ConsulProcess, ConsulStarterBuilder }
+import com.typesafe.config.ConfigFactory
 import org.apache.pekko
 import pekko.actor.ActorSystem
 import pekko.discovery.ServiceDiscovery.ResolvedTarget
@@ -28,6 +28,7 @@ import org.scalatest.concurrent.ScalaFutures
 import org.scalatest.matchers.should.Matchers
 import org.scalatest.time.{ Millis, Seconds, Span }
 import org.scalatest.wordspec.AnyWordSpecLike
+import org.testcontainers.consul.ConsulContainer
 
 import java.net.InetAddress
 import scala.concurrent.duration._
@@ -39,12 +40,16 @@ class ConsulDiscoverySpec
     with TestKitBase
     with ScalaFutures {
 
-  private val consul: ConsulProcess = 
ConsulStarterBuilder.consulStarter().withHttpPort(8500).build().start()
+  private val consul = new ConsulContainer("hashicorp/consul:1.15")
+  consul.start()
 
   "Consul Discovery" should {
     "work for defaults" in {
+      val consulPort = consul.getFirstMappedPort()
       val consulAgent =
-        
Consul.builder().withHostAndPort(HostAndPort.fromParts(consul.getAddress, 
consul.getHttpPort)).build()
+        Consul.builder()
+          .withHostAndPort(HostAndPort.fromParts(consul.getHost(), consulPort))
+          .build()
       consulAgent
         .catalogClient()
         .register(
@@ -63,13 +68,24 @@ class ConsulDiscoverySpec
             .address("localhost")
             .build())
 
-      val lookupService = new ConsulServiceDiscovery(system)
-      val resolved = lookupService.lookup("test", 10.seconds).futureValue
-      resolved.addresses should contain(
-        ResolvedTarget(
-          host = "127.0.0.1",
-          port = Some(1234),
-          address = Some(InetAddress.getByName("127.0.0.1"))))
+      val cfg = ConfigFactory.parseString(s"""
+        pekko.discovery.pekko-consul {
+          consul-host = "${consul.getHost()}"
+          consul-port = $consulPort
+        }
+        """).withFallback(system.settings.config)
+      val testSystem = ActorSystem("defaultTest", cfg)
+      try {
+        val lookupService = new ConsulServiceDiscovery(testSystem)
+        val resolved = lookupService.lookup("test", 10.seconds).futureValue
+        resolved.addresses should contain(
+          ResolvedTarget(
+            host = "127.0.0.1",
+            port = Some(1234),
+            address = Some(InetAddress.getByName("127.0.0.1"))))
+      } finally {
+        testSystem.terminate()
+      }
     }
   }
 
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index 028b498a..4b56e8d6 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -69,7 +69,7 @@ object Dependencies {
     "org.apache.pekko" %% "pekko-actor" % pekkoVersion,
     "org.apache.pekko" %% "pekko-discovery" % pekkoVersion,
     "com.orbitz.consul" % "consul-client" % "1.5.3",
-    "com.pszymczyk.consul" % "embedded-consul" % "2.2.1" % Test,
+    "org.testcontainers" % "consul" % "1.20.1" % Test,
     "org.scalatest" %% "scalatest" % scalaTestVersion % Test,
     "org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test,
     "org.apache.pekko" %% "pekko-slf4j" % pekkoVersion % Test,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to