* change package name to akka.cluster.sbr * reference.conf has same config paths * akka.cluster.sbr.SplitBrainResolverProvider instead of com.lightbend.akka.sbr.SplitBrainResolverProvider * dependency from akka-cluster to akka-coordination, for lease strategy * move TestLease to akka-coordination and use that in SBR tests * remove keep-referee strategy * use keep-majority by default * review and adjust reference documentation Co-authored-by: Johan Andrén <johan@markatta.com> Co-authored-by: Johannes Rudolph <johannes.rudolph@gmail.com> Co-authored-by: Christopher Batey <christopher.batey@gmail.com> Co-authored-by: Arnout Engelen <github@bzzt.net>
This commit is contained in:
parent
e0586e546c
commit
c45e6ef39b
37 changed files with 5612 additions and 67 deletions
102
akka-docs/src/test/scala/docs/coordination/LeaseDocSpec.scala
Normal file
102
akka-docs/src/test/scala/docs/coordination/LeaseDocSpec.scala
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.coordination
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import akka.cluster.Cluster
|
||||
import akka.coordination.lease.LeaseSettings
|
||||
import akka.coordination.lease.scaladsl.Lease
|
||||
import akka.coordination.lease.scaladsl.LeaseProvider
|
||||
import akka.testkit.AkkaSpec
|
||||
|
||||
//#lease-example
|
||||
class SampleLease(settings: LeaseSettings) extends Lease(settings) {
|
||||
|
||||
override def acquire(): Future[Boolean] = {
|
||||
Future.successful(true)
|
||||
}
|
||||
|
||||
override def acquire(leaseLostCallback: Option[Throwable] => Unit): Future[Boolean] = {
|
||||
Future.successful(true)
|
||||
}
|
||||
|
||||
override def release(): Future[Boolean] = {
|
||||
Future.successful(true)
|
||||
}
|
||||
|
||||
override def checkLease(): Boolean = {
|
||||
true
|
||||
}
|
||||
}
|
||||
//#lease-example
|
||||
|
||||
object LeaseDocSpec {
|
||||
|
||||
def config() =
|
||||
ConfigFactory.parseString("""
|
||||
jdocs-lease.lease-class = "jdocs.coordination.LeaseDocTest$SampleLease"
|
||||
#lease-config
|
||||
akka.actor.provider = cluster
|
||||
docs-lease {
|
||||
lease-class = "docs.coordination.SampleLease"
|
||||
heartbeat-timeout = 100s
|
||||
heartbeat-interval = 1s
|
||||
lease-operation-timeout = 1s
|
||||
# Any lease specific configuration
|
||||
}
|
||||
#lease-config
|
||||
""".stripMargin)
|
||||
|
||||
def blackhole(stuff: Any*): Unit = {
|
||||
stuff.toString
|
||||
()
|
||||
}
|
||||
def doSomethingImportant(leaseLostReason: Option[Throwable]): Unit = {
|
||||
leaseLostReason.map(_.toString)
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
class LeaseDocSpec extends AkkaSpec(LeaseDocSpec.config) {
|
||||
import LeaseDocSpec._
|
||||
|
||||
"A docs lease" should {
|
||||
"scala lease be loadable from scala" in {
|
||||
|
||||
//#lease-usage
|
||||
val lease = LeaseProvider(system).getLease("<name of the lease>", "docs-lease", "owner")
|
||||
val acquired: Future[Boolean] = lease.acquire()
|
||||
val stillAcquired: Boolean = lease.checkLease()
|
||||
val released: Future[Boolean] = lease.release()
|
||||
//#lease-usage
|
||||
|
||||
//#lost-callback
|
||||
lease.acquire(leaseLostReason => doSomethingImportant(leaseLostReason))
|
||||
//#lost-callback
|
||||
|
||||
//#cluster-owner
|
||||
val owner = Cluster(system).selfAddress.hostPort
|
||||
//#cluster-owner
|
||||
|
||||
// remove compiler warnings
|
||||
blackhole(acquired, stillAcquired, released, owner)
|
||||
|
||||
}
|
||||
|
||||
"java lease be loadable from scala" in {
|
||||
val lease = LeaseProvider(system).getLease("<name of the lease>", "jdocs-lease", "owner")
|
||||
val acquired: Future[Boolean] = lease.acquire()
|
||||
val stillAcquired: Boolean = lease.checkLease()
|
||||
val released: Future[Boolean] = lease.release()
|
||||
lease.acquire(leaseLostReason => doSomethingImportant(leaseLostReason))
|
||||
|
||||
blackhole(acquired, stillAcquired, released)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue