parent
04a6b9f50f
commit
ccb542734e
1 changed files with 22 additions and 11 deletions
|
|
@ -5,13 +5,10 @@
|
|||
package akka.cluster
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import akka.ConfigurationException
|
||||
import akka.actor.ActorSystem
|
||||
import akka.actor.Props
|
||||
|
|
@ -19,6 +16,8 @@ import akka.testkit.TestKit.awaitCond
|
|||
import akka.testkit.TestKit.shutdownActorSystem
|
||||
import akka.util.unused
|
||||
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
class FailingDowningProvider(@unused system: ActorSystem) extends DowningProvider {
|
||||
override val downRemovalMargin: FiniteDuration = 20.seconds
|
||||
override def downingActorProps: Option[Props] = {
|
||||
|
|
@ -76,18 +75,30 @@ class DowningProviderSpec extends AnyWordSpec with Matchers {
|
|||
}
|
||||
|
||||
"stop the cluster if the downing provider throws exception in props method" in {
|
||||
val system = ActorSystem(
|
||||
// race condition where the downing provider failure can be detected and trigger
|
||||
// graceful shutdown fast enough that creating the actor system throws on constructing
|
||||
// thread (or slow enough that we have time to try join the cluster before noticing)
|
||||
val maybeSystem = try {
|
||||
Some(
|
||||
ActorSystem(
|
||||
"auto-downing",
|
||||
ConfigFactory.parseString("""
|
||||
akka.cluster.downing-provider-class="akka.cluster.FailingDowningProvider"
|
||||
""").withFallback(baseConf))
|
||||
""").withFallback(baseConf)))
|
||||
} catch {
|
||||
case NonFatal(_) =>
|
||||
// expected to sometimes happen
|
||||
None
|
||||
}
|
||||
|
||||
maybeSystem.foreach { system =>
|
||||
val cluster = Cluster(system)
|
||||
cluster.join(cluster.selfAddress)
|
||||
|
||||
awaitCond(cluster.isTerminated, 3.seconds)
|
||||
shutdownActorSystem(system)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue