Strict compiler settings for discovery (#26552)

This commit is contained in:
Christopher Batey 2019-03-20 08:12:40 +00:00 committed by Arnout Engelen
parent d681eb10ab
commit 886088f03b
4 changed files with 22 additions and 18 deletions

View file

@ -143,12 +143,11 @@ class FakeTestDiscovery extends ServiceDiscovery {
class FakeTestDiscovery2 extends FakeTestDiscovery class FakeTestDiscovery2 extends FakeTestDiscovery
class DiscoveryException(message: String) extends Exception class DiscoveryException(message: String) extends Exception(message)
class ExceptionThrowingDiscovery extends ServiceDiscovery {
def lookup(lookup: Lookup, resolveTimeout: FiniteDuration): Future[Resolved] = ???
throw new DiscoveryException("Test Exception")
class ExceptionThrowingDiscovery extends FakeTestDiscovery {
bad()
def bad(): Unit = {
throw new DiscoveryException("oh no")
}
} }

View file

@ -8,6 +8,7 @@ import akka.actor.{ ActorSystem, ExtendedActorSystem }
import akka.discovery.ServiceDiscovery.{ Resolved, ResolvedTarget } import akka.discovery.ServiceDiscovery.{ Resolved, ResolvedTarget }
import akka.discovery.{ Discovery, Lookup, ServiceDiscovery } import akka.discovery.{ Discovery, Lookup, ServiceDiscovery }
import akka.testkit.TestKit import akka.testkit.TestKit
import akka.util.unused
import com.typesafe.config.{ Config, ConfigFactory } import com.typesafe.config.{ Config, ConfigFactory }
import org.scalatest.concurrent.ScalaFutures import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike } import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }
@ -16,7 +17,7 @@ import scala.concurrent.Future
import scala.concurrent.duration._ import scala.concurrent.duration._
import scala.collection.immutable import scala.collection.immutable
class StubbedServiceDiscovery(system: ExtendedActorSystem) extends ServiceDiscovery { class StubbedServiceDiscovery(@unused system: ExtendedActorSystem) extends ServiceDiscovery {
override def lookup(query: Lookup, resolveTimeout: FiniteDuration): Future[Resolved] = { override def lookup(query: Lookup, resolveTimeout: FiniteDuration): Future[Resolved] = {
if (query.serviceName == "stubbed") { if (query.serviceName == "stubbed") {

View file

@ -48,7 +48,7 @@ class DnsDiscoverySpec extends AkkaSpec(DnsDiscoverySpec.config) with DockerBind
val systemWithAsyncDnsAsResolver = ActorSystem("AsyncDnsSystem", configWithAsyncDnsResolverAsDefault) val systemWithAsyncDnsAsResolver = ActorSystem("AsyncDnsSystem", configWithAsyncDnsResolverAsDefault)
private def testSrvRecords(discovery: ServiceDiscovery): Unit = { private def testSrvRecords(discovery: ServiceDiscovery) = {
val name = "_service._tcp.foo.test." val name = "_service._tcp.foo.test."
def lookup() = def lookup() =
@ -71,7 +71,7 @@ class DnsDiscoverySpec extends AkkaSpec(DnsDiscoverySpec.config) with DockerBind
result2.serviceName shouldEqual name result2.serviceName shouldEqual name
} }
private def testIpRecords(discovery: ServiceDiscovery): Unit = { private def testIpRecords(discovery: ServiceDiscovery) = {
val name = "a-single.foo.test" val name = "a-single.foo.test"
val expected = Set(ResolvedTarget("192.168.1.20", None, Some(InetAddress.getByName("192.168.1.20")))) val expected = Set(ResolvedTarget("192.168.1.20", None, Some(InetAddress.getByName("192.168.1.20"))))

View file

@ -19,9 +19,10 @@ object AkkaDisciplinePlugin extends AutoPlugin with ScalafixSupport {
override def trigger: PluginTrigger = allRequirements override def trigger: PluginTrigger = allRequirements
override def requires: Plugins = JvmPlugin && ScalafixPlugin override def requires: Plugins = JvmPlugin && ScalafixPlugin
override lazy val projectSettings = disciplineSettings override lazy val projectSettings = disciplineSettings
val strictProjects = Set("akka-discovery")
lazy val scalaFixSettings = Seq( lazy val scalaFixSettings = Seq(
Compile / scalacOptions += "-Yrangepos") Compile / scalacOptions += "-Yrangepos")
@ -36,15 +37,18 @@ object AkkaDisciplinePlugin extends AutoPlugin with ScalafixSupport {
lazy val disciplineSettings = lazy val disciplineSettings =
scalaFixSettings ++ scalaFixSettings ++
scoverageSettings ++ Seq( scoverageSettings ++ Seq(
Compile / scalacOptions ++= disciplineScalacOptions, Compile / scalacOptions ++= (if (strictProjects.contains(name.value)) {
Compile / scalacOptions --= undisciplineScalacOptions, disciplineScalacOptions
} else {
disciplineScalacOptions -- undisciplineScalacOptions
}).toSeq,
Compile / console / scalacOptions --= Seq("-deprecation", "-Xfatal-warnings", "-Xlint", "-Ywarn-unused:imports"), Compile / console / scalacOptions --= Seq("-deprecation", "-Xfatal-warnings", "-Xlint", "-Ywarn-unused:imports"),
// Discipline is not needed for the docs compilation run (which uses // Discipline is not needed for the docs compilation run (which uses
// different compiler phases from the regular run), and in particular // different compiler phases from the regular run), and in particular
// '-Ywarn-unused:explicits' breaks 'sbt ++2.13.0-M5 akka-actor/doc' // '-Ywarn-unused:explicits' breaks 'sbt ++2.13.0-M5 akka-actor/doc'
// https://github.com/akka/akka/issues/26119 // https://github.com/akka/akka/issues/26119
Compile / doc / scalacOptions --= disciplineScalacOptions, Compile / doc / scalacOptions --= disciplineScalacOptions.toSeq,
Compile / scalacOptions --= (CrossVersion.partialVersion(scalaVersion.value) match { Compile / scalacOptions --= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => case Some((2, 13)) =>
Seq( Seq(
@ -66,14 +70,14 @@ object AkkaDisciplinePlugin extends AutoPlugin with ScalafixSupport {
/** /**
* Remain visibly filtered for future code quality work and removing. * Remain visibly filtered for future code quality work and removing.
*/ */
val undisciplineScalacOptions = Seq( val undisciplineScalacOptions = Set(
"-Ywarn-value-discard", "-Ywarn-value-discard",
"-Ywarn-numeric-widen", "-Ywarn-numeric-widen",
"-Yno-adapted-args", "-Yno-adapted-args",
"-Xfatal-warnings") "-Xfatal-warnings")
/** These options are desired, but some are excluded for the time being*/ /** These options are desired, but some are excluded for the time being*/
val disciplineScalacOptions = Seq( val disciplineScalacOptions = Set(
// start: must currently remove, version regardless // start: must currently remove, version regardless
"-Xfatal-warnings", "-Xfatal-warnings",
"-Ywarn-value-discard", "-Ywarn-value-discard",