|
14 | 14 | package org.apache.pekko.management.cluster.bootstrap.internal |
15 | 15 |
|
16 | 16 | import java.util.concurrent.atomic.AtomicReference |
| 17 | + |
17 | 18 | import org.apache.pekko |
18 | 19 | import pekko.actor.{ ActorRef, ActorSystem, Props } |
19 | 20 | import pekko.discovery.ServiceDiscovery.{ Resolved, ResolvedTarget } |
20 | 21 | import pekko.discovery.{ Lookup, MockDiscovery } |
21 | 22 | import pekko.http.scaladsl.model.Uri |
22 | | -import com.typesafe.config.ConfigFactory |
23 | 23 | import pekko.management.cluster.bootstrap.internal.BootstrapCoordinator.Protocol.InitiateBootstrapping |
24 | 24 | import pekko.management.cluster.bootstrap.{ ClusterBootstrapSettings, LowestAddressJoinDecider } |
25 | | -import org.scalatest.concurrent.Eventually |
| 25 | +import com.typesafe.config.ConfigFactory |
26 | 26 | import org.scalatest.BeforeAndAfterAll |
| 27 | +import org.scalatest.concurrent.Eventually |
| 28 | +import org.scalatest.matchers.should.Matchers |
27 | 29 | import org.scalatest.time.{ Millis, Seconds, Span } |
| 30 | +import org.scalatest.wordspec.AnyWordSpec |
28 | 31 |
|
29 | 32 | import scala.concurrent.{ Await, Future } |
30 | 33 | import scala.concurrent.duration._ |
31 | | -import org.scalatest.matchers.should.Matchers |
32 | | -import org.scalatest.wordspec.AnyWordSpec |
33 | 34 |
|
34 | 35 | class BootstrapCoordinatorSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll with Eventually { |
35 | 36 | val serviceName = "bootstrap-coordinator-test-service" |
@@ -156,6 +157,39 @@ class BootstrapCoordinatorSpec extends AnyWordSpec with Matchers with BeforeAndA |
156 | 157 | targetsToCheck.flatMap(_.port).toSet shouldBe empty |
157 | 158 | } |
158 | 159 | } |
| 160 | + |
| 161 | + "probe all hosts with fallback port (https)" in { |
| 162 | + |
| 163 | + MockDiscovery.set( |
| 164 | + Lookup(serviceName, portName = None, protocol = Some("tcp")), |
| 165 | + () => |
| 166 | + Future.successful( |
| 167 | + Resolved( |
| 168 | + serviceName, |
| 169 | + List( |
| 170 | + ResolvedTarget("host1", None, None), |
| 171 | + ResolvedTarget("host1", None, None), |
| 172 | + ResolvedTarget("host2", None, None), |
| 173 | + ResolvedTarget("host2", None, None))))) |
| 174 | + |
| 175 | + val targets = new AtomicReference[List[ResolvedTarget]](Nil) |
| 176 | + val coordinator = system.actorOf(Props(new BootstrapCoordinator(discovery, joinDecider, settings) { |
| 177 | + override def ensureProbing(selfContactPointScheme: String, contactPoint: ResolvedTarget): Option[ActorRef] = { |
| 178 | + println(s"Resolving $contactPoint") |
| 179 | + val targetsSoFar = targets.get |
| 180 | + targets.compareAndSet(targetsSoFar, contactPoint +: targetsSoFar) |
| 181 | + None |
| 182 | + } |
| 183 | + })) |
| 184 | + coordinator ! InitiateBootstrapping(secureSelfUri) |
| 185 | + eventually { |
| 186 | + val targetsToCheck = targets.get |
| 187 | + targetsToCheck.length should be >= 2 |
| 188 | + targetsToCheck.map(_.host) should contain("host1") |
| 189 | + targetsToCheck.map(_.host) should contain("host2") |
| 190 | + targetsToCheck.flatMap(_.port).toSet shouldBe empty |
| 191 | + } |
| 192 | + } |
159 | 193 | } |
160 | 194 |
|
161 | 195 | "BootstrapCoordinator target filtering" should { |
|
0 commit comments